chore: systematic syncthing_build_info metric

Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
Jakob Borg
2026-04-06 09:44:49 +02:00
parent e2cb283155
commit b594b7491f
8 changed files with 37 additions and 14 deletions
+24 -1
View File
@@ -16,8 +16,18 @@ import (
"strconv"
"strings"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var buildInfo = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "syncthing",
Subsystem: "build",
Name: "info",
Help: "A metric with a constant '1' value labeled by version information from when the binary was built.",
}, []string{"program", "version", "codename", "goversion", "builduser", "builddate", "tags"})
const Codename = "Hafnium Hornet"
var (
@@ -98,9 +108,22 @@ func LongVersionFor(program string) string {
date := Date.UTC().Format("2006-01-02 15:04:05 MST")
v := fmt.Sprintf(`%s %s "%s" (%s %s-%s) %s@%s %s`, program, Version, Codename, runtime.Version(), runtime.GOOS, runtime.GOARCH, User, Host, date)
if tags := TagsList(); len(tags) > 0 {
tags := TagsList()
if len(tags) > 0 {
v = fmt.Sprintf("%s [%s]", v, strings.Join(tags, ", "))
}
buildInfo.Reset()
buildInfo.With(prometheus.Labels{
"program": program,
"version": Version,
"codename": Codename,
"goversion": runtime.Version(),
"builduser": fmt.Sprintf("%s@%s", User, Host),
"builddate": Date.UTC().Format("2006-01-02 15:04:05 MST"),
"tags": strings.Join(tags, ","),
}).Set(1)
return v
}