Skip to content

Commit

Permalink
add new counter for dns messages operations
Browse files Browse the repository at this point in the history
  • Loading branch information
dmachard committed Oct 23, 2024
1 parent 75e4b5b commit 029b8e0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions workers/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type EpsCounters struct {

TotalRcodes, TotalQtypes map[string]float64
TotalIPVersion, TotalIPProtocol map[string]float64
TotalOperations map[string]float64
TotalDNSMessages float64
TotalQueries, TotalReplies int
TotalBytes, TotalBytesSent, TotalBytesReceived int
Expand Down Expand Up @@ -166,6 +167,7 @@ type Prometheus struct {
counterQtypes, counterRcodes *prometheus.Desc
counterIPProtocol, counterIPVersion *prometheus.Desc
counterDNSMessages, counterDNSQueries, counterDNSReplies *prometheus.Desc
counterOperations *prometheus.Desc

counterFlagsTC, counterFlagsAA *prometheus.Desc
counterFlagsRA, counterFlagsAD *prometheus.Desc
Expand Down Expand Up @@ -196,6 +198,7 @@ func newPrometheusCounterSet(w *Prometheus, labels prometheus.Labels) *Prometheu
epsCounters: EpsCounters{
TotalRcodes: make(map[string]float64), TotalQtypes: make(map[string]float64),
TotalIPVersion: make(map[string]float64), TotalIPProtocol: make(map[string]float64),
TotalOperations: make(map[string]float64),
},

topRequesters: topmap.NewTopMap(w.GetConfig().Loggers.Prometheus.TopN),
Expand Down Expand Up @@ -248,6 +251,7 @@ func (w *PrometheusCountersSet) Describe(ch chan<- *prometheus.Desc) {

ch <- w.prom.counterQtypes
ch <- w.prom.counterRcodes
ch <- w.prom.counterOperations
ch <- w.prom.counterIPProtocol
ch <- w.prom.counterIPVersion
ch <- w.prom.counterDNSMessages
Expand Down Expand Up @@ -374,6 +378,12 @@ func (w *PrometheusCountersSet) Record(dm dnsutils.DNSMessage) {
w.epsCounters.TotalRcodes[dm.DNS.Rcode]++
}

if _, exists := w.epsCounters.TotalOperations[dm.DNSTap.Operation]; !exists {
w.epsCounters.TotalOperations[dm.DNSTap.Operation] = 1
} else {
w.epsCounters.TotalOperations[dm.DNSTap.Operation]++
}

if dm.DNS.Type == dnsutils.DNSQuery {
w.epsCounters.TotalBytesReceived += dm.DNS.Length
w.epsCounters.TotalQueries++
Expand Down Expand Up @@ -518,6 +528,13 @@ func (w *PrometheusCountersSet) Collect(ch chan<- prometheus.Metric) {
)
}

// Update DNSTap Operations counter
for k, v := range w.epsCounters.TotalOperations {
ch <- prometheus.MustNewConstMetric(w.prom.counterOperations, prometheus.CounterValue,
v, k,
)
}

// Update IP protocol counter
for k, v := range w.epsCounters.TotalIPProtocol {
ch <- prometheus.MustNewConstMetric(w.prom.counterIPProtocol, prometheus.CounterValue,
Expand Down Expand Up @@ -880,6 +897,12 @@ func (w *Prometheus) InitProm() {
[]string{"return_code"}, nil,
)

w.counterOperations = prometheus.NewDesc(
fmt.Sprintf("%s_operations_total", promPrefix),
"Counter of dns messages per operations",
[]string{"operation"}, nil,
)

w.counterIPProtocol = prometheus.NewDesc(
fmt.Sprintf("%s_ipprotocol_total", promPrefix),
"Counter of packets per IP protocol",
Expand Down

0 comments on commit 029b8e0

Please sign in to comment.