github.com/netdata/go.d.plugin@v0.58.1/modules/dnsmasq_dhcp/charts.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package dnsmasq_dhcp 4 5 import ( 6 "fmt" 7 "strings" 8 9 "github.com/netdata/go.d.plugin/agent/module" 10 ) 11 12 const ( 13 prioDHCPRangeUtilization = module.Priority + iota 14 prioDHCPRangeAllocatesLeases 15 prioDHCPRanges 16 prioDHCPHosts 17 ) 18 19 var charts = module.Charts{ 20 { 21 ID: "dhcp_ranges", 22 Title: "Number of DHCP Ranges", 23 Units: "ranges", 24 Fam: "dhcp ranges", 25 Ctx: "dnsmasq_dhcp.dhcp_ranges", 26 Type: module.Stacked, 27 Priority: prioDHCPRanges, 28 Dims: module.Dims{ 29 {ID: "ipv4_dhcp_ranges", Name: "ipv4"}, 30 {ID: "ipv6_dhcp_ranges", Name: "ipv6"}, 31 }, 32 }, 33 { 34 ID: "dhcp_hosts", 35 Title: "Number of DHCP Hosts", 36 Units: "hosts", 37 Fam: "dhcp hosts", 38 Ctx: "dnsmasq_dhcp.dhcp_host", 39 Type: module.Stacked, 40 Priority: prioDHCPHosts, 41 Dims: module.Dims{ 42 {ID: "ipv4_dhcp_hosts", Name: "ipv4"}, 43 {ID: "ipv6_dhcp_hosts", Name: "ipv6"}, 44 }, 45 }, 46 } 47 48 var ( 49 chartsTmpl = module.Charts{ 50 chartTmplDHCPRangeUtilization.Copy(), 51 chartTmplDHCPRangeAllocatedLeases.Copy(), 52 } 53 ) 54 55 var ( 56 chartTmplDHCPRangeUtilization = module.Chart{ 57 ID: "dhcp_range_%s_utilization", 58 Title: "DHCP Range utilization", 59 Units: "percentage", 60 Fam: "dhcp range utilization", 61 Ctx: "dnsmasq_dhcp.dhcp_range_utilization", 62 Type: module.Area, 63 Priority: prioDHCPRangeUtilization, 64 Dims: module.Dims{ 65 {ID: "dhcp_range_%s_utilization", Name: "used"}, 66 }, 67 } 68 chartTmplDHCPRangeAllocatedLeases = module.Chart{ 69 ID: "dhcp_range_%s_allocated_leases", 70 Title: "DHCP Range Allocated Leases", 71 Units: "leases", 72 Fam: "dhcp range leases", 73 Ctx: "dnsmasq_dhcp.dhcp_range_allocated_leases", 74 Priority: prioDHCPRangeAllocatesLeases, 75 Dims: module.Dims{ 76 {ID: "dhcp_range_%s_allocated_leases", Name: "leases"}, 77 }, 78 } 79 ) 80 81 func newDHCPRangeCharts(dhcpRange string) *module.Charts { 82 charts := chartsTmpl.Copy() 83 84 for _, c := range *charts { 85 c.ID = fmt.Sprintf(c.ID, dhcpRange) 86 c.Labels = []module.Label{ 87 {Key: "dhcp_range", Value: dhcpRange}, 88 } 89 for _, d := range c.Dims { 90 d.ID = fmt.Sprintf(d.ID, dhcpRange) 91 } 92 } 93 return charts 94 } 95 96 func (d *DnsmasqDHCP) addDHCPRangeCharts(dhcpRange string) { 97 charts := newDHCPRangeCharts(dhcpRange) 98 if err := d.Charts().Add(*charts...); err != nil { 99 d.Warning(err) 100 } 101 } 102 103 func (d *DnsmasqDHCP) removeDHCPRangeCharts(dhcpRange string) { 104 p := "dhcp_range_" + dhcpRange 105 for _, c := range *d.Charts() { 106 if strings.HasSuffix(c.ID, p) { 107 c.MarkRemove() 108 c.MarkNotCreated() 109 } 110 } 111 }