count total number of connected peers

This commit is contained in:
ohrensessel 2018-05-23 22:47:45 +02:00 committed by Martin Weinelt
parent 19cee0fc60
commit 542ea8ba86

View file

@ -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) {