Skip to content

Commit

Permalink
fix(prometheus): add link support
Browse files Browse the repository at this point in the history
  • Loading branch information
genofire committed Jul 5, 2024
1 parent 523a5a7 commit 76868ff
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions webserver/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ var (
promDescNodeAirtimeRxUtil = prometheus.NewDesc("yanic_node_airtime_rx_util", "", allLabelsWithFrequency, prometheus.Labels{})
promDescNodeAirtimeNoise = prometheus.NewDesc("yanic_node_airtime_noise", "", allLabelsWithFrequency, prometheus.Labels{})
promDescNodeWirelessTxPower = prometheus.NewDesc("yanic_node_wireless_txpower", "", allLabelsWithFrequency, prometheus.Labels{})

// Links - just necessary
labelLinks = []string{"source_id", "target_id", "source_address", "target_address", "source_hostname", "target_hostname"}
promDescLinkTQ = prometheus.NewDesc("yanic_link_tq", "", labelLinks, prometheus.Labels{})
)

type Prometheus struct {
Expand Down Expand Up @@ -164,6 +168,8 @@ func (prom *Prometheus) Describe(d chan<- *prometheus.Desc) {
d <- promDescNodeAirtimeTxUtil
d <- promDescNodeAirtimeNoise
d <- promDescNodeWirelessTxPower

d <- promDescLinkTQ
}

func (prom *Prometheus) getNodeLabels(ni *data.Nodeinfo) []string {
Expand Down Expand Up @@ -618,5 +624,21 @@ func (prom *Prometheus) Collect(metrics chan<- prometheus.Metric) {
}
}
}
for _, link := range prom.nodes.NodeLinks(node) {
if m, err := prometheus.NewConstMetric(
promDescLinkTQ,
prometheus.GaugeValue,
float64(link.TQ),
// labels:
link.SourceID,
link.TargetID,
link.SourceAddress,
link.TargetAddress,
link.SourceHostname,
link.TargetHostname,
); err == nil {
metrics <- m
}
}
}
}

0 comments on commit 76868ff

Please sign in to comment.