24e8161262
- add base structure - unify the proto metrics creation and propagation - implement arp and openvpn - refactor to meet the prom exporter standart - add instance label to the metrics - refactor the call chain - add gateway, unbound_dns and openvpn implementations - add gateway stuff - structure refactor; mod clean; cron implementation - implement cron in the collector; refactor utils in the opnsense package refactor names and implement option functions to disable collectorInstances add GH action workflows Create codeql.yml - clean fix stuff
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package collector
|
|
|
|
import (
|
|
"github.com/go-kit/log"
|
|
"github.com/go-kit/log/level"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/st3ga/opnsense-exporter/opnsense"
|
|
)
|
|
|
|
type unboundDNSCollector struct {
|
|
log log.Logger
|
|
subsystem string
|
|
instance string
|
|
uptime *prometheus.Desc
|
|
}
|
|
|
|
func init() {
|
|
collectorInstances = append(collectorInstances, &unboundDNSCollector{
|
|
subsystem: "unbound_dns",
|
|
})
|
|
}
|
|
|
|
func (c *unboundDNSCollector) Name() string {
|
|
return c.subsystem
|
|
}
|
|
|
|
func (c *unboundDNSCollector) Register(namespace, instanceLabel string, log log.Logger) {
|
|
c.log = log
|
|
c.instance = instanceLabel
|
|
level.Debug(c.log).
|
|
Log("msg", "Registering collector", "collector", c.Name())
|
|
|
|
c.uptime = buildPrometheusDesc(c.subsystem, "uptime_seconds",
|
|
"Uptime of the unbound DNS service in seconds",
|
|
nil,
|
|
)
|
|
|
|
}
|
|
|
|
func (c *unboundDNSCollector) Describe(ch chan<- *prometheus.Desc) {
|
|
ch <- c.uptime
|
|
}
|
|
|
|
func (c *unboundDNSCollector) Update(client *opnsense.Client, ch chan<- prometheus.Metric) *opnsense.APICallError {
|
|
data, err := client.FetchUnboundOverview()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
ch <- prometheus.MustNewConstMetric(
|
|
c.uptime,
|
|
prometheus.GaugeValue,
|
|
float64(data.UptimeSeconds),
|
|
c.instance,
|
|
)
|
|
|
|
return nil
|
|
}
|