add flag to explicitly enable per-peer metrics

This commit is contained in:
Martin Weinelt 2018-05-23 15:11:04 +02:00
parent c08b4202c9
commit 39b21226c4
No known key found for this signature in database
GPG key ID: BD4AA0528F63F17E
3 changed files with 22 additions and 19 deletions

View file

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2017 Martin Weinelt Copyright (c) 2017-2018 Martin Weinelt
Copyright (c) 2017 Andreas Rammhold Copyright (c) 2017 Andreas Rammhold
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -16,7 +16,7 @@ $ go get github.com/freifunk-darmstadt/fastd-exporter
and and
``` ```
$ ./fastd-exporter --instance ffda $ ./fastd-exporter --instance ffda --metrics.perpeer
``` ```
The exporter will need read access to both the instances `fastd.conf` and `status socket`, keep that in mind. The exporter will need read access to both the instances `fastd.conf` and `status socket`, keep that in mind.

View file

@ -21,6 +21,7 @@ var (
address = flag.String("web.listen-address", ":9281", "Address on which to expose metrics and web interface.") address = flag.String("web.listen-address", ":9281", "Address on which to expose metrics and web interface.")
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.") metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
instances = flag.String("instances", "", "Fastd instances to report metrics on, comma separated.") instances = flag.String("instances", "", "Fastd instances to report metrics on, comma separated.")
peerMetrics = flag.Bool("metrics.perpeer", false, "Expose detailed metrics on each peer.")
) )
// These are the structs necessary for unmarshalling the data that is being received on fastds unix socket. // These are the structs necessary for unmarshalling the data that is being received on fastds unix socket.
@ -192,6 +193,7 @@ 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 {
for publicKey, peer := range data.Peers { for publicKey, peer := range data.Peers {
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)
@ -213,6 +215,7 @@ func (e PrometheusExporter) Collect(c chan<- prometheus.Metric) {
} }
} }
} }
}
func data_from_sock(sock string) (Message, error) { func data_from_sock(sock string) (Message, error) {
conn, err := net.DialTimeout("unix", sock, 2*time.Second) conn, err := net.DialTimeout("unix", sock, 2*time.Second)