2021-11-16 18:04:01 +00:00
|
|
|
//go:build !consulent
|
2020-09-02 15:24:17 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
|
|
|
package usagemetrics
|
|
|
|
|
2020-10-09 16:01:45 +00:00
|
|
|
import (
|
|
|
|
"github.com/armon/go-metrics"
|
2021-08-18 14:27:15 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/serf/serf"
|
|
|
|
|
2020-10-09 16:01:45 +00:00
|
|
|
"github.com/hashicorp/consul/agent/consul/state"
|
2023-02-08 20:07:21 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2020-10-09 16:01:45 +00:00
|
|
|
)
|
2020-09-02 15:24:17 +00:00
|
|
|
|
2021-08-18 14:27:15 +00:00
|
|
|
func (u *UsageMetricsReporter) emitNodeUsage(nodeUsage state.NodeUsage) {
|
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"consul", "state", "nodes"},
|
|
|
|
float32(nodeUsage.Nodes),
|
|
|
|
u.metricLabels,
|
|
|
|
)
|
2022-09-09 17:13:43 +00:00
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"state", "nodes"},
|
|
|
|
float32(nodeUsage.Nodes),
|
|
|
|
u.metricLabels,
|
|
|
|
)
|
2021-08-18 14:27:15 +00:00
|
|
|
}
|
|
|
|
|
2022-07-27 22:34:04 +00:00
|
|
|
func (u *UsageMetricsReporter) emitPeeringUsage(peeringUsage state.PeeringUsage) {
|
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"consul", "state", "peerings"},
|
|
|
|
float32(peeringUsage.Peerings),
|
|
|
|
u.metricLabels,
|
|
|
|
)
|
2022-09-09 17:13:43 +00:00
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"state", "peerings"},
|
|
|
|
float32(peeringUsage.Peerings),
|
|
|
|
u.metricLabels,
|
|
|
|
)
|
2022-07-27 22:34:04 +00:00
|
|
|
}
|
|
|
|
|
2021-08-18 14:27:15 +00:00
|
|
|
func (u *UsageMetricsReporter) emitMemberUsage(members []serf.Member) {
|
|
|
|
var (
|
|
|
|
servers int
|
|
|
|
clients int
|
|
|
|
)
|
|
|
|
for _, m := range members {
|
|
|
|
switch m.Tags["role"] {
|
|
|
|
case "node":
|
|
|
|
clients++
|
|
|
|
case "consul":
|
|
|
|
servers++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"consul", "members", "clients"},
|
|
|
|
float32(clients),
|
|
|
|
u.metricLabels,
|
|
|
|
)
|
2022-09-09 17:13:43 +00:00
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"members", "clients"},
|
|
|
|
float32(clients),
|
|
|
|
u.metricLabels,
|
|
|
|
)
|
2021-08-18 14:27:15 +00:00
|
|
|
|
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"consul", "members", "servers"},
|
|
|
|
float32(servers),
|
|
|
|
u.metricLabels,
|
|
|
|
)
|
2022-09-09 17:13:43 +00:00
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"members", "servers"},
|
|
|
|
float32(servers),
|
|
|
|
u.metricLabels,
|
|
|
|
)
|
2021-08-18 14:27:15 +00:00
|
|
|
}
|
|
|
|
|
2023-02-08 20:07:21 +00:00
|
|
|
func (u *UsageMetricsReporter) emitServiceUsage(serviceUsage structs.ServiceUsage) {
|
2020-10-09 16:01:45 +00:00
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"consul", "state", "services"},
|
|
|
|
float32(serviceUsage.Services),
|
|
|
|
u.metricLabels,
|
|
|
|
)
|
2022-09-09 17:13:43 +00:00
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"state", "services"},
|
|
|
|
float32(serviceUsage.Services),
|
|
|
|
u.metricLabels,
|
|
|
|
)
|
2020-10-09 16:01:45 +00:00
|
|
|
|
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"consul", "state", "service_instances"},
|
|
|
|
float32(serviceUsage.ServiceInstances),
|
|
|
|
u.metricLabels,
|
|
|
|
)
|
2022-09-09 17:13:43 +00:00
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"state", "service_instances"},
|
|
|
|
float32(serviceUsage.ServiceInstances),
|
|
|
|
u.metricLabels,
|
|
|
|
)
|
2023-02-08 20:07:21 +00:00
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"state", "billable_service_instances"},
|
|
|
|
float32(serviceUsage.BillableServiceInstances),
|
|
|
|
u.metricLabels,
|
|
|
|
)
|
2021-09-30 21:15:26 +00:00
|
|
|
|
|
|
|
for k, i := range serviceUsage.ConnectServiceInstances {
|
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"consul", "state", "connect_instances"},
|
|
|
|
float32(i),
|
|
|
|
append(u.metricLabels, metrics.Label{Name: "kind", Value: k}),
|
|
|
|
)
|
2022-09-09 17:13:43 +00:00
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"state", "connect_instances"},
|
|
|
|
float32(i),
|
|
|
|
append(u.metricLabels, metrics.Label{Name: "kind", Value: k}),
|
|
|
|
)
|
2021-09-30 21:15:26 +00:00
|
|
|
}
|
2020-10-09 16:01:45 +00:00
|
|
|
}
|
2021-09-17 19:36:34 +00:00
|
|
|
|
|
|
|
func (u *UsageMetricsReporter) emitKVUsage(kvUsage state.KVUsage) {
|
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"consul", "state", "kv_entries"},
|
|
|
|
float32(kvUsage.KVCount),
|
|
|
|
u.metricLabels,
|
|
|
|
)
|
2022-09-09 17:13:43 +00:00
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"state", "kv_entries"},
|
|
|
|
float32(kvUsage.KVCount),
|
|
|
|
u.metricLabels,
|
|
|
|
)
|
2021-09-17 19:36:34 +00:00
|
|
|
}
|
2021-10-01 18:22:30 +00:00
|
|
|
|
2021-10-07 21:19:55 +00:00
|
|
|
func (u *UsageMetricsReporter) emitConfigEntryUsage(configUsage state.ConfigEntryUsage) {
|
2021-10-01 18:22:30 +00:00
|
|
|
for k, i := range configUsage.ConfigByKind {
|
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"consul", "state", "config_entries"},
|
|
|
|
float32(i),
|
|
|
|
append(u.metricLabels, metrics.Label{Name: "kind", Value: k}),
|
|
|
|
)
|
2022-09-09 17:13:43 +00:00
|
|
|
metrics.SetGaugeWithLabels(
|
|
|
|
[]string{"state", "config_entries"},
|
|
|
|
float32(i),
|
|
|
|
append(u.metricLabels, metrics.Label{Name: "kind", Value: k}),
|
|
|
|
)
|
2021-10-01 18:22:30 +00:00
|
|
|
}
|
|
|
|
}
|