summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/consul/collect_config.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 11:19:16 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-07-24 09:53:24 +0000
commitb5f8ee61a7f7e9bd291dd26b0585d03eb686c941 (patch)
treed4d31289c39fc00da064a825df13a0b98ce95b10 /src/go/collectors/go.d.plugin/modules/consul/collect_config.go
parentAdding upstream version 1.44.3. (diff)
downloadnetdata-upstream.tar.xz
netdata-upstream.zip
Adding upstream version 1.46.3.upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/go/collectors/go.d.plugin/modules/consul/collect_config.go71
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
+}