diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 08:15:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 08:15:20 +0000 |
commit | 87d772a7d708fec12f48cd8adc0dedff6e1025da (patch) | |
tree | 1fee344c64cc3f43074a01981e21126c8482a522 /src/go/plugin/go.d/modules/monit/charts.go | |
parent | Adding upstream version 1.46.3. (diff) | |
download | netdata-87d772a7d708fec12f48cd8adc0dedff6e1025da.tar.xz netdata-87d772a7d708fec12f48cd8adc0dedff6e1025da.zip |
Adding upstream version 1.47.0.upstream/1.47.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/go/plugin/go.d/modules/monit/charts.go | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/go/plugin/go.d/modules/monit/charts.go b/src/go/plugin/go.d/modules/monit/charts.go new file mode 100644 index 000000000..58fcf6c78 --- /dev/null +++ b/src/go/plugin/go.d/modules/monit/charts.go @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package monit + +import ( + "fmt" + "strings" + + "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module" +) + +const ( + prioServiceCheckStatus = module.Priority + iota + prioUptime +) + +var baseCharts = module.Charts{ + uptimeChart.Copy(), +} + +var ( + uptimeChart = module.Chart{ + ID: "uptime", + Title: "Uptime", + Units: "seconds", + Fam: "uptime", + Ctx: "monit.uptime", + Priority: prioUptime, + Dims: module.Dims{ + {ID: "uptime"}, + }, + } +) + +var serviceCheckChartsTmpl = module.Charts{ + serviceCheckStatusChartTmpl.Copy(), +} + +var ( + serviceCheckStatusChartTmpl = module.Chart{ + ID: "service_check_type_%s_name_%s_status", + Title: "Service Check Status", + Units: "status", + Fam: "service status", + Ctx: "monit.service_check_status", + Priority: prioServiceCheckStatus, + Dims: module.Dims{ + {ID: "service_check_type_%s_name_%s_status_ok", Name: "ok"}, + {ID: "service_check_type_%s_name_%s_status_error", Name: "error"}, + {ID: "service_check_type_%s_name_%s_status_initializing", Name: "initializing"}, + {ID: "service_check_type_%s_name_%s_status_not_monitored", Name: "not_monitored"}, + }, + } +) + +func (m *Monit) addServiceCheckCharts(svc statusServiceCheck, srv *statusServer) { + charts := serviceCheckChartsTmpl.Copy() + + for _, chart := range *charts { + chart.ID = cleanChartId(fmt.Sprintf(chart.ID, svc.svcType(), svc.Name)) + chart.Labels = []module.Label{ + {Key: "server_hostname", Value: srv.LocalHostname}, + {Key: "service_check_name", Value: svc.Name}, + {Key: "service_check_type", Value: svc.svcType()}, + } + for _, dim := range chart.Dims { + dim.ID = fmt.Sprintf(dim.ID, svc.svcType(), svc.Name) + } + } + + if err := m.Charts().Add(*charts...); err != nil { + m.Warning(err) + } +} + +func (m *Monit) removeServiceCharts(svc statusServiceCheck) { + px := fmt.Sprintf("service_check_type_%s_name_%s_", svc.svcType(), svc.Name) + px = cleanChartId(px) + + for _, chart := range *m.Charts() { + if strings.HasPrefix(chart.ID, px) { + chart.MarkRemove() + chart.MarkNotCreated() + } + } +} + +func cleanChartId(s string) string { + r := strings.NewReplacer(" ", "_", ".", "_", ",", "_") + return r.Replace(s) +} |