Skip to content

Prometheus metrics for Go database/sql via VictoriaMetrics/metrics

License

Notifications You must be signed in to change notification settings

cristalhq/sqlmetrics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sqlmetrics

build-img pkg-img reportcard-img coverage-img version-img

Prometheus metrics for Go database/sql via VictoriaMetrics/metrics

Features

  • Simple API.
  • Easy to integrate.

Install

Go version 1.16+

go get github.com/cristalhq/sqlmetrics

Example

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.

Documentation

See these docs.

License

MIT License.