@@ -126,17 +126,26 @@ func (c *pcideviceCollector) Update(ch chan<- prometheus.Metric) error {
126126 ch <- c .infoDesc .mustNewConstMetric (1.0 , values ... )
127127
128128 // MaxLinkSpeed and CurrentLinkSpeed are represnted in GT/s
129- maxLinkSpeedTS := float64 (int64 (* device .MaxLinkSpeed * 1e9 ))
130- currentLinkSpeedTS := float64 (int64 (* device .CurrentLinkSpeed * 1e9 ))
131-
132- for i , val := range []float64 {
133- maxLinkSpeedTS ,
134- float64 (* device .MaxLinkWidth ),
135- currentLinkSpeedTS ,
136- float64 (* device .CurrentLinkWidth ),
137- } {
138- ch <- c .descs [i ].mustNewConstMetric (val , device .Location .Strings ()... )
129+ var maxLinkSpeedTS , currentLinkSpeedTS float64
130+ var maxLinkWidth , currentLinkWidth float64
131+
132+ if device .MaxLinkSpeed != nil {
133+ maxLinkSpeedTS = float64 (int64 (* device .MaxLinkSpeed * 1e9 ))
134+ }
135+ if device .CurrentLinkSpeed != nil {
136+ currentLinkSpeedTS = float64 (int64 (* device .CurrentLinkSpeed * 1e9 ))
137+ }
138+ if device .MaxLinkWidth != nil {
139+ maxLinkWidth = float64 (* device .MaxLinkWidth )
139140 }
141+ if device .CurrentLinkWidth != nil {
142+ currentLinkWidth = float64 (* device .CurrentLinkWidth )
143+ }
144+
145+ ch <- c .descs [0 ].mustNewConstMetric (maxLinkSpeedTS , device .Location .Strings ()... )
146+ ch <- c .descs [1 ].mustNewConstMetric (maxLinkWidth , device .Location .Strings ()... )
147+ ch <- c .descs [2 ].mustNewConstMetric (currentLinkSpeedTS , device .Location .Strings ()... )
148+ ch <- c .descs [3 ].mustNewConstMetric (currentLinkWidth , device .Location .Strings ()... )
140149 }
141150
142151 return nil
0 commit comments