Add process start time metric (#675)

This commit is contained in:
Dan Sosedoff 2023-05-08 20:46:00 -05:00 committed by GitHub
parent 52f7988ebd
commit d4cfb059ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -14,6 +14,7 @@ type Handler struct {
func (h Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
uptimeGauge.Set(time.Since(h.startTime).Seconds())
h.promHandler.ServeHTTP(rw, req)
}

View File

@ -1,6 +1,8 @@
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
@ -21,12 +23,21 @@ var (
Help: "Server health status",
})
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",
})
)
func init() {
startTimeGauge.Set(float64(time.Now().Unix()))
}
func IncrementQueriesCount() {
queriesCounter.Inc()
}