Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions bind_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ var (
nil, nil,
),
}
// serverMetricGauges lists the serverMetricStats entries that report a
// current value rather than a running total. BIND reports them in the same
// statistics counters as the totals, so they have to be typed explicitly.
serverMetricGauges = map[string]struct{}{
"RecursClients": {},
}
tasksRunning = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "tasks_running"),
"Number of running tasks.",
Expand Down Expand Up @@ -280,7 +286,7 @@ func (c *serverCollector) Collect(ch chan<- prometheus.Metric) {
}
if desc, ok := serverMetricStats[s.Name]; ok {
ch <- prometheus.MustNewConstMetric(
desc, prometheus.CounterValue, float64(s.Counter),
desc, serverMetricValueType(s.Name), float64(s.Counter),
)
}
}
Expand All @@ -292,12 +298,21 @@ func (c *serverCollector) Collect(ch chan<- prometheus.Metric) {
for _, s := range c.stats.Server.ZoneStatistics {
if desc, ok := serverMetricStats[s.Name]; ok {
ch <- prometheus.MustNewConstMetric(
desc, prometheus.CounterValue, float64(s.Counter),
desc, serverMetricValueType(s.Name), float64(s.Counter),
)
}
}
}

// serverMetricValueType reports the value type to use for a serverMetricStats
// entry.
func serverMetricValueType(name string) prometheus.ValueType {
if _, ok := serverMetricGauges[name]; ok {
return prometheus.GaugeValue
}
return prometheus.CounterValue
}

type viewCollector struct {
logger *slog.Logger
stats *bind.Statistics
Expand Down
2 changes: 2 additions & 0 deletions bind_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ var (
`bind_zone_transfer_success_total 25`,
`bind_zone_transfer_failure_total 1`,
`bind_recursive_clients 76`,
// Current recursive clients is a gauge, not a counter.
`# TYPE bind_recursive_clients gauge`,
`bind_config_time_seconds 1.626325868e+09`,
`bind_response_rcodes_total{rcode="NOERROR"} 989812`,
`bind_response_rcodes_total{rcode="NXDOMAIN"} 33958`,
Expand Down
Loading