This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(consul): collect prometheus key metrics
- Loading branch information
Showing
16 changed files
with
4,487 additions
and
583 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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 | ||
} | ||
} | ||
} | ||
} | ||
|
||
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) | ||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.