Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect CPU temperatures on FreeBSD #397

Merged
merged 2 commits into from
Jan 5, 2017
Merged

Collect CPU temperatures on FreeBSD #397

merged 2 commits into from
Jan 5, 2017

Conversation

dominikh
Copy link
Contributor

@dominikh dominikh commented Jan 1, 2017

No description provided.

Copy link
Member

@discordianfish discordianfish left a comment

Choose a reason for hiding this comment

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

Also needs rebasing on the ConstMetrics change

@grobie
Copy link
Member

grobie commented Jan 5, 2017

@dominikh ping

@dominikh
Copy link
Contributor Author

dominikh commented Jan 5, 2017

Pong. PTAL.

Copy link
Member

@grobie grobie left a comment

Choose a reason for hiding this comment

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

Added two comments. Ideally we should also have tests for these, but that'll require a better test suite first with OS specific tests.

temp, err := unix.SysctlUint32(fmt.Sprintf("dev.cpu.%d.temperature", cpu))
if err == nil {
ftemp := float64(temp-2732) / 10
c.temp.mustNewConstMetric(ftemp, lcpu)
Copy link
Member

Choose a reason for hiding this comment

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

The result needs to be sent to the channel.

ch <- c.cpu.mustNewConstMetric(float64(t.idle), lcpu, "idle")

temp, err := unix.SysctlUint32(fmt.Sprintf("dev.cpu.%d.temperature", cpu))
if err == nil {
Copy link
Member

Choose a reason for hiding this comment

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

In the error case, I think we should still set the metric, probably best to NaN and log the error at least at debug level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The most common error here will be that there's no temperature at all, either because the CPU isn't supported or because the correct driver (coretemp or k8temp) wasn't loaded. Should that still be logged at debug level?

Copy link
Member

@grobie grobie Jan 5, 2017

Choose a reason for hiding this comment

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

Personally I'd expect such information as debug output to understand why metrics are missing.

Ideally we could distinguish temporary errors from unsupported errors. Exporting NaN would make the first case a lot clearer, but not setting the metric at all makes probably more sense in the second case.

@dominikh
Copy link
Contributor Author

dominikh commented Jan 5, 2017

PTAL. We're logging errors now, setting NaN for unexpected errors, and actually sending the metric to ch.

Copy link
Member

@discordianfish discordianfish left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@grobie grobie left a comment

Choose a reason for hiding this comment

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

Thanks for the changes! LGTM once the right log package is used.

"strconv"
"unsafe"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/log"
Copy link
Member

Choose a reason for hiding this comment

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

prometheus/log is deprecated and has been moved to prometheus/common/log. Only the new package has been vendored in node_exporter.

Log why we couldn't collect the temperature, and set metric to NaN if
the CPU should support temperature collection but had an error.
@dominikh
Copy link
Contributor Author

dominikh commented Jan 5, 2017

Fixed and squashed, and given goimports a stern look.

@discordianfish
Copy link
Member

Nice, thanks!

@discordianfish discordianfish merged commit 3e266e2 into prometheus:master Jan 5, 2017
@SuperQ SuperQ mentioned this pull request Jan 15, 2017
tamcore pushed a commit to gitgrave/node_exporter that referenced this pull request Oct 22, 2024
Prometheus node exporter checks the returned error variable of
`NVMeClass` for being `os.ErrNotExist`. This check will never match,
because `NVMeClass` uses `fmt.Errorf` to convert the error.

So wrap the error result using `%w` to allow checking for
`os.ErrNotExist`.

Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants