Skip to content

Commit

Permalink
feat: add switch interface BGP established metric
Browse files Browse the repository at this point in the history
  • Loading branch information
mwennrich committed Nov 26, 2024
1 parent 61819e5 commit 5484c83
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ module github.com/metal-stack/metal-metrics-exporter
go 1.23

require (
github.com/metal-stack/metal-go v0.37.1
github.com/metal-stack/metal-go v0.39.5-0.20241125142836-85a6ff656afd
github.com/prometheus/client_golang v1.20.4
k8s.io/klog/v2 v2.130.1
)

require github.com/golang-jwt/jwt/v5 v5.2.1 // indirect

require (
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand All @@ -28,7 +30,6 @@ require (
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand All @@ -37,11 +38,11 @@ require (
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/httprc v1.0.6 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/jwx/v2 v2.1.1 // indirect
github.com/lestrrat-go/jwx/v2 v2.1.2 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/metal-stack/metal-lib v0.18.3
github.com/metal-stack/security v0.8.1 // indirect
github.com/metal-stack/metal-lib v0.19.0
github.com/metal-stack/security v0.9.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oklog/ulid v1.3.1 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ github.com/go-openapi/validate v0.24.0 h1:LdfDKwNbpB6Vn40xhTdNZAnfLECL81w+VX3Bum
github.com/go-openapi/validate v0.24.0/go.mod h1:iyeX1sEufmv3nPbBdX3ieNviWnOZaJ1+zquzJEf2BAQ=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
Expand All @@ -68,18 +68,18 @@ github.com/lestrrat-go/httprc v1.0.6 h1:qgmgIRhpvBqexMJjA/PmwSvhNk679oqD1RbovdCG
github.com/lestrrat-go/httprc v1.0.6/go.mod h1:mwwz3JMTPBjHUkkDv/IGJ39aALInZLrhBp0X7KGUZlo=
github.com/lestrrat-go/iter v1.0.2 h1:gMXo1q4c2pHmC3dn8LzRhJfP1ceCbgSiT9lUydIzltI=
github.com/lestrrat-go/iter v1.0.2/go.mod h1:Momfcq3AnRlRjI5b5O8/G5/BvpzrhoFTZcn06fEOPt4=
github.com/lestrrat-go/jwx/v2 v2.1.1 h1:Y2ltVl8J6izLYFs54BVcpXLv5msSW4o8eXwnzZLI32E=
github.com/lestrrat-go/jwx/v2 v2.1.1/go.mod h1:4LvZg7oxu6Q5VJwn7Mk/UwooNRnTHUpXBj2C4j3HNx0=
github.com/lestrrat-go/jwx/v2 v2.1.2 h1:6poete4MPsO8+LAEVhpdrNI4Xp2xdiafgl2RD89moBc=
github.com/lestrrat-go/jwx/v2 v2.1.2/go.mod h1:pO+Gz9whn7MPdbsqSJzG8TlEpMZCwQDXnFJ+zsUVh8Y=
github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU=
github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/metal-stack/metal-go v0.37.1 h1:vlvg/MY9Ep61h86GF54DER1VYADcqyHbFPZH3DqEbdM=
github.com/metal-stack/metal-go v0.37.1/go.mod h1:3MJTYCS4YJz8D8oteTKhjpaAKNMMjMKYDrIy9awHGtQ=
github.com/metal-stack/metal-lib v0.18.3 h1:bovFiJPB9SMvuGLqcXVWz6jFB8HrdzwnCX7TFlen4r0=
github.com/metal-stack/metal-lib v0.18.3/go.mod h1:Ctyi6zaXFr2NVrQZLFsDLnFCzupKnYErTtgRFKAsnbw=
github.com/metal-stack/security v0.8.1 h1:4zmVUxZvDWShVvVIxM3XhIv7pTmPe9DvACRIHW6YTsk=
github.com/metal-stack/security v0.8.1/go.mod h1:OO8ZilZO6fUV5QEmwc7HP/RAjqYrGQxXoYIddJ9TvqE=
github.com/metal-stack/metal-go v0.39.5-0.20241125142836-85a6ff656afd h1:qhYHfYwwNw3tkhw3pCdZgGZUmKOF35t2Y3yTDL1QtvQ=
github.com/metal-stack/metal-go v0.39.5-0.20241125142836-85a6ff656afd/go.mod h1:ltItf/Md/z588c7Dr3X6iemCeOFh3rJ8nDL5Dpb9zFQ=
github.com/metal-stack/metal-lib v0.19.0 h1:4yBnp/jPGgX9KeCje3A4MFL2oDjgjOjgsIK391LltRI=
github.com/metal-stack/metal-lib v0.19.0/go.mod h1:fCMaWwVGA/xAoGvBk72/nfzqBkHly0iOzrWpc55Fau4=
github.com/metal-stack/security v0.9.0 h1:FYBXJfNJwUw2E0HBa+jay37XF7b6EikEuf4Mw8u04EY=
github.com/metal-stack/security v0.9.0/go.mod h1:6pQhJ4Kdu4BKnjB4zyzfK9skiHymqfrqt63Y+UmZBKA=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
Expand Down
22 changes: 16 additions & 6 deletions metalCollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ type metalCollector struct {
capacityReservationsUsed *prometheus.Desc
usedImage *prometheus.Desc

switchInfo *prometheus.Desc
switchInterfaceInfo *prometheus.Desc
switchMetalCoreUp *prometheus.Desc
switchSyncFailed *prometheus.Desc
switchSyncDurationsMs *prometheus.Desc
switchInfo *prometheus.Desc
switchInterfaceInfo *prometheus.Desc
switchInterfaceBGPEstablished *prometheus.Desc
switchMetalCoreUp *prometheus.Desc
switchSyncFailed *prometheus.Desc
switchSyncDurationsMs *prometheus.Desc

machineAllocationInfo *prometheus.Desc
machineIssues *prometheus.Desc
Expand Down Expand Up @@ -154,7 +155,12 @@ func newMetalCollector(client metalgo.Client) *metalCollector {
),
switchInterfaceInfo: prometheus.NewDesc(
"metal_switch_interface_info",
"Provide information about the network",
"Provide information about the switch interfaces",
[]string{"switchname", "device", "machineid", "partition"}, nil,
),
switchInterfaceBGPEstablished: prometheus.NewDesc(
"metal_switch_interface_bgp_established",
"Provide information about the BGP state of the switch interfaces",
[]string{"switchname", "device", "machineid", "partition"}, nil,
),
switchMetalCoreUp: prometheus.NewDesc(
Expand Down Expand Up @@ -243,6 +249,7 @@ func (collector *metalCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- collector.usedImage
ch <- collector.switchInfo
ch <- collector.switchInterfaceInfo
ch <- collector.switchInterfaceBGPEstablished
ch <- collector.switchMetalCoreUp
ch <- collector.switchSyncFailed
ch <- collector.switchSyncDurationsMs
Expand Down Expand Up @@ -368,6 +375,9 @@ func (collector *metalCollector) Collect(ch chan<- prometheus.Metric) {

for _, c := range s.Connections {
ch <- prometheus.MustNewConstMetric(collector.switchInterfaceInfo, prometheus.GaugeValue, 1.0, s.Name, pointer.SafeDeref(pointer.SafeDeref(c.Nic).Name), c.MachineID, partitionID)
if c.Nic.BgpPortState != nil {
ch <- prometheus.MustNewConstMetric(collector.switchInterfaceBGPEstablished, prometheus.GaugeValue, float64(pointer.SafeDeref(c.Nic.BgpPortState.BgpTimerUpEstablished)), s.Name, pointer.SafeDeref(pointer.SafeDeref(c.Nic).Name), c.MachineID, partitionID)
}
}
}

Expand Down

0 comments on commit 5484c83

Please sign in to comment.