Skip to content

Commit

Permalink
ref: convert mango_manager_module_run_duration_seconds to histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhop committed Apr 9, 2024
1 parent 7375f23 commit e6a23e8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions internal/manager/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ var (
[]string{"module", "script"},
)

metricManagerModuleRunDuration = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "mango_manager_module_run_duration_seconds",
Help: "Approximately how long it took for the module to run, in seconds",
metricManagerModuleRunDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "mango_manager_module_run_duration_seconds",
Help: "Histogram of durations of how long it took a given module to run, in seconds",
Buckets: prometheus.ExponentialBuckets(1, 2, 8),
},
[]string{"module", "script"},
)
Expand Down
5 changes: 3 additions & 2 deletions internal/manager/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (mgr *Manager) RunModule(ctx context.Context, logger *slog.Logger, mod Modu

labels := prometheus.Labels{
"module": mod.String(),
"script": "",
}

hostVarsMap := shell.MakeVariableMap(mgr.hostVariables)
Expand Down Expand Up @@ -152,7 +153,7 @@ func (mgr *Manager) RunModule(ctx context.Context, logger *slog.Logger, mod Modu
}

testEnd := time.Since(testStart)
metricManagerModuleRunDuration.With(labels).Set(float64(testEnd))
metricManagerModuleRunDuration.With(labels).Observe(float64(testEnd))
}

applyStart := time.Now()
Expand All @@ -169,7 +170,7 @@ func (mgr *Manager) RunModule(ctx context.Context, logger *slog.Logger, mod Modu
// update metrics regardless of error, so do them before handling error
applyEnd := time.Since(applyStart)
metricManagerModuleRunSuccessTimestamp.With(labels).Set(float64(applyStart.Unix()))
metricManagerModuleRunDuration.With(labels).Set(float64(applyEnd))
metricManagerModuleRunDuration.With(labels).Observe(float64(applyEnd))
metricManagerModuleRunTotal.With(labels).Inc()

if err != nil {
Expand Down

0 comments on commit e6a23e8

Please sign in to comment.