2020-12-02 08:50:59 +01:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
2021-08-10 07:27:27 +02:00
|
|
|
|
2021-09-23 12:50:17 +02:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
2021-08-10 07:27:27 +02:00
|
|
|
"go.opentelemetry.io/otel/metric"
|
2020-12-02 08:50:59 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
ActiveSessionCounter = "zitadel.active_session_counter"
|
|
|
|
ActiveSessionCounterDescription = "Active session counter"
|
|
|
|
SpoolerDivCounter = "zitadel.spooler_div_milliseconds"
|
|
|
|
SpoolerDivCounterDescription = "Spooler div from last successful run to now in milliseconds"
|
|
|
|
Database = "database"
|
|
|
|
ViewName = "view_name"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Metrics interface {
|
|
|
|
GetExporter() http.Handler
|
|
|
|
GetMetricsProvider() metric.MeterProvider
|
|
|
|
RegisterCounter(name, description string) error
|
2021-09-23 12:50:17 +02:00
|
|
|
AddCount(ctx context.Context, name string, value int64, labels map[string]attribute.Value) error
|
2023-09-01 13:32:13 +03:00
|
|
|
RegisterUpDownSumObserver(name, description string, callbackFunc metric.Int64Callback) error
|
|
|
|
RegisterValueObserver(name, description string, callbackFunc metric.Int64Callback) error
|
2020-12-02 08:50:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var M Metrics
|
|
|
|
|
|
|
|
func GetExporter() http.Handler {
|
|
|
|
if M == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return M.GetExporter()
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMetricsProvider() metric.MeterProvider {
|
|
|
|
if M == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return M.GetMetricsProvider()
|
|
|
|
}
|
|
|
|
|
|
|
|
func RegisterCounter(name, description string) error {
|
|
|
|
if M == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return M.RegisterCounter(name, description)
|
|
|
|
}
|
|
|
|
|
2021-09-23 12:50:17 +02:00
|
|
|
func AddCount(ctx context.Context, name string, value int64, labels map[string]attribute.Value) error {
|
2020-12-02 08:50:59 +01:00
|
|
|
if M == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return M.AddCount(ctx, name, value, labels)
|
|
|
|
}
|
|
|
|
|
2023-09-01 13:32:13 +03:00
|
|
|
func RegisterUpDownSumObserver(name, description string, callbackFunc metric.Int64Callback) error {
|
2020-12-02 08:50:59 +01:00
|
|
|
if M == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return M.RegisterUpDownSumObserver(name, description, callbackFunc)
|
|
|
|
}
|
|
|
|
|
2023-09-01 13:32:13 +03:00
|
|
|
func RegisterValueObserver(name, description string, callbackFunc metric.Int64Callback) error {
|
2020-12-02 08:50:59 +01:00
|
|
|
if M == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return M.RegisterValueObserver(name, description, callbackFunc)
|
|
|
|
}
|