Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement process uptime metric (#666)
* Implement process uptime metric * Add clarification comment * Add another clarification comment
- Loading branch information
Showing
5 changed files
with
35 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters