feat(observability): add maintenance policy metrics
Prometheus: runs, duration, rows_deleted, config_changes; инкремент при CRUD и Execute. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package observability
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
var (
|
||||
maintenancePolicyRuns = promauto.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Name: "maintenance_policy_runs_total",
|
||||
Help: "Maintenance policy executions by outcome.",
|
||||
},
|
||||
[]string{"policy_id", "action", "status", "dry_run"},
|
||||
)
|
||||
|
||||
maintenancePolicyDuration = promauto.NewHistogramVec(
|
||||
prometheus.HistogramOpts{
|
||||
Namespace: namespace,
|
||||
Name: "maintenance_policy_duration_seconds",
|
||||
Help: "Maintenance policy execution duration.",
|
||||
Buckets: prometheus.ExponentialBuckets(0.05, 2, 12),
|
||||
},
|
||||
[]string{"policy_id", "action"},
|
||||
)
|
||||
|
||||
maintenanceRowsDeleted = promauto.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Name: "maintenance_policy_rows_deleted_total",
|
||||
Help: "Rows deleted by maintenance cleanup policies.",
|
||||
},
|
||||
[]string{"policy_id"},
|
||||
)
|
||||
|
||||
maintenanceConfigChanges = promauto.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Name: "maintenance_config_changes_total",
|
||||
Help: "Maintenance policy configuration changes from UI/API.",
|
||||
},
|
||||
[]string{"action"},
|
||||
)
|
||||
)
|
||||
|
||||
// RecordMaintenancePolicyRun updates run counters and histograms.
|
||||
func RecordMaintenancePolicyRun(policyID, action, status string, dryRun bool, duration time.Duration, rowsDeleted int64) {
|
||||
if policyID == "" {
|
||||
policyID = "unknown"
|
||||
}
|
||||
if action == "" {
|
||||
action = "run"
|
||||
}
|
||||
dry := strconv.FormatBool(dryRun)
|
||||
maintenancePolicyRuns.WithLabelValues(policyID, action, status, dry).Inc()
|
||||
maintenancePolicyDuration.WithLabelValues(policyID, action).Observe(duration.Seconds())
|
||||
if rowsDeleted > 0 && !dryRun {
|
||||
maintenanceRowsDeleted.WithLabelValues(policyID).Add(float64(rowsDeleted))
|
||||
}
|
||||
}
|
||||
|
||||
// IncMaintenanceConfigChange increments config audit metric.
|
||||
func IncMaintenanceConfigChange(action string) {
|
||||
if action == "" {
|
||||
action = "unknown"
|
||||
}
|
||||
maintenanceConfigChanges.WithLabelValues(action).Inc()
|
||||
}
|
||||
Reference in New Issue
Block a user