count total number of connected peers
This commit is contained in:
parent
19cee0fc60
commit
542ea8ba86
|
@ -77,6 +77,8 @@ type PrometheusExporter struct {
|
||||||
txErrorPackets *prometheus.Desc
|
txErrorPackets *prometheus.Desc
|
||||||
txErrorBytes *prometheus.Desc
|
txErrorBytes *prometheus.Desc
|
||||||
|
|
||||||
|
peersUpTotal *prometheus.Desc
|
||||||
|
|
||||||
peerUp *prometheus.Desc
|
peerUp *prometheus.Desc
|
||||||
peerUptime *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),
|
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),
|
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
|
// per peer metrics
|
||||||
peerUp: prometheus.NewDesc(c("peer_up"), "whether the peer is connected", p, l),
|
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),
|
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.txDroppedPackets
|
||||||
c <- e.txDroppedBytes
|
c <- e.txDroppedBytes
|
||||||
|
|
||||||
|
c <- e.peersUpTotal
|
||||||
|
|
||||||
c <- e.peerUp
|
c <- e.peerUp
|
||||||
c <- e.peerUptime
|
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.txDroppedPackets, prometheus.CounterValue, float64(data.Statistics.TX.Count))
|
||||||
c <- prometheus.MustNewConstMetric(e.txDroppedBytes, prometheus.CounterValue, float64(data.Statistics.TX_Dropped.Bytes))
|
c <- prometheus.MustNewConstMetric(e.txDroppedBytes, prometheus.CounterValue, float64(data.Statistics.TX_Dropped.Bytes))
|
||||||
|
|
||||||
if *peerMetrics {
|
peersUpTotal := 0
|
||||||
for publicKey, peer := range data.Peers {
|
|
||||||
|
for publicKey, peer := range data.Peers {
|
||||||
|
if peer.Connection != nil {
|
||||||
|
peersUpTotal += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if *peerMetrics {
|
||||||
if peer.Connection == nil {
|
if peer.Connection == nil {
|
||||||
c <- prometheus.MustNewConstMetric(e.peerUp, prometheus.GaugeValue, float64(0), publicKey, peer.Name)
|
c <- prometheus.MustNewConstMetric(e.peerUp, prometheus.GaugeValue, float64(0), publicKey, peer.Name)
|
||||||
} else {
|
} 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) {
|
func data_from_sock(sock string) (Message, error) {
|
||||||
|
|
Loading…
Reference in a new issue