Skip to content

Commit

Permalink
Merge pull request PelicanPlatform#207 from Techming/component-health…
Browse files Browse the repository at this point in the history
…-prometheus

Integrate component health status to Prometheus
  • Loading branch information
bbockelm committed Oct 16, 2023
2 parents 818b35e + aff5896 commit 96d9cc0
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion metrics/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
"fmt"
"sync"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

type (
Expand All @@ -45,6 +48,16 @@ type (

var (
healthStatus = sync.Map{}

PelicanHealthStatus = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "pelican_component_health_status",
Help: "The health status of various components",
}, []string{"component"})

PelicanHealthLastUpdate = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "pelican_component_health_status_last_update",
Help: "Last update timestamp of components health status",
}, []string{"component"})
)

func statusToInt(status string) (int, error) {
Expand Down Expand Up @@ -76,7 +89,16 @@ func SetComponentHealthStatus(name, state, msg string) error {
if err != nil {
return err
}
healthStatus.Store(name, componentStatusInternal{statusInt, msg, time.Now()})
now := time.Now()
healthStatus.Store(name, componentStatusInternal{statusInt, msg, now})

PelicanHealthStatus.With(
prometheus.Labels{"component": name}).
Set(float64(statusInt))

PelicanHealthLastUpdate.With(prometheus.Labels{"component": name}).
SetToCurrentTime()

return nil
}

Expand Down

0 comments on commit 96d9cc0

Please sign in to comment.