prom mongo: use seconds instead of nanoseconds
This commit is contained in:
parent
80ea6b7821
commit
532575a87b
13
cmd/mongo.go
13
cmd/mongo.go
@ -3,6 +3,7 @@ package logmower
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
prom "github.com/prometheus/client_golang/prometheus"
|
prom "github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
@ -16,15 +17,15 @@ var (
|
|||||||
Namespace: PrometheusPrefix,
|
Namespace: PrometheusPrefix,
|
||||||
Subsystem: "database",
|
Subsystem: "database",
|
||||||
Name: "heartbeat_time",
|
Name: "heartbeat_time",
|
||||||
Help: "Time in ns for succeeded heartbeat, or 0 on failure",
|
Help: "Time in seconds for succeeded heartbeat, or 0 on failure",
|
||||||
Buckets: []float64{1},
|
Buckets: []float64{0.1, 0.2, 0.5, 1, 5, 10, 50},
|
||||||
}, []string{"connection_id"})
|
}, []string{"connection_id"})
|
||||||
|
|
||||||
promDbCmd = promauto.NewHistogramVec(prom.HistogramOpts{
|
promDbCmd = promauto.NewHistogramVec(prom.HistogramOpts{
|
||||||
Namespace: PrometheusPrefix,
|
Namespace: PrometheusPrefix,
|
||||||
Subsystem: "database",
|
Subsystem: "database",
|
||||||
Name: "operation_latency", // "command_time",
|
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},
|
Buckets: []float64{0.1, 0.2, 0.5, 1, 5, 10, 50},
|
||||||
}, []string{"connection_id", "command_name"})
|
}, []string{"connection_id", "command_name"})
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ func mongoMonitoredClientOptions(l *zap.Logger) *mongoOpt.ClientOptions {
|
|||||||
return mongoOpt.Client().
|
return mongoOpt.Client().
|
||||||
SetServerMonitor(&mongoEvent.ServerMonitor{
|
SetServerMonitor(&mongoEvent.ServerMonitor{
|
||||||
ServerHeartbeatSucceeded: func(ev *mongoEvent.ServerHeartbeatSucceededEvent) {
|
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) {
|
ServerHeartbeatFailed: func(ev *mongoEvent.ServerHeartbeatFailedEvent) {
|
||||||
promDbHeartbeat.WithLabelValues(ev.ConnectionID).Observe(0)
|
promDbHeartbeat.WithLabelValues(ev.ConnectionID).Observe(0)
|
||||||
@ -49,10 +50,10 @@ func mongoMonitoredClientOptions(l *zap.Logger) *mongoOpt.ClientOptions {
|
|||||||
}).
|
}).
|
||||||
SetMonitor(&mongoEvent.CommandMonitor{
|
SetMonitor(&mongoEvent.CommandMonitor{
|
||||||
Succeeded: func(_ context.Context, ev *mongoEvent.CommandSucceededEvent) {
|
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) {
|
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)
|
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
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user