Skip to content

Commit

Permalink
Add process start time metric (sosedoff#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
sosedoff authored May 9, 2023
1 parent 52f7988 commit d4cfb05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/metrics/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package metrics

import (
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
Expand All @@ -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()
}
Expand Down

0 comments on commit d4cfb05

Please sign in to comment.