Enabling metrics in Prometheus

Note

The article is being updated.

Below are examples of the code for enabling metrics in Prometheus in different YDB SDKs

Go

  1. package main
  2. import (
  3. "context"
  4. "github.com/prometheus/client_golang/prometheus"
  5. metrics "github.com/ydb-platform/ydb-go-sdk-prometheus"
  6. "github.com/ydb-platform/ydb-go-sdk/v3"
  7. "github.com/ydb-platform/ydb-go-sdk/v3/trace"
  8. )
  9. func main() {
  10. ctx := context.Background()
  11. registry := prometheus.NewRegistry()
  12. db, err := ydb.Open(
  13. ctx,
  14. os.Getenv("YDB_CONNECTION_STRING"),
  15. metrics.WithTraces(
  16. registry,
  17. metrics.WithDetails(trace.DetailsAll),
  18. metrics.WithSeparator("_"),
  19. ),
  20. )
  21. if err != nil {
  22. panic(err)
  23. }
  24. defer func() {
  25. _ = db.Close(ctx)
  26. }()
  27. }

Enable metrics in Prometheus - 图1