ARO-RP/pkg/database/metrics.go

30 строки
657 B
Go
Исходник Обычный вид История

2020-01-09 23:34:15 +03:00
package database
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
"time"
2020-09-25 23:48:01 +03:00
"github.com/sirupsen/logrus"
"github.com/Azure/ARO-RP/pkg/metrics"
2020-01-09 23:34:15 +03:00
"github.com/Azure/ARO-RP/pkg/util/recover"
)
func EmitMetrics(ctx context.Context, log *logrus.Entry, dbOpenShiftClusters OpenShiftClusters, m metrics.Emitter) {
2020-09-25 23:48:01 +03:00
defer recover.Panic(log)
2020-01-09 23:34:15 +03:00
t := time.NewTicker(time.Minute)
defer t.Stop()
for range t.C {
2020-09-26 01:07:03 +03:00
i, err := dbOpenShiftClusters.QueueLength(ctx, "OpenShiftClusters")
2020-01-09 23:34:15 +03:00
if err != nil {
2020-09-25 23:48:01 +03:00
log.Error(err)
2020-01-09 23:34:15 +03:00
} else {
2020-09-25 23:48:01 +03:00
m.EmitGauge("database.openshiftclusters.queue.length", int64(i), nil)
2020-01-09 23:34:15 +03:00
}
}
}