diff --git a/collector/cpu_freebsd.go b/collector/cpu_freebsd.go index e8d2fb98..dc3d6a11 100644 --- a/collector/cpu_freebsd.go +++ b/collector/cpu_freebsd.go @@ -138,7 +138,23 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error { } continue } - ch <- c.temp.mustNewConstMetric(float64(temp-2732)/10, lcpu) + + // Temp is a signed integer in deci-degrees Kelvin. + // Cast uint32 to int32 and convert to float64 degrees Celsius. + // + // 2732 is used as the conversion constant for deci-degrees + // Kelvin, in multiple places in the kernel that feed into this + // sysctl, so we want to maintain consistency: + // + // sys/dev/amdtemp/amdtemp.c + // #define AMDTEMP_ZERO_C_TO_K 2732 + // + // sys/dev/acpica/acpi_thermal.c + // #define TZ_ZEROC 2732 + // + // sys/dev/coretemp/coretemp.c + // #define TZ_ZEROC 2732 + ch <- c.temp.mustNewConstMetric(float64(int32(temp)-2732)/10, lcpu) } return err }