Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions collector/pcidevice_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,26 @@ func (c *pcideviceCollector) Update(ch chan<- prometheus.Metric) error {
ch <- c.infoDesc.mustNewConstMetric(1.0, values...)

// MaxLinkSpeed and CurrentLinkSpeed are represnted in GT/s
maxLinkSpeedTS := float64(int64(*device.MaxLinkSpeed * 1e9))
currentLinkSpeedTS := float64(int64(*device.CurrentLinkSpeed * 1e9))

for i, val := range []float64{
maxLinkSpeedTS,
float64(*device.MaxLinkWidth),
currentLinkSpeedTS,
float64(*device.CurrentLinkWidth),
} {
ch <- c.descs[i].mustNewConstMetric(val, device.Location.Strings()...)
var maxLinkSpeedTS, currentLinkSpeedTS float64
var maxLinkWidth, currentLinkWidth float64

if device.MaxLinkSpeed != nil {
maxLinkSpeedTS = float64(int64(*device.MaxLinkSpeed * 1e9))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will emit a 0 for metrics we don't know the value for.

I think we should do something like this:

Suggested change
maxLinkSpeedTS = float64(int64(*device.MaxLinkSpeed * 1e9))
ch <- c.descs[0].mustNewConstMetric(maxLinkSpeedTS, device.Location.Strings()...)

}
if device.CurrentLinkSpeed != nil {
currentLinkSpeedTS = float64(int64(*device.CurrentLinkSpeed * 1e9))
}
if device.MaxLinkWidth != nil {
maxLinkWidth = float64(*device.MaxLinkWidth)
}
if device.CurrentLinkWidth != nil {
currentLinkWidth = float64(*device.CurrentLinkWidth)
}

ch <- c.descs[0].mustNewConstMetric(maxLinkSpeedTS, device.Location.Strings()...)
ch <- c.descs[1].mustNewConstMetric(maxLinkWidth, device.Location.Strings()...)
ch <- c.descs[2].mustNewConstMetric(currentLinkSpeedTS, device.Location.Strings()...)
ch <- c.descs[3].mustNewConstMetric(currentLinkWidth, device.Location.Strings()...)
}

return nil
Expand Down