A plugin for GORM providing metrics using Prometheus.
Warning: this plugin is still in an early stage of development. APIs may change.
import "github.com/profects/gormetrics"
err := gormetrics.Register(db, <database name>)
if err != nil {
// handle the error
}gormetrics does not expose the metrics endpoint using promhttp, you have to do this yourself.
You can use the following snippet for exposing metrics on port 2112 at /metrics:
go func() {
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(":2112", nil))
}()gormetrics exports the following metrics (counter vectors):
gormetrics_all_totalgormetrics_creates_totalgormetrics_deletes_totalgormetrics_queries_totalgormetrics_updates_total
These all have the following labels:
database: the name of the databasedriver: the driver for the database (e.g. pq)status: fail or success
It also export the following metrics (gauge vectors):
gormetrics_connections_idlegormetrics_connections_in_usegormetrics_connections_open
These all have the following labels:
database: the name of the databasedriver: the driver for the database (e.g. pq)