diff --git a/fastd-exporter.go b/fastd-exporter.go index 8bf0147..d33d79b 100644 --- a/fastd-exporter.go +++ b/fastd-exporter.go @@ -77,6 +77,8 @@ type PrometheusExporter struct { txErrorPackets *prometheus.Desc txErrorBytes *prometheus.Desc + peersUpTotal *prometheus.Desc + peerUp *prometheus.Desc peerUptime *prometheus.Desc @@ -124,6 +126,8 @@ func NewPrometheusExporter(ifName string, sockName string) PrometheusExporter { txErrorPackets: prometheus.NewDesc(c("tx_error_packets"), "tx error packets count", nil, l), txErrorBytes: prometheus.NewDesc(c("tx_error_bytes"), "tx error bytes count", nil, l), + peersUpTotal: prometheus.NewDesc(c("peers_up_total"), "number of connected peers", nil, l), + // per peer metrics peerUp: prometheus.NewDesc(c("peer_up"), "whether the peer is connected", p, l), peerUptime: prometheus.NewDesc(c("peer_uptime_seconds"), "peer session uptime", p, l), @@ -156,6 +160,8 @@ func (e PrometheusExporter) Describe(c chan<- *prometheus.Desc) { c <- e.txDroppedPackets c <- e.txDroppedBytes + c <- e.peersUpTotal + c <- e.peerUp c <- e.peerUptime @@ -193,8 +199,14 @@ func (e PrometheusExporter) Collect(c chan<- prometheus.Metric) { c <- prometheus.MustNewConstMetric(e.txDroppedPackets, prometheus.CounterValue, float64(data.Statistics.TX.Count)) c <- prometheus.MustNewConstMetric(e.txDroppedBytes, prometheus.CounterValue, float64(data.Statistics.TX_Dropped.Bytes)) - if *peerMetrics { - for publicKey, peer := range data.Peers { + peersUpTotal := 0 + + for publicKey, peer := range data.Peers { + if peer.Connection != nil { + peersUpTotal += 1 + } + + if *peerMetrics { if peer.Connection == nil { c <- prometheus.MustNewConstMetric(e.peerUp, prometheus.GaugeValue, float64(0), publicKey, peer.Name) } else { @@ -215,6 +227,8 @@ func (e PrometheusExporter) Collect(c chan<- prometheus.Metric) { } } } + + c <- prometheus.MustNewConstMetric(e.peersUpTotal, prometheus.GaugeValue, float64(peersUpTotal)) } func data_from_sock(sock string) (Message, error) {