From 51e661ecfed8a02b42be5bbf7bc21ea7b2256abb Mon Sep 17 00:00:00 2001 From: John Belmonte Date: Tue, 3 Nov 2020 21:10:42 +0900 Subject: [PATCH] add short_version label to vm_app_version metric (#877) * add short_version label to vm_app_version metric use case: Version panel of Grafana dashboard should use a live query, but currently it uses a template query which becomes stale. Grafana is not able to preform regex substitution on labels. * Update metrics.go * fix compile --- lib/httpserver/metrics.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/httpserver/metrics.go b/lib/httpserver/metrics.go index aff8791e6..5bfc3ef81 100644 --- a/lib/httpserver/metrics.go +++ b/lib/httpserver/metrics.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "io" + "regexp" "strings" "time" @@ -13,11 +14,14 @@ import ( "github.com/VictoriaMetrics/metrics" ) +var versionRe = regexp.MustCompile(`v\d+\.\d+\.\d+`) + // WritePrometheusMetrics writes all the registered metrics to w in Prometheus exposition format. func WritePrometheusMetrics(w io.Writer) { metrics.WritePrometheus(w, true) - fmt.Fprintf(w, "vm_app_version{version=%q} 1\n", buildinfo.Version) + fmt.Fprintf(w, "vm_app_version{version=%q, short_version=%q} 1\n", buildinfo.Version, + versionRe.FindString(buildinfo.Version)) fmt.Fprintf(w, "vm_allowed_memory_bytes %d\n", memory.Allowed()) // Export start time and uptime in seconds