master
go 54 lines 1.26 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package consul
4
5 import "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/oldmetrix"
6
7 const (
8 // https://www.consul.io/api-docs/agent/check#list-checks
9 urlPathAgentChecks = "/v1/agent/checks"
10 )
11
12 type agentCheck struct {
13 Node string
14 CheckID string
15 Name string
16 Status string
17 ServiceID string
18 ServiceName string
19 ServiceTags []string
20 }
21
22 func (c *Collector) collectChecks(mx map[string]int64) error {
23 req, err := c.createRequest(urlPathAgentChecks)
24 if err != nil {
25 return err
26 }
27
28 var checks map[string]*agentCheck
29
30 if err := c.client().RequestJSON(req, &checks); err != nil {
31 return err
32 }
33
34 for id, check := range checks {
35 if !c.checks[id] {
36 c.checks[id] = true
37 c.addHealthCheckCharts(check)
38 }
39
40 mx["health_check_"+id+"_passing_status"] = oldmetrix.Bool(check.Status == "passing")
41 mx["health_check_"+id+"_warning_status"] = oldmetrix.Bool(check.Status == "warning")
42 mx["health_check_"+id+"_critical_status"] = oldmetrix.Bool(check.Status == "critical")
43 mx["health_check_"+id+"_maintenance_status"] = oldmetrix.Bool(check.Status == "maintenance")
44 }
45
46 for id := range c.checks {
47 if _, ok := checks[id]; !ok {
48 delete(c.checks, id)
49 c.removeHealthCheckCharts(id)
50 }
51 }
52
53 return nil
54 }