@@ -18,6 +18,7 @@ const (
18
18
pathLabel = "path"
19
19
methodLabel = "method"
20
20
statusLabel = "status"
21
+ subRouteLabel = "sub_route"
21
22
)
22
23
23
24
func RegisterRequestMetrics (metricsServer metrics.TaskMetrics ) []error {
@@ -29,17 +30,19 @@ func RegisterRequestMetrics(metricsServer metrics.TaskMetrics) []error {
29
30
}
30
31
}
31
32
32
- register (totalRequestsMetricName , "Total number of HTTP requests made." , []string {"method" , "path" , "status" }, & collectors.Counter {})
33
- register (durationMillisecondsMetricName , "Duration of HTTP requests in milliseconds." , []string {"method" , "path" , "status" }, & collectors.Gauge {})
34
- register (responseSizeMetricName , "Size of HTTP response in bytes." , []string {"method" , "path" , "status" }, & collectors.Histogram {})
35
- register (activeConnectionsMetricName , "Number of active HTTP connections." , []string {"method" , "path" }, & collectors.Gauge {})
33
+ register (totalRequestsMetricName , "Total number of HTTP requests made." , []string {subRouteLabel , methodLabel , pathLabel , statusLabel }, & collectors.Counter {})
34
+ register (durationMillisecondsMetricName , "Duration of HTTP requests in milliseconds." , []string {subRouteLabel , methodLabel , pathLabel , statusLabel }, & collectors.Gauge {})
35
+ register (responseSizeMetricName , "Size of HTTP response in bytes." , []string {subRouteLabel , methodLabel , pathLabel , statusLabel }, & collectors.Histogram {})
36
+ register (activeConnectionsMetricName , "Number of active HTTP connections." , []string {subRouteLabel , methodLabel , pathLabel }, & collectors.Gauge {})
37
+
38
+ register (getRequestBodyErrorMetric , "Register get request body error." , []string {subRouteLabel , pathLabel }, & collectors.Counter {})
36
39
37
40
cacheHitsMetricName := cacheHitsMetric
38
41
cacheMissesMetricName := cacheMissesMetric
39
42
cacheSetsMetricName := cacheSetsMetric
40
- register (cacheHitsMetricName , "Number of cache hits." , []string {pathLabel }, & collectors.Counter {})
41
- register (cacheMissesMetricName , "Number of cache misses." , []string {pathLabel }, & collectors.Counter {})
42
- register (cacheSetsMetricName , "Number of responses added to the cache." , []string {pathLabel }, & collectors.Counter {})
43
+ register (cacheHitsMetricName , "Number of cache hits." , []string {subRouteLabel , pathLabel }, & collectors.Counter {})
44
+ register (cacheMissesMetricName , "Number of cache misses." , []string {subRouteLabel , pathLabel }, & collectors.Counter {})
45
+ register (cacheSetsMetricName , "Number of responses added to the cache." , []string {subRouteLabel , pathLabel }, & collectors.Counter {})
43
46
44
47
return errs
45
48
}
@@ -51,11 +54,12 @@ func RequestMetrics(metricsServer metrics.TaskMetrics) Middleware {
51
54
return func (next http.Handler ) http.Handler {
52
55
return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
53
56
path := GetRoutePattern (r )
57
+ subRoute := GetSubRoutePattern (r )
54
58
startTime := time .Now ()
55
59
56
60
mu .Lock ()
57
61
activeConnections ++
58
- if err := metricsServer .UpdateMetric (activeConnectionsMetricName , float64 (activeConnections ), r .Method , path ); err != nil {
62
+ if err := metricsServer .UpdateMetric (activeConnectionsMetricName , float64 (activeConnections ), subRoute , r .Method , path ); err != nil {
59
63
logger .GetLoggerFromContext (r .Context ()).Errorf ("error updating active connections metric: %v" , err .Error ())
60
64
}
61
65
mu .Unlock ()
@@ -65,7 +69,7 @@ func RequestMetrics(metricsServer metrics.TaskMetrics) Middleware {
65
69
66
70
mu .Lock ()
67
71
activeConnections --
68
- if err := metricsServer .UpdateMetric (activeConnectionsMetricName , float64 (activeConnections ), r .Method , path ); err != nil {
72
+ if err := metricsServer .UpdateMetric (activeConnectionsMetricName , float64 (activeConnections ), subRoute , r .Method , path ); err != nil {
69
73
logger .GetLoggerFromContext (r .Context ()).Errorf ("error updating active connections metric: %v" , err .Error ())
70
74
}
71
75
mu .Unlock ()
@@ -75,7 +79,7 @@ func RequestMetrics(metricsServer metrics.TaskMetrics) Middleware {
75
79
responseStatus := mrw .status
76
80
bytesWritten := mrw .written
77
81
78
- labels := []string {r .Method , path , strconv .Itoa (responseStatus )}
82
+ labels := []string {subRoute , r .Method , path , strconv .Itoa (responseStatus )}
79
83
80
84
if err := metricsServer .UpdateMetric (durationMillisecondsMetricName , duration , labels ... ); err != nil {
81
85
logger .GetLoggerFromContext (r .Context ()).Errorf ("error updating request duration metric: %v" , err .Error ())
0 commit comments