From 87d772a7d708fec12f48cd8adc0dedff6e1025da Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 26 Aug 2024 10:15:20 +0200 Subject: Adding upstream version 1.47.0. Signed-off-by: Daniel Baumann --- src/go/plugin/go.d/modules/dnsmasq_dhcp/charts.go | 111 ++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/go/plugin/go.d/modules/dnsmasq_dhcp/charts.go (limited to 'src/go/plugin/go.d/modules/dnsmasq_dhcp/charts.go') diff --git a/src/go/plugin/go.d/modules/dnsmasq_dhcp/charts.go b/src/go/plugin/go.d/modules/dnsmasq_dhcp/charts.go new file mode 100644 index 000000000..bcef8aa3f --- /dev/null +++ b/src/go/plugin/go.d/modules/dnsmasq_dhcp/charts.go @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package dnsmasq_dhcp + +import ( + "fmt" + "strings" + + "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module" +) + +const ( + prioDHCPRangeUtilization = module.Priority + iota + prioDHCPRangeAllocatesLeases + prioDHCPRanges + prioDHCPHosts +) + +var charts = module.Charts{ + { + ID: "dhcp_ranges", + Title: "Number of DHCP Ranges", + Units: "ranges", + Fam: "dhcp ranges", + Ctx: "dnsmasq_dhcp.dhcp_ranges", + Type: module.Stacked, + Priority: prioDHCPRanges, + Dims: module.Dims{ + {ID: "ipv4_dhcp_ranges", Name: "ipv4"}, + {ID: "ipv6_dhcp_ranges", Name: "ipv6"}, + }, + }, + { + ID: "dhcp_hosts", + Title: "Number of DHCP Hosts", + Units: "hosts", + Fam: "dhcp hosts", + Ctx: "dnsmasq_dhcp.dhcp_host", + Type: module.Stacked, + Priority: prioDHCPHosts, + Dims: module.Dims{ + {ID: "ipv4_dhcp_hosts", Name: "ipv4"}, + {ID: "ipv6_dhcp_hosts", Name: "ipv6"}, + }, + }, +} + +var ( + chartsTmpl = module.Charts{ + chartTmplDHCPRangeUtilization.Copy(), + chartTmplDHCPRangeAllocatedLeases.Copy(), + } +) + +var ( + chartTmplDHCPRangeUtilization = module.Chart{ + ID: "dhcp_range_%s_utilization", + Title: "DHCP Range utilization", + Units: "percentage", + Fam: "dhcp range utilization", + Ctx: "dnsmasq_dhcp.dhcp_range_utilization", + Type: module.Area, + Priority: prioDHCPRangeUtilization, + Dims: module.Dims{ + {ID: "dhcp_range_%s_utilization", Name: "used"}, + }, + } + chartTmplDHCPRangeAllocatedLeases = module.Chart{ + ID: "dhcp_range_%s_allocated_leases", + Title: "DHCP Range Allocated Leases", + Units: "leases", + Fam: "dhcp range leases", + Ctx: "dnsmasq_dhcp.dhcp_range_allocated_leases", + Priority: prioDHCPRangeAllocatesLeases, + Dims: module.Dims{ + {ID: "dhcp_range_%s_allocated_leases", Name: "leases"}, + }, + } +) + +func newDHCPRangeCharts(dhcpRange string) *module.Charts { + charts := chartsTmpl.Copy() + + for _, c := range *charts { + c.ID = fmt.Sprintf(c.ID, dhcpRange) + c.Labels = []module.Label{ + {Key: "dhcp_range", Value: dhcpRange}, + } + for _, d := range c.Dims { + d.ID = fmt.Sprintf(d.ID, dhcpRange) + } + } + return charts +} + +func (d *DnsmasqDHCP) addDHCPRangeCharts(dhcpRange string) { + charts := newDHCPRangeCharts(dhcpRange) + if err := d.Charts().Add(*charts...); err != nil { + d.Warning(err) + } +} + +func (d *DnsmasqDHCP) removeDHCPRangeCharts(dhcpRange string) { + p := "dhcp_range_" + dhcpRange + for _, c := range *d.Charts() { + if strings.HasSuffix(c.ID, p) { + c.MarkRemove() + c.MarkNotCreated() + } + } +} -- cgit v1.2.3