asifdxtreme closed pull request #344: SCB-563 Fix the incorrect metric label value URL: https://github.com/apache/incubator-servicecomb-service-center/pull/344
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/integration/health-metrics-grafana.json b/integration/health-metrics-grafana.json index 2404a611..cec6a9ce 100644 --- a/integration/health-metrics-grafana.json +++ b/integration/health-metrics-grafana.json @@ -555,7 +555,7 @@ "format": "time_series", "instant": false, "intervalFactor": 2, - "legendFormat": "goroutines", + "legendFormat": "goroutines_{{instance}}", "refId": "A" } ], @@ -642,7 +642,7 @@ "format": "time_series", "instant": false, "intervalFactor": 2, - "legendFormat": "cpu", + "legendFormat": "cpu_{{instance}}", "refId": "A" } ], @@ -725,11 +725,11 @@ "steppedLine": false, "targets": [ { - "expr": "max(max_over_time(go_gc_duration_seconds{job=\"service-center\"}[1m]))", + "expr": "max(max_over_time(go_gc_duration_seconds{job=\"service-center\"}[1m])) by (instance)", "format": "time_series", "instant": false, "intervalFactor": 2, - "legendFormat": "gc", + "legendFormat": "gc_{{instance}}", "refId": "A" } ], @@ -830,7 +830,7 @@ "expr": "go_threads{job=\"service-center\"}", "format": "time_series", "intervalFactor": 2, - "legendFormat": "threads", + "legendFormat": "threads_{{instance}}", "refId": "A" } ], @@ -915,7 +915,7 @@ "expr": "process_open_fds{job=\"service-center\"}", "format": "time_series", "intervalFactor": 2, - "legendFormat": "fds", + "legendFormat": "fds_{{instance}}", "refId": "A" } ], @@ -1000,21 +1000,21 @@ "expr": "go_memstats_heap_inuse_bytes{job=\"service-center\"} + go_memstats_heap_idle_bytes{job=\"service-center\"}", "format": "time_series", "intervalFactor": 1, - "legendFormat": "heap", + "legendFormat": "heap_{{instance}}", "refId": "B" }, { "expr": "go_memstats_heap_inuse_bytes{job=\"service-center\"}", "format": "time_series", "intervalFactor": 1, - "legendFormat": "inuse", + "legendFormat": "inuse_{{instance}}", "refId": "C" }, { "expr": "process_resident_memory_bytes{job=\"service-center\"}", "format": "time_series", "intervalFactor": 1, - "legendFormat": "all", + "legendFormat": "all_{{instance}}", "refId": "A" } ], @@ -1099,17 +1099,17 @@ "steppedLine": false, "targets": [ { - "expr": "sum(service_center_local_cache_size_bytes{job=\"service-center\"}) by (resource)", + "expr": "sum(service_center_local_cache_size_bytes{job=\"service-center\"}) by (resource,instance)", "format": "time_series", "intervalFactor": 2, - "legendFormat": "{{resource}}", + "legendFormat": "{{resource}}_{{instance}}", "refId": "A" }, { - "expr": "sum(service_center_local_cache_size_bytes{job=\"service-center\"})", + "expr": "sum(service_center_local_cache_size_bytes{job=\"service-center\"}) by (instance)", "format": "time_series", "intervalFactor": 2, - "legendFormat": "ALL", + "legendFormat": "ALL_{{instance}}", "refId": "B" } ], @@ -1154,7 +1154,7 @@ } } ], - "refresh": false, + "refresh": "5s", "schemaVersion": 16, "style": "dark", "tags": [], @@ -1193,5 +1193,5 @@ "timezone": "", "title": "ServiceCenter", "uid": "Zg6NoHGiz", - "version": 5 + "version": 6 } \ No newline at end of file diff --git a/server/core/backend/store/metric.go b/server/core/backend/store/metric.go index 9661aaa4..889e4dc0 100644 --- a/server/core/backend/store/metric.go +++ b/server/core/backend/store/metric.go @@ -17,10 +17,10 @@ package store import ( - "fmt" "github.com/apache/incubator-servicecomb-service-center/pkg/util" "github.com/apache/incubator-servicecomb-service-center/server/core" "github.com/prometheus/client_golang/prometheus" + "sync" ) var ( @@ -33,11 +33,18 @@ var ( }, []string{"instance", "resource", "type"}) ) +var ( + instance string + once sync.Once +) + func init() { prometheus.MustRegister(cacheSizeGauge) } func ReportCacheMetrics(resource, t string, obj interface{}) { - instance := fmt.Sprint(core.Instance.Endpoints) + once.Do(func() { + instance, _ = util.ParseEndpoint(core.Instance.Endpoints[0]) + }) cacheSizeGauge.WithLabelValues(instance, resource, t).Set(float64(util.Sizeof(obj))) } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services