promsrv

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2020 License: MIT Imports: 2 Imported by: 1

README

go-rscsrv-prometheus CircleCI

Getting Started

Prerequisites

What things you need to setup the project:

Environment

Close the repository:

git clone git@github.com:lab259/go-rscsrv-prometheus.git

Now, the dependencies must be installed.

cd go-rscsrv-prometheus && go mod download

😉 Finally, you are done to start developing.

Collectors

database/sql.DB

Given a *sql.DB instance, you can create a collector by using promsql.NewDatabaseCollector(db, opts).

The information provided by the collector will generate these metrics:

  • db_max_open_connections: Maximum number of open connections to the database.
  • db_pool_open_connections: The number of established connections both in use and idle.
  • db_pool_in_use: The number of connections currently in use.
  • db_pool_idle: The number of idle connections.
  • db_wait_count: The total number of connections waited for.
  • db_wait_duration: The total time blocked waiting for a new connection.
  • db_max_idle_closed: The total number of connections closed due to SetMaxIdleConns.
  • db_max_lifetime_closed: The total number of connections closed due to SetConnMaxLifetime.

All these metrics are provided by the database/sql package interface.

opts: promsql.DatabaseCollectorOpts

  • Prefix string: That will add a prefix to the metrics names. So, for example, db_max_open_connections will become db_PREFIX_max_open_connections.

database/sql/driver

Given a driver name (e.g. postgres), you can create a collector by using promsql.Register(opts).

The information provided by the collector will generate these metrics:

  • db_query_total: The total number of queries processed.
  • db_query_successful: The number of queries processed with success.
  • db_query_failed: The number of queries processed with failure.
  • db_transaction_total: The total number of transactions processed.
  • db_transaction_successful: The number of transactions processed with success.
  • db_transaction_failed: The number of transactions processed with failure.
  • db_execution_total: The total number of executions processed.
  • db_execution_successful: The number of executions processed with success.
  • db_execution_failed: The number of executions processed with failure.

opts: _promsql.DriverCollectorOpts

  • DriverName string: The base driver name that will be used by sql package (e.g. postgres, mysql)
  • Prefix string: That will add a prefix to the metrics names. So, for example, db_query_total will become db_PREFIX_query_total.
Running tests

In order to run the tests, spin up the :

make dco-test-up

In the src/github.com/lab259/go-rscsrv-prometheus directory, execute:

make test

To enable coverage, execute:

make coverage

To generate the HTML coverage report, execute:

make coverage coverage-html

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service represents a Prometheus service.

func (*Service) Gather

func (service *Service) Gather() ([]*dto.MetricFamily, error)

Gather implements prometheus.Gatherer.

func (*Service) MustRegister

func (service *Service) MustRegister(cs ...prometheus.Collector)

MustRegister implements prometheus.Registerer.

func (*Service) NewCounter

func (service *Service) NewCounter(opts prometheus.CounterOpts) prometheus.Counter

NewCounter works like the function of the same name in the prometheus package but it automatically registers the Counter with the service's internal registry. If the registration fails, NewCounter panics.

func (*Service) NewCounterFunc

func (service *Service) NewCounterFunc(opts prometheus.CounterOpts, function func() float64) prometheus.CounterFunc

NewCounterFunc works like the function of the same name in the prometheus package but it automatically registers the CounterFunc with the service's internal registry. If the registration fails, NewCounterFunc panics.

func (*Service) NewCounterVec

func (service *Service) NewCounterVec(opts prometheus.CounterOpts, labelNames []string) *prometheus.CounterVec

NewCounterVec works like the function of the same name in the prometheus package but it automatically registers the CounterVec with the service's internal registry. If the registration fails, NewCounterVec panics.

func (*Service) NewGauge

func (service *Service) NewGauge(opts prometheus.GaugeOpts) prometheus.Gauge

NewGauge works like the function of the same name in the prometheus package but it automatically registers the Gauge with the service's internal registry. If the registration fails, NewGauge panics.

func (*Service) NewGaugeFunc

func (service *Service) NewGaugeFunc(opts prometheus.GaugeOpts, function func() float64) prometheus.GaugeFunc

NewGaugeFunc works like the function of the same name in the prometheus package but it automatically registers the GaugeFunc with the service's internal registry. If the registration fails, NewGaugeFunc panics.

func (*Service) NewGaugeVec

func (service *Service) NewGaugeVec(opts prometheus.GaugeOpts, labelNames []string) *prometheus.GaugeVec

NewGaugeVec works like the function of the same name in the prometheus package but it automatically registers the GaugeVec with the service's internal registry. If the registration fails, NewGaugeVec panics.

func (*Service) NewHistogram

func (service *Service) NewHistogram(opts prometheus.HistogramOpts) prometheus.Histogram

NewHistogram works like the function of the same name in the prometheus package but it automatically registers the Histogram with the service's internal registry. If the registration fails, NewHistogram panics.

func (*Service) NewHistogramVec

func (service *Service) NewHistogramVec(opts prometheus.HistogramOpts, labelNames []string) *prometheus.HistogramVec

NewHistogramVec works like the function of the same name in the prometheus package but it automatically registers the HistogramVec with the service's internal registry. If the registration fails, NewHistogramVec panics.

func (*Service) NewSummary

func (service *Service) NewSummary(opts prometheus.SummaryOpts) prometheus.Summary

NewSummary works like the function of the same name in the prometheus package but it automatically registers the Summary with the service's internal registry. If the registration fails, NewSummary panics.

func (*Service) NewSummaryVec

func (service *Service) NewSummaryVec(opts prometheus.SummaryOpts, labelNames []string) *prometheus.SummaryVec

NewSummaryVec works like the function of the same name in the prometheus package but it automatically registers the SummaryVec with the service's internal registry. If the registration fails, NewSummaryVec panics.

func (*Service) Register

func (service *Service) Register(c prometheus.Collector) error

Register implements prometheus.Registerer.

func (*Service) Restart

func (service *Service) Restart() error

Restart restarts the Prometheus service.

func (*Service) Start

func (service *Service) Start() error

Start starts the Prometheus service.

func (*Service) Stop

func (service *Service) Stop() error

Stop stops the Prometheus service.

func (*Service) Unregister

func (service *Service) Unregister(c prometheus.Collector) bool

Unregister implements prometheus.Registerer.

Directories

Path Synopsis
examples
Package promfasthttp provides tooling around HTTP servers.
Package promfasthttp provides tooling around HTTP servers.
Package promhermes provides tooling around HTTP servers.
Package promhermes provides tooling around HTTP servers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL