Включение метрик в Prometheus
Примечание
Материал статьи дополняется.
Ниже приведены примеры кода включения метрик в Prometheus в разных YDB SDK.
Go (native)
Go (database/sql)
package main
import (
"context"
"github.com/prometheus/client_golang/prometheus"
metrics "github.com/ydb-platform/ydb-go-sdk-prometheus/v2"
"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
)
func main() {
ctx := context.Background()
registry := prometheus.NewRegistry()
db, err := ydb.Open(ctx,
os.Getenv("YDB_CONNECTION_STRING"),
metrics.WithTraces(
registry,
metrics.WithDetails(trace.DetailsAll),
metrics.WithSeparator("_"),
),
)
if err != nil {
panic(err)
}
defer db.Close(ctx)
...
}
package main
import (
"context"
"database/sql"
"github.com/prometheus/client_golang/prometheus"
metrics "github.com/ydb-platform/ydb-go-sdk-prometheus/v2"
"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
)
func main() {
ctx := context.Background()
registry := prometheus.NewRegistry()
nativeDriver, err := ydb.Open(ctx,
os.Getenv("YDB_CONNECTION_STRING"),
metrics.WithTraces(
registry,
metrics.WithDetails(trace.DetailsAll),
metrics.WithSeparator("_"),
),
)
if err != nil {
panic(err)
}
defer nativeDriver.Close(ctx)
connector, err := ydb.Connector(nativeDriver)
if err != nil {
panic(err)
}
db := sql.OpnDB(connector)
defer db.Close()
...
}