From 17c2deaee517aa6d2f8c39a4f3a36d87135bd370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=A0tibran=C3=BD?= Date: Mon, 10 Jun 2024 11:58:44 +0200 Subject: [PATCH] Update procfs to v0.15.1 and fix compilation errors. --- collector/fibrechannel_linux.go | 46 ++++++++++++++++++++------------- go.mod | 2 +- go.sum | 4 +-- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/collector/fibrechannel_linux.go b/collector/fibrechannel_linux.go index 13a3b5dc16..6c8f465321 100644 --- a/collector/fibrechannel_linux.go +++ b/collector/fibrechannel_linux.go @@ -87,10 +87,10 @@ func (c *fibrechannelCollector) pushMetric(ch chan<- prometheus.Metric, name str ch <- prometheus.MustNewConstMetric(c.metricDescs[name], valueType, float64(value), host) } -func (c *fibrechannelCollector) pushCounter(ch chan<- prometheus.Metric, name string, value uint64, host string) { +func (c *fibrechannelCollector) pushCounter(ch chan<- prometheus.Metric, name string, value *uint64, host string) { // Don't push counters that aren't implemented (a counter equal to maxUint64 is unimplemented by the HBA firmware) - if value != maxUint64 { - c.pushMetric(ch, name, value, host, prometheus.CounterValue) + if value != nil && *value != maxUint64 { + c.pushMetric(ch, name, *value, host, prometheus.CounterValue) } } @@ -114,24 +114,34 @@ func (c *fibrechannelCollector) Update(ch chan<- prometheus.Metric) error { infoValue := 1.0 // First push the Host values - ch <- prometheus.MustNewConstMetric(infoDesc, prometheus.GaugeValue, infoValue, host.Name, host.Speed, host.PortState, host.PortType, host.PortID, host.PortName, host.FabricName, host.SymbolicName, host.SupportedClasses, host.SupportedSpeeds, host.DevLossTMO) + ch <- prometheus.MustNewConstMetric(infoDesc, prometheus.GaugeValue, infoValue, + nilToEmpty(host.Name), nilToEmpty(host.Speed), nilToEmpty(host.PortState), nilToEmpty(host.PortType), + nilToEmpty(host.PortID), nilToEmpty(host.PortName), nilToEmpty(host.FabricName), nilToEmpty(host.SymbolicName), + nilToEmpty(host.SupportedClasses), nilToEmpty(host.SupportedSpeeds), nilToEmpty(host.DevLossTMO)) // Then the counters - c.pushCounter(ch, "dumped_frames_total", host.Counters.DumpedFrames, host.Name) - c.pushCounter(ch, "error_frames_total", host.Counters.ErrorFrames, host.Name) - c.pushCounter(ch, "invalid_crc_total", host.Counters.InvalidCRCCount, host.Name) - c.pushCounter(ch, "rx_frames_total", host.Counters.RXFrames, host.Name) - c.pushCounter(ch, "rx_words_total", host.Counters.RXWords, host.Name) - c.pushCounter(ch, "tx_frames_total", host.Counters.TXFrames, host.Name) - c.pushCounter(ch, "tx_words_total", host.Counters.TXWords, host.Name) - c.pushCounter(ch, "seconds_since_last_reset_total", host.Counters.SecondsSinceLastReset, host.Name) - c.pushCounter(ch, "invalid_tx_words_total", host.Counters.InvalidTXWordCount, host.Name) - c.pushCounter(ch, "link_failure_total", host.Counters.LinkFailureCount, host.Name) - c.pushCounter(ch, "loss_of_sync_total", host.Counters.LossOfSyncCount, host.Name) - c.pushCounter(ch, "loss_of_signal_total", host.Counters.LossOfSignalCount, host.Name) - c.pushCounter(ch, "nos_total", host.Counters.NosCount, host.Name) - c.pushCounter(ch, "fcp_packet_aborts_total", host.Counters.FCPPacketAborts, host.Name) + c.pushCounter(ch, "dumped_frames_total", host.Counters.DumpedFrames, nilToEmpty(host.Name)) + c.pushCounter(ch, "error_frames_total", host.Counters.ErrorFrames, nilToEmpty(host.Name)) + c.pushCounter(ch, "invalid_crc_total", host.Counters.InvalidCRCCount, nilToEmpty(host.Name)) + c.pushCounter(ch, "rx_frames_total", host.Counters.RXFrames, nilToEmpty(host.Name)) + c.pushCounter(ch, "rx_words_total", host.Counters.RXWords, nilToEmpty(host.Name)) + c.pushCounter(ch, "tx_frames_total", host.Counters.TXFrames, nilToEmpty(host.Name)) + c.pushCounter(ch, "tx_words_total", host.Counters.TXWords, nilToEmpty(host.Name)) + c.pushCounter(ch, "seconds_since_last_reset_total", host.Counters.SecondsSinceLastReset, nilToEmpty(host.Name)) + c.pushCounter(ch, "invalid_tx_words_total", host.Counters.InvalidTXWordCount, nilToEmpty(host.Name)) + c.pushCounter(ch, "link_failure_total", host.Counters.LinkFailureCount, nilToEmpty(host.Name)) + c.pushCounter(ch, "loss_of_sync_total", host.Counters.LossOfSyncCount, nilToEmpty(host.Name)) + c.pushCounter(ch, "loss_of_signal_total", host.Counters.LossOfSignalCount, nilToEmpty(host.Name)) + c.pushCounter(ch, "nos_total", host.Counters.NosCount, nilToEmpty(host.Name)) + c.pushCounter(ch, "fcp_packet_aborts_total", host.Counters.FCPPacketAborts, nilToEmpty(host.Name)) } return nil } + +func nilToEmpty(s *string) string { + if s == nil { + return "" + } + return *s +} diff --git a/go.mod b/go.mod index 0b9e8a0a38..55ca545e6c 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/prometheus/client_model v0.6.1 github.com/prometheus/common v0.53.0 github.com/prometheus/exporter-toolkit v0.11.0 - github.com/prometheus/procfs v0.14.0 + github.com/prometheus/procfs v0.15.1 github.com/safchain/ethtool v0.3.0 golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f golang.org/x/sys v0.20.0 diff --git a/go.sum b/go.sum index 652f6056e3..2c378be7dd 100644 --- a/go.sum +++ b/go.sum @@ -82,8 +82,8 @@ github.com/prometheus/common v0.53.0 h1:U2pL9w9nmJwJDa4qqLQ3ZaePJ6ZTwt7cMD3AG3+a github.com/prometheus/common v0.53.0/go.mod h1:BrxBKv3FWBIGXw89Mg1AeBq7FSyRzXWI3l3e7W3RN5U= github.com/prometheus/exporter-toolkit v0.11.0 h1:yNTsuZ0aNCNFQ3aFTD2uhPOvr4iD7fdBvKPAEGkNf+g= github.com/prometheus/exporter-toolkit v0.11.0/go.mod h1:BVnENhnNecpwoTLiABx7mrPB/OLRIgN74qlQbV+FK1Q= -github.com/prometheus/procfs v0.14.0 h1:Lw4VdGGoKEZilJsayHf0B+9YgLGREba2C6xr+Fdfq6s= -github.com/prometheus/procfs v0.14.0/go.mod h1:XL+Iwz8k8ZabyZfMFHPiilCniixqQarAy5Mu67pHlNQ= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/safchain/ethtool v0.3.0 h1:gimQJpsI6sc1yIqP/y8GYgiXn/NjgvpM0RNoWLVVmP0=