chore: add version metric
package version
-import "fmt"
+import (
+ "fmt"
+
+ "github.com/prometheus/client_golang/prometheus"
+ "github.com/prometheus/client_golang/prometheus/promauto"
+
+ "d7y.io/dragonfly/v2/internal/constants"
+)
var (
Major = "2"
@@ -30,6 +37,18 @@ var (
Gogcflags = "unknown"
)
+var (
+ versionGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
+ Namespace: constants.MetricsNamespace,
+ Name: "version",
+ Help: "Version info of dragonfly components.",
+ }, []string{"major", "minor", "git_version", "git_commit", "platform", "build_time", "go_version", "go_tags", "go_gcflags"})
+)
+
+func init() {
+ versionGauge.WithLabelValues(Major, Minor, GitVersion, GitCommit, Platform, BuildTime, GoVersion, Gotags, Gogcflags).Set(1)
+}
+
func Version() string {
return fmt.Sprintf("Major: %s, Minor: %s, GitVersion: %s, GitCommit: %s, Platform: %s, BuildTime: %s, GoVersion: %s, Gotags: %s, Gogcflags: %s", Major,
Minor, GitVersion, GitCommit, Platform, BuildTime, GoVersion, Gotags, Gogcflags)
