From 98d5dfff8e74d982fd2da31f71ef6701e566a776 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Thu, 7 Jul 2022 12:23:06 +0800 Subject: [PATCH] add namespace and subsystem prefix for metrics --- src/server/router/router.go | 2 +- src/server/stat/stat.go | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/server/router/router.go b/src/server/router/router.go index e0f80e3a..d515e41e 100644 --- a/src/server/router/router.go +++ b/src/server/router/router.go @@ -106,7 +106,7 @@ func stat() gin.HandlerFunc { code := fmt.Sprintf("%d", c.Writer.Status()) method := c.Request.Method - labels := []string{"n9e-server", code, c.FullPath(), method} + labels := []string{code, c.FullPath(), method} promstat.RequestDuration.WithLabelValues(labels...).Observe(time.Since(start).Seconds()) } diff --git a/src/server/stat/stat.go b/src/server/stat/stat.go index 819b0387..10824e45 100644 --- a/src/server/stat/stat.go +++ b/src/server/stat/stat.go @@ -61,18 +61,22 @@ var ( // 一些重要的请求,比如接收数据的请求,应该统计一下延迟情况 RequestDuration = prometheus.NewHistogramVec( prometheus.HistogramOpts{ - Buckets: []float64{.01, .1, 1}, - Name: "http_request_duration_seconds", - Help: "HTTP request latencies in seconds.", - }, []string{"service", "code", "path", "method"}, + Namespace: namespace, + Subsystem: subsystem, + Buckets: []float64{.01, .1, 1}, + Name: "http_request_duration_seconds", + Help: "HTTP request latencies in seconds.", + }, []string{"code", "path", "method"}, ) // 发往后端TSDB,延迟如何 ForwardDuration = prometheus.NewHistogramVec( prometheus.HistogramOpts{ - Buckets: []float64{.1, 1, 10}, - Name: "forward_duration_seconds", - Help: "Forward samples to TSDB. latencies in seconds.", + Namespace: namespace, + Subsystem: subsystem, + Buckets: []float64{.1, 1, 10}, + Name: "forward_duration_seconds", + Help: "Forward samples to TSDB. latencies in seconds.", }, []string{"cluster", "channel_number"}, ) )