pgweb/pkg/metrics/metrics.go

56 lines
1.1 KiB
Go
Raw Normal View History

package metrics
import (
2023-05-08 20:46:00 -05:00
"time"
"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",
Help: "Server health status",
})
2023-05-08 20:46:00 -05:00
startTimeGauge = promauto.NewGauge(prometheus.GaugeOpts{
Name: "pgweb_process_start_time",
Help: "Server start time, seconds since unix epoch",
})
uptimeGauge = promauto.NewGauge(prometheus.GaugeOpts{
Name: "pgweb_uptime",
Help: "Server application uptime in seconds",
})
)
2023-05-08 20:46:00 -05:00
func init() {
startTimeGauge.Set(float64(time.Now().Unix()))
}
func IncrementQueriesCount() {
queriesCounter.Inc()
}
func SetSessionsCount(val int) {
sessionsGauge.Set(float64(val))
}
2023-02-28 11:57:36 -06:00
func SetHealthy(val bool) {
healthy := 0.0
if val {
healthy = 1.0
}
2023-02-28 11:57:36 -06:00
healthyGauge.Set(float64(healthy))
}