From 532575a87b37c0bf173e91a59f5a07c890e1bc25 Mon Sep 17 00:00:00 2001 From: rasmus Date: Sun, 6 Nov 2022 20:37:43 +0200 Subject: [PATCH] prom mongo: use seconds instead of nanoseconds --- cmd/mongo.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/mongo.go b/cmd/mongo.go index 5948d34..a17eecc 100644 --- a/cmd/mongo.go +++ b/cmd/mongo.go @@ -3,6 +3,7 @@ package logmower import ( "context" "fmt" + "time" prom "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" @@ -16,15 +17,15 @@ var ( Namespace: PrometheusPrefix, Subsystem: "database", Name: "heartbeat_time", - Help: "Time in ns for succeeded heartbeat, or 0 on failure", - Buckets: []float64{1}, + Help: "Time in seconds for succeeded heartbeat, or 0 on failure", + Buckets: []float64{0.1, 0.2, 0.5, 1, 5, 10, 50}, }, []string{"connection_id"}) promDbCmd = promauto.NewHistogramVec(prom.HistogramOpts{ Namespace: PrometheusPrefix, Subsystem: "database", Name: "operation_latency", // "command_time", - Help: "Time in ns of commands", + Help: "Time in seconds of commands", Buckets: []float64{0.1, 0.2, 0.5, 1, 5, 10, 50}, }, []string{"connection_id", "command_name"}) @@ -40,7 +41,7 @@ func mongoMonitoredClientOptions(l *zap.Logger) *mongoOpt.ClientOptions { return mongoOpt.Client(). SetServerMonitor(&mongoEvent.ServerMonitor{ ServerHeartbeatSucceeded: func(ev *mongoEvent.ServerHeartbeatSucceededEvent) { - promDbHeartbeat.WithLabelValues(ev.ConnectionID).Observe(float64(ev.DurationNanos)) + promDbHeartbeat.WithLabelValues(ev.ConnectionID).Observe(time.Duration(ev.DurationNanos).Seconds()) }, ServerHeartbeatFailed: func(ev *mongoEvent.ServerHeartbeatFailedEvent) { promDbHeartbeat.WithLabelValues(ev.ConnectionID).Observe(0) @@ -49,10 +50,10 @@ func mongoMonitoredClientOptions(l *zap.Logger) *mongoOpt.ClientOptions { }). SetMonitor(&mongoEvent.CommandMonitor{ Succeeded: func(_ context.Context, ev *mongoEvent.CommandSucceededEvent) { - promDbCmd.WithLabelValues(ev.ConnectionID, ev.CommandName).Observe(float64(ev.DurationNanos)) + promDbCmd.WithLabelValues(ev.ConnectionID, ev.CommandName).Observe(time.Duration(ev.DurationNanos).Seconds()) }, Failed: func(_ context.Context, ev *mongoEvent.CommandFailedEvent) { - promDbCmd.WithLabelValues(ev.ConnectionID, ev.CommandName).Observe(float64(ev.DurationNanos)) + promDbCmd.WithLabelValues(ev.ConnectionID, ev.CommandName).Observe(time.Duration(ev.DurationNanos).Seconds()) promDbCmdErr.WithLabelValues(ev.ConnectionID, ev.CommandName).Add(1) l.Error("database command", zap.Error(fmt.Errorf("%s", ev.Failure)), zap.String("connection_id", ev.ConnectionID), zap.String("command_name", ev.CommandName)) // TODO: https://github.com/mongodb/mongo-go-driver/pull/1105