diff options
Diffstat (limited to '')
-rw-r--r-- | src/go/collectors/go.d.plugin/modules/consul/collect_config.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/consul/collect_config.go b/src/go/collectors/go.d.plugin/modules/consul/collect_config.go new file mode 100644 index 000000000..14c77067f --- /dev/null +++ b/src/go/collectors/go.d.plugin/modules/consul/collect_config.go @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package consul + +import ( + "github.com/blang/semver/v4" +) + +const ( + // https://developer.hashicorp.com/consul/api-docs/agent#read-configuration + urlPathAgentSelf = "/v1/agent/self" +) + +type consulConfig struct { + Config struct { + Datacenter string + PrimaryDatacenter string + NodeName string + NodeID string + Server bool + Version string + } + DebugConfig struct { + Telemetry struct { + MetricsPrefix string + DisableHostname bool + PrometheusOpts struct { + Expiration string + Name string + } + } + Cloud struct { + AuthURL string + ClientID string + ClientSecret string + Hostname string + ResourceID string + ScadaAddress string + } + } + Stats struct { + License struct { + ID string `json:"id"` + } `json:"license"` + } +} + +func (c *Consul) collectConfiguration() error { + var cfg consulConfig + + if err := c.doOKDecode(urlPathAgentSelf, &cfg); err != nil { + return err + } + + c.cfg = &cfg + c.Debugf("consul config: %+v", cfg) + + if !c.isTelemetryPrometheusEnabled() { + c.Warning("export of Prometheus metrics is disabled") + } + + ver, err := semver.New(c.cfg.Config.Version) + if err != nil { + c.Warningf("error on parsing Consul version '%s': %v", c.cfg.Config.Version, err) + return nil + } + + c.version = ver + + return nil +} |