2022-12-20 10:13:42 -06:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
sessionsGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
|
|
|
Name: "pgweb_sessions_count",
|
|
|
|
Help: "Total number of database sessions",
|
|
|
|
})
|
|
|
|
|
|
|
|
queriesCounter = promauto.NewCounter(prometheus.CounterOpts{
|
|
|
|
Name: "pgweb_queries_count",
|
|
|
|
Help: "Total number of custom queries executed",
|
|
|
|
})
|
|
|
|
|
2023-02-28 11:57:36 -06:00
|
|
|
healthyGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
|
|
|
Name: "pgweb_healthy",
|
2022-12-20 10:13:42 -06:00
|
|
|
Help: "Server health status",
|
|
|
|
})
|
2023-03-30 12:51:49 -05:00
|
|
|
|
|
|
|
uptimeGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
|
|
|
Name: "pgweb_uptime",
|
|
|
|
Help: "Server application uptime in seconds",
|
|
|
|
})
|
2022-12-20 10:13:42 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func IncrementQueriesCount() {
|
|
|
|
queriesCounter.Inc()
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetSessionsCount(val int) {
|
|
|
|
sessionsGauge.Set(float64(val))
|
|
|
|
}
|
|
|
|
|
2023-02-28 11:57:36 -06:00
|
|
|
func SetHealthy(val bool) {
|
2022-12-20 10:13:42 -06:00
|
|
|
healthy := 0.0
|
|
|
|
if val {
|
|
|
|
healthy = 1.0
|
|
|
|
}
|
2023-02-28 11:57:36 -06:00
|
|
|
healthyGauge.Set(float64(healthy))
|
2022-12-20 10:13:42 -06:00
|
|
|
}
|