@@ -43,75 +43,108 @@ var (
4343
4444 pcideviceLabelNames = []string {"segment" , "bus" , "device" , "function" }
4545
46- pcideviceMaxLinkTSDesc = prometheus .NewDesc (
47- prometheus .BuildFQName (namespace , pcideviceSubsystem , "max_link_transfers_per_second" ),
48- "Value of maximum link's transfers per second (T/s)" ,
49- pcideviceLabelNames , nil ,
50- )
51- pcideviceMaxLinkWidthDesc = prometheus .NewDesc (
52- prometheus .BuildFQName (namespace , pcideviceSubsystem , "max_link_width" ),
53- "Value of maximum link's width (number of lanes)" ,
54- pcideviceLabelNames , nil ,
55- )
46+ pcideviceMaxLinkTSDesc = typedDesc {
47+ desc : prometheus .NewDesc (
48+ prometheus .BuildFQName (namespace , pcideviceSubsystem , "max_link_transfers_per_second" ),
49+ "Value of maximum link's transfers per second (T/s)" ,
50+ pcideviceLabelNames , nil ,
51+ ),
52+ valueType : prometheus .GaugeValue ,
53+ }
5654
57- pcideviceCurrentLinkTSDesc = prometheus .NewDesc (
58- prometheus .BuildFQName (namespace , pcideviceSubsystem , "current_link_transfers_per_second" ),
59- "Value of current link's transfers per second (T/s)" ,
60- pcideviceLabelNames , nil ,
61- )
62- pcideviceCurrentLinkWidthDesc = prometheus .NewDesc (
63- prometheus .BuildFQName (namespace , pcideviceSubsystem , "current_link_width" ),
64- "Value of current link's width (number of lanes)" ,
65- pcideviceLabelNames , nil ,
66- )
55+ pcideviceMaxLinkWidthDesc = typedDesc {
56+ desc : prometheus .NewDesc (
57+ prometheus .BuildFQName (namespace , pcideviceSubsystem , "max_link_width" ),
58+ "Value of maximum link's width (number of lanes)" ,
59+ pcideviceLabelNames , nil ,
60+ ),
61+ valueType : prometheus .GaugeValue ,
62+ }
6763
68- pcidevicePowerStateDesc = prometheus .NewDesc (
69- prometheus .BuildFQName (namespace , pcideviceSubsystem , "power_state" ),
70- "PCIe device power state, one of: D0, D1, D2, D3hot, D3cold, unknown or error." ,
71- append (pcideviceLabelNames , "state" ), nil ,
72- )
64+ pcideviceCurrentLinkTSDesc = typedDesc {
65+ desc : prometheus .NewDesc (
66+ prometheus .BuildFQName (namespace , pcideviceSubsystem , "current_link_transfers_per_second" ),
67+ "Value of current link's transfers per second (T/s)" ,
68+ pcideviceLabelNames , nil ,
69+ ),
70+ valueType : prometheus .GaugeValue ,
71+ }
72+ pcideviceCurrentLinkWidthDesc = typedDesc {
73+ desc : prometheus .NewDesc (
74+ prometheus .BuildFQName (namespace , pcideviceSubsystem , "current_link_width" ),
75+ "Value of current link's width (number of lanes)" ,
76+ pcideviceLabelNames , nil ,
77+ ),
78+ valueType : prometheus .GaugeValue ,
79+ }
7380
74- pcideviceD3coldAllowedDesc = prometheus .NewDesc (
75- prometheus .BuildFQName (namespace , pcideviceSubsystem , "d3cold_allowed" ),
76- "Whether the PCIe device supports D3cold power state (0/1)." ,
77- pcideviceLabelNames , nil ,
78- )
81+ pcidevicePowerStateDesc = typedDesc {
82+ desc : prometheus .NewDesc (
83+ prometheus .BuildFQName (namespace , pcideviceSubsystem , "power_state" ),
84+ "PCIe device power state, one of: D0, D1, D2, D3hot, D3cold, unknown or error." ,
85+ append (pcideviceLabelNames , "state" ), nil ,
86+ ),
87+ valueType : prometheus .GaugeValue ,
88+ }
7989
80- pcideviceSriovDriversAutoprobeDesc = prometheus .NewDesc (
81- prometheus .BuildFQName (namespace , pcideviceSubsystem , "sriov_drivers_autoprobe" ),
82- "Whether SR-IOV drivers autoprobe is enabled for the device (0/1)." ,
83- pcideviceLabelNames , nil ,
84- )
90+ pcideviceD3coldAllowedDesc = typedDesc {
91+ desc : prometheus .NewDesc (
92+ prometheus .BuildFQName (namespace , pcideviceSubsystem , "d3cold_allowed" ),
93+ "Whether the PCIe device supports D3cold power state (0/1)." ,
94+ pcideviceLabelNames , nil ,
95+ ),
96+ valueType : prometheus .GaugeValue ,
97+ }
8598
86- pcideviceSriovNumvfsDesc = prometheus .NewDesc (
87- prometheus .BuildFQName (namespace , pcideviceSubsystem , "sriov_numvfs" ),
88- "Number of Virtual Functions (VFs) currently enabled for SR-IOV." ,
89- pcideviceLabelNames , nil ,
90- )
99+ pcideviceSriovDriversAutoprobeDesc = typedDesc {
100+ desc : prometheus .NewDesc (
101+ prometheus .BuildFQName (namespace , pcideviceSubsystem , "sriov_drivers_autoprobe" ),
102+ "Whether SR-IOV drivers autoprobe is enabled for the device (0/1)." ,
103+ pcideviceLabelNames , nil ,
104+ ),
105+ valueType : prometheus .GaugeValue ,
106+ }
91107
92- pcideviceSriovTotalvfsDesc = prometheus .NewDesc (
93- prometheus .BuildFQName (namespace , pcideviceSubsystem , "sriov_totalvfs" ),
94- "Total number of Virtual Functions (VFs) supported by the device." ,
95- pcideviceLabelNames , nil ,
96- )
108+ pcideviceSriovNumvfsDesc = typedDesc {
109+ desc : prometheus .NewDesc (
110+ prometheus .BuildFQName (namespace , pcideviceSubsystem , "sriov_numvfs" ),
111+ "Number of Virtual Functions (VFs) currently enabled for SR-IOV." ,
112+ pcideviceLabelNames , nil ,
113+ ),
114+ valueType : prometheus .GaugeValue ,
115+ }
97116
98- pcideviceSriovVfTotalMsixDesc = prometheus .NewDesc (
99- prometheus .BuildFQName (namespace , pcideviceSubsystem , "sriov_vf_total_msix" ),
100- "Total number of MSI-X vectors for Virtual Functions." ,
101- pcideviceLabelNames , nil ,
102- )
117+ pcideviceSriovTotalvfsDesc = typedDesc {
118+ desc : prometheus .NewDesc (
119+ prometheus .BuildFQName (namespace , pcideviceSubsystem , "sriov_totalvfs" ),
120+ "Total number of Virtual Functions (VFs) supported by the device." ,
121+ pcideviceLabelNames , nil ,
122+ ),
123+ valueType : prometheus .GaugeValue ,
124+ }
103125
104- pcideviceNumaNodeDesc = prometheus .NewDesc (
105- prometheus .BuildFQName (namespace , pcideviceSubsystem , "numa_node" ),
106- "NUMA node number for the PCI device. -1 indicates unknown or not available." ,
107- pcideviceLabelNames , nil ,
108- )
126+ pcideviceSriovVfTotalMsixDesc = typedDesc {
127+ desc : prometheus .NewDesc (
128+ prometheus .BuildFQName (namespace , pcideviceSubsystem , "sriov_vf_total_msix" ),
129+ "Total number of MSI-X vectors for Virtual Functions." ,
130+ pcideviceLabelNames , nil ,
131+ ),
132+ valueType : prometheus .GaugeValue ,
133+ }
134+
135+ pcideviceNumaNodeDesc = typedDesc {
136+ desc : prometheus .NewDesc (
137+ prometheus .BuildFQName (namespace , pcideviceSubsystem , "numa_node" ),
138+ "NUMA node number for the PCI device. -1 indicates unknown or not available." ,
139+ pcideviceLabelNames , nil ,
140+ ),
141+ valueType : prometheus .GaugeValue ,
142+ }
109143)
110144
111145type pcideviceCollector struct {
112146 fs sysfs.FS
113147 infoDesc typedDesc
114- descs []typedFactorDesc
115148 logger * slog.Logger
116149 pciVendors map [string ]string
117150 pciDevices map [string ]map [string ]string
@@ -161,20 +194,6 @@ func NewPcideviceCollector(logger *slog.Logger) (Collector, error) {
161194 valueType : prometheus .GaugeValue ,
162195 }
163196
164- c .descs = []typedFactorDesc {
165- {desc : pcideviceMaxLinkTSDesc , valueType : prometheus .GaugeValue },
166- {desc : pcideviceMaxLinkWidthDesc , valueType : prometheus .GaugeValue },
167- {desc : pcideviceCurrentLinkTSDesc , valueType : prometheus .GaugeValue },
168- {desc : pcideviceCurrentLinkWidthDesc , valueType : prometheus .GaugeValue },
169- {desc : pcidevicePowerStateDesc , valueType : prometheus .GaugeValue },
170- {desc : pcideviceD3coldAllowedDesc , valueType : prometheus .GaugeValue },
171- {desc : pcideviceSriovDriversAutoprobeDesc , valueType : prometheus .GaugeValue },
172- {desc : pcideviceSriovNumvfsDesc , valueType : prometheus .GaugeValue },
173- {desc : pcideviceSriovTotalvfsDesc , valueType : prometheus .GaugeValue },
174- {desc : pcideviceSriovVfTotalMsixDesc , valueType : prometheus .GaugeValue },
175- {desc : pcideviceNumaNodeDesc , valueType : prometheus .GaugeValue },
176- }
177-
178197 return c , nil
179198}
180199
@@ -300,23 +319,15 @@ func (c *pcideviceCollector) Update(ch chan<- prometheus.Metric) error {
300319 }
301320
302321 // Emit metrics for all fields except numa_node and power_state
303- metrics := []float64 {
304- maxLinkSpeedTS ,
305- maxLinkWidth ,
306- currentLinkSpeedTS ,
307- currentLinkWidth ,
308- d3coldAllowed ,
309- sriovDriversAutoprobe ,
310- sriovNumvfs ,
311- sriovTotalvfs ,
312- sriovVfTotalMsix ,
313- }
314-
315- // Emit regular metrics (excluding power_state which is at index 4)
316- metricIndices := []int {0 , 1 , 2 , 3 , 5 , 6 , 7 , 8 , 9 } // Skip power_state (4) and numa_node (10)
317- for i , val := range metrics {
318- ch <- c.descs [metricIndices [i ]].mustNewConstMetric (val , device .Location .Strings ()... )
319- }
322+ ch <- pcideviceMaxLinkTSDesc .mustNewConstMetric (maxLinkSpeedTS , device .Location .Strings ()... )
323+ ch <- pcideviceMaxLinkWidthDesc .mustNewConstMetric (maxLinkWidth , device .Location .Strings ()... )
324+ ch <- pcideviceCurrentLinkTSDesc .mustNewConstMetric (currentLinkSpeedTS , device .Location .Strings ()... )
325+ ch <- pcideviceCurrentLinkWidthDesc .mustNewConstMetric (currentLinkWidth , device .Location .Strings ()... )
326+ ch <- pcideviceD3coldAllowedDesc .mustNewConstMetric (d3coldAllowed , device .Location .Strings ()... )
327+ ch <- pcideviceSriovDriversAutoprobeDesc .mustNewConstMetric (sriovDriversAutoprobe , device .Location .Strings ()... )
328+ ch <- pcideviceSriovNumvfsDesc .mustNewConstMetric (sriovNumvfs , device .Location .Strings ()... )
329+ ch <- pcideviceSriovTotalvfsDesc .mustNewConstMetric (sriovTotalvfs , device .Location .Strings ()... )
330+ ch <- pcideviceSriovVfTotalMsixDesc .mustNewConstMetric (sriovVfTotalMsix , device .Location .Strings ()... )
320331
321332 // Emit power state metrics with state labels only if power state is available
322333 if hasPowerState {
@@ -330,13 +341,13 @@ func (c *pcideviceCollector) Update(ch chan<- prometheus.Metric) error {
330341 value = 0
331342 }
332343 stateLabels := append (deviceLabels , state )
333- ch <- c . descs [ 4 ] .mustNewConstMetric (value , stateLabels ... )
344+ ch <- pcidevicePowerStateDesc .mustNewConstMetric (value , stateLabels ... )
334345 }
335346 }
336347
337348 // Only emit numa_node metric if the value is available (not -1)
338349 if numaNode != - 1 {
339- ch <- c . descs [ 10 ] .mustNewConstMetric (numaNode , device .Location .Strings ()... )
350+ ch <- pcideviceNumaNodeDesc .mustNewConstMetric (numaNode , device .Location .Strings ()... )
340351 }
341352 }
342353
0 commit comments