Implement process uptime metric (#666)

* Implement process uptime metric
* Add clarification comment
* Add another clarification comment
This commit is contained in:
Dan Sosedoff
2023-03-30 12:51:49 -05:00
committed by GitHub
parent 941c0acea3
commit 08bbb1537e
5 changed files with 35 additions and 7 deletions

25
pkg/metrics/handler.go Normal file
View File

@@ -0,0 +1,25 @@
package metrics
import (
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
type Handler struct {
startTime time.Time
promHandler http.Handler
}
func (h Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
uptimeGauge.Set(time.Since(h.startTime).Seconds())
h.promHandler.ServeHTTP(rw, req)
}
func NewHandler() http.Handler {
return Handler{
startTime: time.Now(),
promHandler: promhttp.Handler(),
}
}