Skip to content

Commit

Permalink
feat: add ayd_incident_count to Prometheus metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
macrat committed Apr 23, 2021
1 parent 5770c55 commit 7c046a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions exporter/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ func MetricsExporter(s *store.Store) http.HandlerFunc {
fmt.Fprintln(w)
}
}
fmt.Fprintln(w)
fmt.Fprintln(w, "# HELP ayd_incident_count The number of incident happend since server started")
fmt.Fprintln(w, "# TYPE ayd_incident_count Counter")
fmt.Fprintf(w, "ayd_incident_count %d\n", s.IncidentCount)
}
}
4 changes: 3 additions & 1 deletion store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ type Store struct {
CurrentIncidents []*Incident
IncidentHistory []*Incident

OnIncident []IncidentHandler
OnIncident []IncidentHandler
IncidentCount int

file *os.File
lastError error
Expand Down Expand Up @@ -115,6 +116,7 @@ func (s *Store) setIncidentIfNeed(r Record, needCallback bool) {
s.CurrentIncidents = append(s.CurrentIncidents, incident)

if needCallback {
s.IncidentCount++
for _, cb := range s.OnIncident {
s.appendWithoutLock(cb(incident))
}
Expand Down

0 comments on commit 7c046a9

Please sign in to comment.