Prometheus metrics for Go database/sql
via VictoriaMetrics/metrics
- Simple API.
- Easy to integrate.
Go version 1.16+
go get github.com/cristalhq/sqlmetrics
import (
"github.com/VictoriaMetrics/metrics"
"github.com/cristalhq/sqlmetrics"
)
// ...
db, err := sql.Open("<some-connection-string>")
if err != nil {
panic(err)
}
ctx := context.Background() // or any other context you have
every := 3 * time.Second
sqlmetrics.NewCollector(ctx, db, every, "label1", "value1", "another", "etc")
// done, db metrics are registered
// you can see them here
w := &bytes.Buffer{}
metrics.WritePrometheus(w, true)
See this examples: example_test.go.
See these docs.