What things you need to setup the project:
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.
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 becomedb_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 becomedb_PREFIX_query_total
.
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