collect_checks.go 1.2 KB

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