github.com/netdata/go.d.plugin@v0.58.1/modules/consul/collect_checks.go (about)

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