diff --git a/cmd/run.go b/cmd/run.go index bce9889..1058ec7 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -41,6 +41,7 @@ var runCmd = &cobra.Command{ } metrics := prometheus.New() + metrics.SetBuildInfo(cmd.Version) manager := manager.New(repository, metrics, gitConfig.Path, cfg.Hostname, machineId) go poller.Poller(manager, cfg.Remotes) http.Serve(manager, diff --git a/internal/prometheus/prometheus.go b/internal/prometheus/prometheus.go index 45659fd..d4f2297 100644 --- a/internal/prometheus/prometheus.go +++ b/internal/prometheus/prometheus.go @@ -9,12 +9,17 @@ import ( type Prometheus struct { promRegistry *prometheus.Registry + buildInfo *prometheus.GaugeVec deploymentInfo *prometheus.GaugeVec fetchCounter *prometheus.CounterVec } func New() Prometheus { promReg := prometheus.NewRegistry() + buildInfo := prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "comin_build_info", + Help: "Build info for comin.", + }, []string{"version"}) deploymentInfo := prometheus.NewGaugeVec(prometheus.GaugeOpts{ Name: "comin_deployment_info", Help: "Info of the last deployment.", @@ -23,10 +28,12 @@ func New() Prometheus { Name: "comin_fetch_count", Help: "Number of fetches per status", }, []string{"remote_name", "status"}) + promReg.MustRegister(buildInfo) promReg.MustRegister(deploymentInfo) promReg.MustRegister(fetchCounter) return Prometheus{ promRegistry: promReg, + buildInfo: buildInfo, deploymentInfo: deploymentInfo, fetchCounter: fetchCounter, } @@ -44,6 +51,11 @@ func (m Prometheus) IncFetchCounter(remoteName, status string) { m.fetchCounter.With(prometheus.Labels{"remote_name": remoteName, "status": status}).Inc() } +func (m Prometheus) SetBuildInfo(version string) { + m.buildInfo.Reset() + m.buildInfo.With(prometheus.Labels{"version": version}).Set(1) +} + func (m Prometheus) SetDeploymentInfo(commitId, status string) { m.deploymentInfo.Reset() m.deploymentInfo.With(prometheus.Labels{"commit_id": commitId, "status": status}).Set(1)