| 1 | package metricsscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/ |
| 2 | |
| 3 | import ( |
| 4 | "github.com/czerwonk/bird_exporter/clientscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/client`/" |
| 5 | "github.com/czerwonk/bird_exporter/protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/" |
| 6 | "github.com/prometheus/client_golang/prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/" |
| 7 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/ "github.com/sirupsen/logrusscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/" |
| 8 | ) |
| 9 | |
| 10 | var ( |
| 11 | bfdUpDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdUpDesc. *prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Desc# |
| 12 | bfdUptimeDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdUptimeDesc. *prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Desc# |
| 13 | bfdIntervalDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdIntervalDesc. *prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Desc# |
| 14 | bfdTimoutDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdTimoutDesc. *prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Desc# |
| 15 | ) |
| 16 | |
| 17 | func initscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/init().() { |
| 18 | l := []string{"name", "ip", "interface"} |
| 19 | prefix := "bird_bfd_session_" |
| 20 | bfdUpDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdUpDesc. = prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.NewDescscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/NewDesc().(prefix+"up", "Session is up", l, nil) |
| 21 | bfdUptimeDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdUptimeDesc. = prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.NewDescscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/NewDesc().(prefix+"uptime_seconds", "Session uptime in seconds", l, nil) |
| 22 | bfdIntervalDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdIntervalDesc. = prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.NewDescscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/NewDesc().(prefix+"interval_seconds", "Session uptime in seconds", l, nil) |
| 23 | bfdTimoutDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdTimoutDesc. = prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.NewDescscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/NewDesc().(prefix+"timeout_seconds", "Session timeout in seconds", l, nil) |
| 24 | } |
| 25 | |
| 26 | type bfdMetricExporterscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdMetricExporter# struct { |
| 27 | clientscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdMetricExporter#client. clientscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/client`/.Clientscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/client`/Client# |
| 28 | } |
| 29 | |
| 30 | // NewBFDExporter creates a new MetricExporter for BFD metrics |
| 31 | func NewBFDExporterscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/NewBFDExporter().(client clientscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/client`/.Clientscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/client`/Client#) MetricExporterscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/MetricExporter# { |
| 32 | return &bfdMetricExporterscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdMetricExporter#{clientscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdMetricExporter#client.: client} |
| 33 | } |
| 34 | |
| 35 | func (m *bfdMetricExporterscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdMetricExporter#) Describescip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdMetricExporter#Describe().(ch chan<- *prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Desc#) { |
| 36 | ch <- bfdUpDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdUpDesc. |
| 37 | ch <- bfdUptimeDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdUptimeDesc. |
| 38 | ch <- bfdIntervalDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdIntervalDesc. |
| 39 | ch <- bfdTimoutDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdTimoutDesc. |
| 40 | } |
| 41 | |
| 42 | func (m *bfdMetricExporterscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdMetricExporter#) Exportscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdMetricExporter#Export().(p *protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/.Protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#, ch chan<- prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Metricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#, newFormat bool) { |
| 43 | if p.Protoscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#Proto. != protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/.BFDscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/BFD. { |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | sessions, err := m.clientscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdMetricExporter#client..GetBFDSessionsscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/client`/Client#GetBFDSessions.(p) |
| 48 | if err != nil { |
| 49 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Errorlnscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Errorln().(err) |
| 50 | return |
| 51 | } |
| 52 | |
| 53 | for _, s := range sessions { |
| 54 | m.exportSessionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdMetricExporter#exportSession().(s, p.Namescip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#Name., ch) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func (m *bfdMetricExporterscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdMetricExporter#) exportSessionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdMetricExporter#exportSession().(s *protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/.BFDSessionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/BFDSession#, protocolName string, ch chan<- prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Metricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#) { |
| 59 | l := []string{protocolName, s.IPscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/BFDSession#IP., s.Interfacescip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/BFDSession#Interface.} |
| 60 | |
| 61 | var up float64 |
| 62 | var uptime float64 |
| 63 | |
| 64 | if s.Upscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/BFDSession#Up. { |
| 65 | up = 1 |
| 66 | uptime = float64(s.Sincescip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/BFDSession#Since.) |
| 67 | } |
| 68 | |
| 69 | ch <- prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.MustNewConstMetricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/MustNewConstMetric().(bfdUpDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdUpDesc., prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.GaugeValuescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/GaugeValue., up, l...) |
| 70 | ch <- prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.MustNewConstMetricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/MustNewConstMetric().(bfdUptimeDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdUptimeDesc., prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.GaugeValuescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/GaugeValue., uptime, l...) |
| 71 | ch <- prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.MustNewConstMetricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/MustNewConstMetric().(bfdIntervalDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdIntervalDesc., prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.GaugeValuescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/GaugeValue., s.Intervalscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/BFDSession#Interval., l...) |
| 72 | ch <- prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.MustNewConstMetricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/MustNewConstMetric().(bfdTimoutDescscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/bfdTimoutDesc., prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.GaugeValuescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/GaugeValue., s.Timeoutscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/BFDSession#Timeout., l...) |
| 73 | } |