diff options
author | Ilya Mashchenko <ilya@netdata.cloud> | 2024-05-09 17:11:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-09 17:11:22 +0300 |
commit | ee1969a4a80641fa084d4a2c30bc2c8f8680d6df (patch) | |
tree | cd75116d7160d2658c9010059e4dff25e3aee222 /src | |
parent | a23be5f046be0a4aa60415dd812e4800cf72dc91 (diff) |
go.d isc_dhcpd create a chart for each pool (#17629)
Diffstat (limited to 'src')
6 files changed, 143 insertions, 116 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/isc_dhcpd/charts.go b/src/go/collectors/go.d.plugin/modules/isc_dhcpd/charts.go index 4763a8ab11..7165bbffb9 100644 --- a/src/go/collectors/go.d.plugin/modules/isc_dhcpd/charts.go +++ b/src/go/collectors/go.d.plugin/modules/isc_dhcpd/charts.go @@ -6,30 +6,52 @@ import ( "github.com/netdata/netdata/go/go.d.plugin/agent/module" ) +const ( + prioLeasesTotal = module.Priority + iota + + prioDHCPPoolUtilization + prioDHCPPoolActiveLeases +) + var activeLeasesTotalChart = module.Chart{ - ID: "active_leases_total", - Title: "Active Leases Total", - Units: "leases", - Fam: "summary", - Ctx: "isc_dhcpd.active_leases_total", + ID: "active_leases_total", + Title: "Active Leases Total", + Units: "leases", + Fam: "summary", + Ctx: "isc_dhcpd.active_leases_total", + Priority: prioLeasesTotal, Dims: module.Dims{ {ID: "active_leases_total", Name: "active"}, }, } +var dhcpPoolChartsTmpl = module.Charts{ + dhcpPoolActiveLeasesChartTmpl.Copy(), + dhcpPoolUtilizationChartTmpl.Copy(), +} + var ( - poolActiveLeasesChart = module.Chart{ - ID: "pool_active_leases", - Title: "Pool Active Leases", - Units: "leases", - Fam: "pools", - Ctx: "isc_dhcpd.pool_active_leases", + dhcpPoolUtilizationChartTmpl = module.Chart{ + ID: "dhcp_pool_%s_utilization", + Title: "DHCP Pool Utilization", + Units: "percent", + Fam: "pools", + Ctx: "isc_dhcpd.dhcp_pool_utilization", + Priority: prioDHCPPoolUtilization, + Type: module.Area, + Dims: module.Dims{ + {ID: "dhcp_pool_%s_utilization", Name: "utilization"}, + }, } - poolUtilizationChart = module.Chart{ - ID: "pool_utilization", - Title: "Pool Utilization", - Units: "percentage", - Fam: "pools", - Ctx: "isc_dhcpd.pool_utilization", + dhcpPoolActiveLeasesChartTmpl = module.Chart{ + ID: "dhcp_pool_%s_active_leases", + Title: "DHCP Pool Active Leases", + Units: "leases", + Fam: "pools", + Ctx: "isc_dhcpd.dhcp_pool_active_leases", + Priority: prioDHCPPoolActiveLeases, + Dims: module.Dims{ + {ID: "dhcp_pool_%s_active_leases", Name: "active"}, + }, } ) diff --git a/src/go/collectors/go.d.plugin/modules/isc_dhcpd/collect.go b/src/go/collectors/go.d.plugin/modules/isc_dhcpd/collect.go index 6930e8770f..08716a1081 100644 --- a/src/go/collectors/go.d.plugin/modules/isc_dhcpd/collect.go +++ b/src/go/collectors/go.d.plugin/modules/isc_dhcpd/collect.go @@ -54,8 +54,8 @@ const precision = 100 func collectPool(collected map[string]int64, pool ipPool, leases []leaseEntry) { n := calcPoolActiveLeases(pool, leases) - collected["pool_"+pool.name+"_active_leases"] = n - collected["pool_"+pool.name+"_utilization"] = int64(calcPoolUtilizationPercentage(pool, n) * precision) + collected["dhcp_pool_"+pool.name+"_active_leases"] = n + collected["dhcp_pool_"+pool.name+"_utilization"] = int64(calcPoolUtilizationPercentage(pool, n) * precision) } func calcPoolActiveLeases(pool ipPool, leases []leaseEntry) (num int64) { diff --git a/src/go/collectors/go.d.plugin/modules/isc_dhcpd/init.go b/src/go/collectors/go.d.plugin/modules/isc_dhcpd/init.go index 2261adab1b..861ded398f 100644 --- a/src/go/collectors/go.d.plugin/modules/isc_dhcpd/init.go +++ b/src/go/collectors/go.d.plugin/modules/isc_dhcpd/init.go @@ -5,6 +5,7 @@ package isc_dhcpd import ( "errors" "fmt" + "strings" "github.com/netdata/netdata/go/go.d.plugin/agent/module" "github.com/netdata/netdata/go/go.d.plugin/pkg/iprange" @@ -35,18 +36,20 @@ func (d *DHCPd) validateConfig() error { func (d *DHCPd) initPools() ([]ipPool, error) { var pools []ipPool + for i, cfg := range d.Pools { - rs, err := iprange.ParseRanges(cfg.Networks) + ipRange, err := iprange.ParseRanges(cfg.Networks) if err != nil { return nil, fmt.Errorf("parse pools[%d]->pool.networks '%s' ('%s'): %v", i+1, cfg.Name, cfg.Networks, err) } - if len(rs) != 0 { - pools = append(pools, ipPool{ - name: cfg.Name, - addresses: rs, - }) + if len(ipRange) == 0 { + continue } + + pool := ipPool{name: cfg.Name, addresses: ipRange} + pools = append(pools, pool) } + return pools, nil } @@ -57,34 +60,29 @@ func (d *DHCPd) initCharts(pools []ipPool) (*module.Charts, error) { return nil, err } - chart := poolActiveLeasesChart.Copy() - if err := charts.Add(chart); err != nil { - return nil, err - } for _, pool := range pools { - dim := &module.Dim{ - ID: "pool_" + pool.name + "_active_leases", - Name: pool.name, - } - if err := chart.AddDim(dim); err != nil { - return nil, err - } - } + poolCharts := dhcpPoolChartsTmpl.Copy() - chart = poolUtilizationChart.Copy() - if err := charts.Add(chart); err != nil { - return nil, err - } - for _, pool := range pools { - dim := &module.Dim{ - ID: "pool_" + pool.name + "_utilization", - Name: pool.name, - Div: precision, + for _, chart := range *poolCharts { + chart.ID = fmt.Sprintf(chart.ID, cleanPoolNameForChart(pool.name)) + chart.Labels = []module.Label{ + {Key: "dhcp_pool_name", Value: pool.name}, + } + for _, dim := range chart.Dims { + dim.ID = fmt.Sprintf(dim.ID, pool.name) + } } - if err := chart.AddDim(dim); err != nil { + + if err := charts.Add(*poolCharts...); err != nil { return nil, err } } return charts, nil } + +func cleanPoolNameForChart(name string) string { + name = strings.ReplaceAll(name, " ", "_") + name = strings.ReplaceAll(name, ".", "_") + return name +} diff --git a/src/go/collectors/go.d.plugin/modules/isc_dhcpd/isc_dhcpd.go b/src/go/collectors/go.d.plugin/modules/isc_dhcpd/isc_dhcpd.go index 087f1f95a4..cdeb4da84d 100644 --- a/src/go/collectors/go.d.plugin/modules/isc_dhcpd/isc_dhcpd.go +++ b/src/go/collectors/go.d.plugin/modules/isc_dhcpd/isc_dhcpd.go @@ -35,9 +35,10 @@ func New() *DHCPd { type ( Config struct { - UpdateEvery int `yaml:"update_every" json:"update_every"` - LeasesPath string `yaml:"leases_path" json:"leases_path"` - Pools []PoolConfig `yaml:"pools" json:"pools"` + UpdateEvery int `yaml:"update_every" json:"update_every"` + LeasesPath string `yaml:"leases_path" json:"leases_path"` + // TODO: parse config file to extract configured pool + Pools []PoolConfig `yaml:"pools" json:"pools"` } PoolConfig struct { Name string `yaml:"name" json:"name"` diff --git a/src/go/collectors/go.d.plugin/modules/isc_dhcpd/isc_dhcpd_test.go b/src/go/collectors/go.d.plugin/modules/isc_dhcpd/isc_dhcpd_test.go index 03d98311a6..d91dfca159 100644 --- a/src/go/collectors/go.d.plugin/modules/isc_dhcpd/isc_dhcpd_test.go +++ b/src/go/collectors/go.d.plugin/modules/isc_dhcpd/isc_dhcpd_test.go @@ -140,83 +140,83 @@ func TestDHCPd_Collect(t *testing.T) { "lease db is an empty file": { prepare: prepareDHCPdLeasesEmpty, wantCollected: map[string]int64{ - "active_leases_total": 0, - "pool_net1_active_leases": 0, - "pool_net1_utilization": 0, - "pool_net2_active_leases": 0, - "pool_net2_utilization": 0, - "pool_net3_active_leases": 0, - "pool_net3_utilization": 0, - "pool_net4_active_leases": 0, - "pool_net4_utilization": 0, - "pool_net5_active_leases": 0, - "pool_net5_utilization": 0, - "pool_net6_active_leases": 0, - "pool_net6_utilization": 0, + "active_leases_total": 0, + "dhcp_pool_net1_active_leases": 0, + "dhcp_pool_net1_utilization": 0, + "dhcp_pool_net2_active_leases": 0, + "dhcp_pool_net2_utilization": 0, + "dhcp_pool_net3_active_leases": 0, + "dhcp_pool_net3_utilization": 0, + "dhcp_pool_net4_active_leases": 0, + "dhcp_pool_net4_utilization": 0, + "dhcp_pool_net5_active_leases": 0, + "dhcp_pool_net5_utilization": 0, + "dhcp_pool_net6_active_leases": 0, + "dhcp_pool_net6_utilization": 0, }, }, "lease db ipv4": { prepare: prepareDHCPdLeasesIPv4, wantCollected: map[string]int64{ - "active_leases_total": 5, - "pool_net1_active_leases": 2, - "pool_net1_utilization": 158, - "pool_net2_active_leases": 1, - "pool_net2_utilization": 39, - "pool_net3_active_leases": 0, - "pool_net3_utilization": 0, - "pool_net4_active_leases": 1, - "pool_net4_utilization": 79, - "pool_net5_active_leases": 0, - "pool_net5_utilization": 0, - "pool_net6_active_leases": 1, - "pool_net6_utilization": 39, + "active_leases_total": 5, + "dhcp_pool_net1_active_leases": 2, + "dhcp_pool_net1_utilization": 158, + "dhcp_pool_net2_active_leases": 1, + "dhcp_pool_net2_utilization": 39, + "dhcp_pool_net3_active_leases": 0, + "dhcp_pool_net3_utilization": 0, + "dhcp_pool_net4_active_leases": 1, + "dhcp_pool_net4_utilization": 79, + "dhcp_pool_net5_active_leases": 0, + "dhcp_pool_net5_utilization": 0, + "dhcp_pool_net6_active_leases": 1, + "dhcp_pool_net6_utilization": 39, }, }, "lease db ipv4 with only inactive leases": { prepare: prepareDHCPdLeasesIPv4Inactive, wantCollected: map[string]int64{ - "active_leases_total": 0, - "pool_net1_active_leases": 0, - "pool_net1_utilization": 0, - "pool_net2_active_leases": 0, - "pool_net2_utilization": 0, - "pool_net3_active_leases": 0, - "pool_net3_utilization": 0, - "pool_net4_active_leases": 0, - "pool_net4_utilization": 0, - "pool_net5_active_leases": 0, - "pool_net5_utilization": 0, - "pool_net6_active_leases": 0, - "pool_net6_utilization": 0, + "active_leases_total": 0, + "dhcp_pool_net1_active_leases": 0, + "dhcp_pool_net1_utilization": 0, + "dhcp_pool_net2_active_leases": 0, + "dhcp_pool_net2_utilization": 0, + "dhcp_pool_net3_active_leases": 0, + "dhcp_pool_net3_utilization": 0, + "dhcp_pool_net4_active_leases": 0, + "dhcp_pool_net4_utilization": 0, + "dhcp_pool_net5_active_leases": 0, + "dhcp_pool_net5_utilization": 0, + "dhcp_pool_net6_active_leases": 0, + "dhcp_pool_net6_utilization": 0, }, }, "lease db ipv4 with backup leases": { prepare: prepareDHCPdLeasesIPv4Backup, wantCollected: map[string]int64{ - "active_leases_total": 2, - "pool_net1_active_leases": 1, - "pool_net1_utilization": 79, - "pool_net2_active_leases": 0, - "pool_net2_utilization": 0, - "pool_net3_active_leases": 0, - "pool_net3_utilization": 0, - "pool_net4_active_leases": 1, - "pool_net4_utilization": 79, - "pool_net5_active_leases": 0, - "pool_net5_utilization": 0, - "pool_net6_active_leases": 0, - "pool_net6_utilization": 0, + "active_leases_total": 2, + "dhcp_pool_net1_active_leases": 1, + "dhcp_pool_net1_utilization": 79, + "dhcp_pool_net2_active_leases": 0, + "dhcp_pool_net2_utilization": 0, + "dhcp_pool_net3_active_leases": 0, + "dhcp_pool_net3_utilization": 0, + "dhcp_pool_net4_active_leases": 1, + "dhcp_pool_net4_utilization": 79, + "dhcp_pool_net5_active_leases": 0, + "dhcp_pool_net5_utilization": 0, + "dhcp_pool_net6_active_leases": 0, + "dhcp_pool_net6_utilization": 0, }, }, "lease db ipv6": { prepare: prepareDHCPdLeasesIPv6, wantCollected: map[string]int64{ - "active_leases_total": 6, - "pool_net1_active_leases": 6, - "pool_net1_utilization": 5454, - "pool_net2_active_leases": 0, - "pool_net2_utilization": 0, + "active_leases_total": 6, + "dhcp_pool_net1_active_leases": 6, + "dhcp_pool_net1_utilization": 5454, + "dhcp_pool_net2_active_leases": 0, + "dhcp_pool_net2_utilization": 0, }, }, } diff --git a/src/go/collectors/go.d.plugin/modules/isc_dhcpd/metadata.yaml b/src/go/collectors/go.d.plugin/modules/isc_dhcpd/metadata.yaml index 56ff3a0457..e6e11d72e1 100644 --- a/src/go/collectors/go.d.plugin/modules/isc_dhcpd/metadata.yaml +++ b/src/go/collectors/go.d.plugin/modules/isc_dhcpd/metadata.yaml @@ -115,15 +115,21 @@ modules: chart_type: line dimensions: - name: active - - name: isc_dhcpd.pool_active_leases - description: Pool Active Leases - unit: leases - chart_type: line + - name: global + description: These metrics refer to the DHCP pool. + labels: + - name: dhcp_pool_name + description: The DHCP pool name defined in the collector configuration. + metrics: + - name: isc_dhcpd.dhcp_pool_utilization + description: DHCP Pool Utilization + unit: percent + chart_type: area dimensions: - - name: a dimension per DHCP pool - - name: isc_dhcpd.pool_utilization - description: Pool Utilization - unit: percentage + - name: utilization + - name: isc_dhcpd.dhcp_pool_active_leases + description: Active Leases Total + unit: leases chart_type: line dimensions: - - name: a dimension per DHCP pool + - name: active |