Skip to content

Commit b1f7005

Browse files
committed
chore: sync with latest procfs release
Needed-for: prometheus#3032 Signed-off-by: Pranshu Srivastava <[email protected]>
1 parent 4f7bd35 commit b1f7005

File tree

5 files changed

+130
-86
lines changed

5 files changed

+130
-86
lines changed

collector/fibrechannel_linux.go

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/go-kit/log"
2424
"github.com/go-kit/log/level"
2525
"github.com/prometheus/client_golang/prometheus"
26+
"github.com/prometheus/node_exporter/collector/utils"
2627
"github.com/prometheus/procfs/sysfs"
2728
)
2829

@@ -114,23 +115,36 @@ func (c *fibrechannelCollector) Update(ch chan<- prometheus.Metric) error {
114115
infoValue := 1.0
115116

116117
// First push the Host values
117-
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)
118+
ch <- prometheus.MustNewConstMetric(infoDesc, prometheus.GaugeValue, infoValue, utils.SafeDereference(
119+
host.Name,
120+
host.Speed,
121+
host.PortState,
122+
host.PortType,
123+
host.PortID,
124+
host.PortName,
125+
host.FabricName,
126+
host.SymbolicName,
127+
host.SupportedClasses,
128+
host.SupportedSpeeds,
129+
host.DevLossTMO,
130+
)...)
118131

119132
// Then the counters
120-
c.pushCounter(ch, "dumped_frames_total", host.Counters.DumpedFrames, host.Name)
121-
c.pushCounter(ch, "error_frames_total", host.Counters.ErrorFrames, host.Name)
122-
c.pushCounter(ch, "invalid_crc_total", host.Counters.InvalidCRCCount, host.Name)
123-
c.pushCounter(ch, "rx_frames_total", host.Counters.RXFrames, host.Name)
124-
c.pushCounter(ch, "rx_words_total", host.Counters.RXWords, host.Name)
125-
c.pushCounter(ch, "tx_frames_total", host.Counters.TXFrames, host.Name)
126-
c.pushCounter(ch, "tx_words_total", host.Counters.TXWords, host.Name)
127-
c.pushCounter(ch, "seconds_since_last_reset_total", host.Counters.SecondsSinceLastReset, host.Name)
128-
c.pushCounter(ch, "invalid_tx_words_total", host.Counters.InvalidTXWordCount, host.Name)
129-
c.pushCounter(ch, "link_failure_total", host.Counters.LinkFailureCount, host.Name)
130-
c.pushCounter(ch, "loss_of_sync_total", host.Counters.LossOfSyncCount, host.Name)
131-
c.pushCounter(ch, "loss_of_signal_total", host.Counters.LossOfSignalCount, host.Name)
132-
c.pushCounter(ch, "nos_total", host.Counters.NosCount, host.Name)
133-
c.pushCounter(ch, "fcp_packet_aborts_total", host.Counters.FCPPacketAborts, host.Name)
133+
// Note: `procfs` guarantees these a safe dereference for these counters.
134+
c.pushCounter(ch, "dumped_frames_total", *host.Counters.DumpedFrames, *host.Name)
135+
c.pushCounter(ch, "error_frames_total", *host.Counters.ErrorFrames, *host.Name)
136+
c.pushCounter(ch, "invalid_crc_total", *host.Counters.InvalidCRCCount, *host.Name)
137+
c.pushCounter(ch, "rx_frames_total", *host.Counters.RXFrames, *host.Name)
138+
c.pushCounter(ch, "rx_words_total", *host.Counters.RXWords, *host.Name)
139+
c.pushCounter(ch, "tx_frames_total", *host.Counters.TXFrames, *host.Name)
140+
c.pushCounter(ch, "tx_words_total", *host.Counters.TXWords, *host.Name)
141+
c.pushCounter(ch, "seconds_since_last_reset_total", *host.Counters.SecondsSinceLastReset, *host.Name)
142+
c.pushCounter(ch, "invalid_tx_words_total", *host.Counters.InvalidTXWordCount, *host.Name)
143+
c.pushCounter(ch, "link_failure_total", *host.Counters.LinkFailureCount, *host.Name)
144+
c.pushCounter(ch, "loss_of_sync_total", *host.Counters.LossOfSyncCount, *host.Name)
145+
c.pushCounter(ch, "loss_of_signal_total", *host.Counters.LossOfSignalCount, *host.Name)
146+
c.pushCounter(ch, "nos_total", *host.Counters.NosCount, *host.Name)
147+
c.pushCounter(ch, "fcp_packet_aborts_total", *host.Counters.FCPPacketAborts, *host.Name)
134148
}
135149

136150
return nil

collector/mountstats_linux.go

Lines changed: 71 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -538,15 +538,16 @@ func (c *mountStatsCollector) Update(ch chan<- prometheus.Metric) error {
538538
mountAddress = miStats.SuperOptions["addr"]
539539
}
540540

541-
deviceIdentifier := nfsDeviceIdentifier{m.Device, stats.Transport.Protocol, mountAddress}
542-
i := deviceList[deviceIdentifier]
543-
if i {
544-
level.Debug(c.logger).Log("msg", "Skipping duplicate device entry", "device", deviceIdentifier)
545-
continue
541+
for k := range stats.Transport {
542+
deviceIdentifier := nfsDeviceIdentifier{m.Device, stats.Transport[k].Protocol, mountAddress}
543+
i := deviceList[deviceIdentifier]
544+
if i {
545+
level.Debug(c.logger).Log("msg", "Skipping duplicate device entry", "device", deviceIdentifier)
546+
break
547+
}
548+
deviceList[deviceIdentifier] = true
549+
c.updateNFSStats(ch, stats, m.Device, stats.Transport[k].Protocol, mountAddress)
546550
}
547-
548-
deviceList[deviceIdentifier] = true
549-
c.updateNFSStats(ch, stats, m.Device, stats.Transport.Protocol, mountAddress)
550551
}
551552

552553
return nil
@@ -617,75 +618,77 @@ func (c *mountStatsCollector) updateNFSStats(ch chan<- prometheus.Metric, s *pro
617618
labelValues...,
618619
)
619620

620-
ch <- prometheus.MustNewConstMetric(
621-
c.NFSTransportBindTotal,
622-
prometheus.CounterValue,
623-
float64(s.Transport.Bind),
624-
labelValues...,
625-
)
621+
for i := range s.Transport {
622+
ch <- prometheus.MustNewConstMetric(
623+
c.NFSTransportBindTotal,
624+
prometheus.CounterValue,
625+
float64(s.Transport[i].Bind),
626+
labelValues...,
627+
)
626628

627-
ch <- prometheus.MustNewConstMetric(
628-
c.NFSTransportConnectTotal,
629-
prometheus.CounterValue,
630-
float64(s.Transport.Connect),
631-
labelValues...,
632-
)
629+
ch <- prometheus.MustNewConstMetric(
630+
c.NFSTransportConnectTotal,
631+
prometheus.CounterValue,
632+
float64(s.Transport[i].Connect),
633+
labelValues...,
634+
)
633635

634-
ch <- prometheus.MustNewConstMetric(
635-
c.NFSTransportIdleTimeSeconds,
636-
prometheus.GaugeValue,
637-
float64(s.Transport.IdleTimeSeconds%float64Mantissa),
638-
labelValues...,
639-
)
636+
ch <- prometheus.MustNewConstMetric(
637+
c.NFSTransportIdleTimeSeconds,
638+
prometheus.GaugeValue,
639+
float64(s.Transport[i].IdleTimeSeconds%float64Mantissa),
640+
labelValues...,
641+
)
640642

641-
ch <- prometheus.MustNewConstMetric(
642-
c.NFSTransportSendsTotal,
643-
prometheus.CounterValue,
644-
float64(s.Transport.Sends),
645-
labelValues...,
646-
)
643+
ch <- prometheus.MustNewConstMetric(
644+
c.NFSTransportSendsTotal,
645+
prometheus.CounterValue,
646+
float64(s.Transport[i].Sends),
647+
labelValues...,
648+
)
647649

648-
ch <- prometheus.MustNewConstMetric(
649-
c.NFSTransportReceivesTotal,
650-
prometheus.CounterValue,
651-
float64(s.Transport.Receives),
652-
labelValues...,
653-
)
650+
ch <- prometheus.MustNewConstMetric(
651+
c.NFSTransportReceivesTotal,
652+
prometheus.CounterValue,
653+
float64(s.Transport[i].Receives),
654+
labelValues...,
655+
)
654656

655-
ch <- prometheus.MustNewConstMetric(
656-
c.NFSTransportBadTransactionIDsTotal,
657-
prometheus.CounterValue,
658-
float64(s.Transport.BadTransactionIDs),
659-
labelValues...,
660-
)
657+
ch <- prometheus.MustNewConstMetric(
658+
c.NFSTransportBadTransactionIDsTotal,
659+
prometheus.CounterValue,
660+
float64(s.Transport[i].BadTransactionIDs),
661+
labelValues...,
662+
)
661663

662-
ch <- prometheus.MustNewConstMetric(
663-
c.NFSTransportBacklogQueueTotal,
664-
prometheus.CounterValue,
665-
float64(s.Transport.CumulativeBacklog),
666-
labelValues...,
667-
)
664+
ch <- prometheus.MustNewConstMetric(
665+
c.NFSTransportBacklogQueueTotal,
666+
prometheus.CounterValue,
667+
float64(s.Transport[i].CumulativeBacklog),
668+
labelValues...,
669+
)
668670

669-
ch <- prometheus.MustNewConstMetric(
670-
c.NFSTransportMaximumRPCSlots,
671-
prometheus.GaugeValue,
672-
float64(s.Transport.MaximumRPCSlotsUsed),
673-
labelValues...,
674-
)
671+
ch <- prometheus.MustNewConstMetric(
672+
c.NFSTransportMaximumRPCSlots,
673+
prometheus.GaugeValue,
674+
float64(s.Transport[i].MaximumRPCSlotsUsed),
675+
labelValues...,
676+
)
675677

676-
ch <- prometheus.MustNewConstMetric(
677-
c.NFSTransportSendingQueueTotal,
678-
prometheus.CounterValue,
679-
float64(s.Transport.CumulativeSendingQueue),
680-
labelValues...,
681-
)
678+
ch <- prometheus.MustNewConstMetric(
679+
c.NFSTransportSendingQueueTotal,
680+
prometheus.CounterValue,
681+
float64(s.Transport[i].CumulativeSendingQueue),
682+
labelValues...,
683+
)
682684

683-
ch <- prometheus.MustNewConstMetric(
684-
c.NFSTransportPendingQueueTotal,
685-
prometheus.CounterValue,
686-
float64(s.Transport.CumulativePendingQueue),
687-
labelValues...,
688-
)
685+
ch <- prometheus.MustNewConstMetric(
686+
c.NFSTransportPendingQueueTotal,
687+
prometheus.CounterValue,
688+
float64(s.Transport[i].CumulativePendingQueue),
689+
labelValues...,
690+
)
691+
}
689692

690693
for _, op := range s.Operations {
691694
opLabelValues := []string{export, protocol, mountAddress, op.Operation}

collector/utils/utils.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2024 The Prometheus Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package utils
15+
16+
func SafeDereference[T any](s ...*T) []T {
17+
var resolved []T
18+
for _, v := range s {
19+
if v != nil {
20+
resolved = append(resolved, *v)
21+
} else {
22+
var zeroValue T
23+
resolved = append(resolved, zeroValue)
24+
}
25+
}
26+
return resolved
27+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
github.com/prometheus/client_model v0.6.1
2727
github.com/prometheus/common v0.53.0
2828
github.com/prometheus/exporter-toolkit v0.11.0
29-
github.com/prometheus/procfs v0.14.0
29+
github.com/prometheus/procfs v0.15.1
3030
github.com/safchain/ethtool v0.3.0
3131
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f
3232
golang.org/x/sys v0.20.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ github.com/prometheus/common v0.53.0 h1:U2pL9w9nmJwJDa4qqLQ3ZaePJ6ZTwt7cMD3AG3+a
8282
github.com/prometheus/common v0.53.0/go.mod h1:BrxBKv3FWBIGXw89Mg1AeBq7FSyRzXWI3l3e7W3RN5U=
8383
github.com/prometheus/exporter-toolkit v0.11.0 h1:yNTsuZ0aNCNFQ3aFTD2uhPOvr4iD7fdBvKPAEGkNf+g=
8484
github.com/prometheus/exporter-toolkit v0.11.0/go.mod h1:BVnENhnNecpwoTLiABx7mrPB/OLRIgN74qlQbV+FK1Q=
85-
github.com/prometheus/procfs v0.14.0 h1:Lw4VdGGoKEZilJsayHf0B+9YgLGREba2C6xr+Fdfq6s=
86-
github.com/prometheus/procfs v0.14.0/go.mod h1:XL+Iwz8k8ZabyZfMFHPiilCniixqQarAy5Mu67pHlNQ=
85+
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
86+
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
8787
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
8888
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
8989
github.com/safchain/ethtool v0.3.0 h1:gimQJpsI6sc1yIqP/y8GYgiXn/NjgvpM0RNoWLVVmP0=

0 commit comments

Comments
 (0)