Skip to content

Commit

Permalink
chore: add websocke duration & http code
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenvechain committed Nov 26, 2024
1 parent 3af97f9 commit 6606e28
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions api/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import (
)

var (
metricHTTPReqCounter = metrics.LazyLoadCounterVec("api_request_count", []string{"name", "code", "method"})
metricHTTPReqDuration = metrics.LazyLoadHistogramVec("api_duration_ms", []string{"name", "code", "method"}, metrics.BucketHTTPReqs)
metricHTTPReqCounter = metrics.LazyLoadCounterVec("api_request_count", []string{"name", "code", "method"})
metricHTTPReqDuration = metrics.LazyLoadHistogramVec("api_duration_ms", []string{"name", "code", "method"}, metrics.BucketHTTPReqs)
metricWebsocketDuration = metrics.LazyLoadHistogramVec("api_websocket_duration", []string{"name", "code"}, metrics.BucketHTTPReqs)
metricActiveWebsocketGauge = metrics.LazyLoadGaugeVec("api_active_websocket_gauge", []string{"name"})
metricWebsocketCounter = metrics.LazyLoadCounterVec("api_websocket_counter", []string{"name"})
)
Expand Down Expand Up @@ -87,6 +88,8 @@ func metricsMiddleware(next http.Handler) http.Handler {

if subscription {
metricActiveWebsocketGauge().AddWithLabel(-1, map[string]string{"name": name})
// record websocket duration in seconds, no MS
metricWebsocketDuration().ObserveWithLabels(time.Since(now).Milliseconds() / 1000, map[string]string{"name": name, "code": strconv.Itoa(mrw.statusCode)})
} else if enabled {
metricHTTPReqCounter().AddWithLabel(1, map[string]string{"name": name, "code": strconv.Itoa(mrw.statusCode), "method": r.Method})
metricHTTPReqDuration().ObserveWithLabels(time.Since(now).Milliseconds(), map[string]string{"name": name, "code": strconv.Itoa(mrw.statusCode), "method": r.Method})
Expand Down

0 comments on commit 6606e28

Please sign in to comment.