diff --git a/agent/agent.go b/agent/agent.go index ff3b800d1f..952ab863b1 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -18,6 +18,7 @@ import ( "time" "github.com/armon/go-metrics" + "github.com/armon/go-metrics/prometheus" "github.com/hashicorp/go-connlimit" "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-memdb" @@ -614,9 +615,22 @@ func (a *Agent) Start(ctx context.Context) error { a.logger.Warn("DEPRECATED Backwards compatibility with pre-1.9 metrics enabled. These metrics will be removed in a future version of Consul. Set `telemetry { disable_compat_1.9 = true }` to disable them.") } + // consul version metric with labels + metrics.SetGaugeWithLabels([]string{"version"}, 1, []metrics.Label{ + {Name: "version", Value: a.config.Version}, + {Name: "pre_release", Value: a.config.VersionPrerelease}, + }) + return nil } +var Gauges = []prometheus.GaugeDefinition{ + { + Name: []string{"version"}, + Help: "Represents the Consul version.", + }, +} + // Failed returns a channel which is closed when the first server goroutine exits // with a non-nil error. func (a *Agent) Failed() <-chan struct{} { diff --git a/agent/setup.go b/agent/setup.go index 9efc565c92..ccf9c08d14 100644 --- a/agent/setup.go +++ b/agent/setup.go @@ -199,6 +199,7 @@ func getPrometheusDefs(cfg lib.TelemetryConfig) ([]prometheus.GaugeDefinition, [ consul.SessionGauges, grpc.StatsGauges, usagemetrics.Gauges, + Gauges, } // Flatten definitions // NOTE(kit): Do we actually want to create a set here so we can ensure definition names are unique? diff --git a/website/pages/docs/agent/telemetry.mdx b/website/pages/docs/agent/telemetry.mdx index 3fb3b35052..e84ef07215 100644 --- a/website/pages/docs/agent/telemetry.mdx +++ b/website/pages/docs/agent/telemetry.mdx @@ -183,6 +183,7 @@ This is a full list of metrics emitted by Consul. | `consul.dns.ptr_query.` | This measures the time spent handling a reverse DNS query for the given node. | ms | timer | | `consul.dns.domain_query.` | This measures the time spent handling a domain query for the given node. | ms | timer | | `consul.http...` | DEPRECATED IN 1.9: This tracks how long it takes to service the given HTTP request for the given verb and path. Paths do not include details like service or key names, for these an underscore will be present as a placeholder (eg. `consul.http.GET.v1.kv._`) | ms | timer | +| `consul.version | This metric measures the count of running agents. | agents | guage | ## Server Health