Skip to content

Commit

Permalink
metrics: add machine label to "cs_active_decisions"
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Feb 28, 2024
1 parent 8e9e091 commit 20216f5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/crowdsec/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var globalActiveDecisions = prometheus.NewGaugeVec(
Name: "cs_active_decisions",
Help: "Number of active decisions.",
},
[]string{"reason", "origin", "action"},
[]string{"reason", "origin", "action", "machine"},
)

var globalAlerts = prometheus.NewGaugeVec(
Expand Down Expand Up @@ -125,8 +125,15 @@ func computeDynamicMetrics(next http.Handler, dbClient *database.Client) http.Ha

globalActiveDecisions.Reset()

machine := "XXX" // how to get the machine id?

for _, d := range decisions {
globalActiveDecisions.With(prometheus.Labels{"reason": d.Scenario, "origin": d.Origin, "action": d.Type}).Set(float64(d.Count))
globalActiveDecisions.With(prometheus.Labels{
"reason": d.Scenario,
"origin": d.Origin,
"action": d.Type,
"machine": machine,
}).Set(float64(d.Count))

Check warning on line 136 in cmd/crowdsec/metrics.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec/metrics.go#L131-L136

Added lines #L131 - L136 were not covered by tests
}

globalAlerts.Reset()
Expand Down

0 comments on commit 20216f5

Please sign in to comment.