add Prometheus support

some basic counters and gauges are now exposed
This commit is contained in:
Nicola Murino
2019-09-13 18:45:36 +02:00
parent fd59f35108
commit 7eb5b01169
17 changed files with 377 additions and 20 deletions

View File

@@ -19,6 +19,7 @@ const (
quotaScanPath = "/api/v1/quota_scan"
userPath = "/api/v1/user"
versionPath = "/api/v1/version"
metricsPath = "/metrics"
)
var (

View File

@@ -36,6 +36,7 @@ const (
activeConnectionsPath = "/api/v1/connection"
quotaScanPath = "/api/v1/quota_scan"
versionPath = "/api/v1/version"
metricsPath = "/metrics"
)
var (
@@ -710,6 +711,12 @@ func TestMethodNotAllowedMock(t *testing.T) {
checkResponseCode(t, http.StatusMethodNotAllowed, rr.Code)
}
func TestMetricsMock(t *testing.T) {
req, _ := http.NewRequest(http.MethodGet, metricsPath, nil)
rr := executeRequest(req)
checkResponseCode(t, http.StatusOK, rr.Code)
}
func waitTCPListening(address string) {
for {
conn, err := net.Dial("tcp", address)

View File

@@ -9,6 +9,7 @@ import (
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/go-chi/render"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
// GetHTTPRouter returns the configured HTTP handler
@@ -31,6 +32,8 @@ func initializeRouter() {
sendAPIResponse(w, r, nil, "Method not allowed", http.StatusMethodNotAllowed)
}))
router.Handle(metricsPath, promhttp.Handler())
router.Get(versionPath, func(w http.ResponseWriter, r *http.Request) {
render.JSON(w, r, utils.GetAppVersion())
})