项目作者: cristalhq

项目描述 :
Prometheus metrics for Go database/sql via VictoriaMetrics/metrics
高级语言: Go
项目地址: git://github.com/cristalhq/sqlmetrics.git
创建时间: 2021-06-10T16:48:40Z
项目社区:https://github.com/cristalhq/sqlmetrics

开源协议:MIT License

下载


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+

  1. go get github.com/cristalhq/sqlmetrics

Example

  1. import (
  2. "github.com/VictoriaMetrics/metrics"
  3. "github.com/cristalhq/sqlmetrics"
  4. )
  5. // ...
  6. db, err := sql.Open("<some-connection-string>")
  7. if err != nil {
  8. panic(err)
  9. }
  10. ctx := context.Background() // or any other context you have
  11. every := 3 * time.Second
  12. sqlmetrics.NewCollector(ctx, db, every, "label1", "value1", "another", "etc")
  13. // done, db metrics are registered
  14. // you can see them here
  15. w := &bytes.Buffer{}
  16. metrics.WritePrometheus(w, true)

See this examples: example_test.go.

Documentation

See these docs.

License

MIT License.