9 fd_ = ::open(temp_path, O_RDONLY | O_NONBLOCK);
10 ::memset(buffer_, 0,
sizeof(buffer_));
23 spdlog::warn(
"CPU temperature observation disabled: file not found");
30 spdlog::warn(
"Read {} bytes from temperature file", size);
33 const double temperature = std::stol(buffer_) / 1000.;
34 check_temperature_warning(temperature);
35 auto& output = observation(
prefix());
39 void CpuTemperature::check_temperature_warning(
40 const double temperature) noexcept {
41 constexpr
double kConcerningTemperature = 75.0;
42 if (temperature > kConcerningTemperature) {
44 spdlog::warn(
"CPU temperature > {} °C, thermal throttling may occur",
45 kConcerningTemperature);
50 constexpr
double kHysteresisFactor = 0.95;
51 if (has_warned_ && temperature < kHysteresisFactor * kConcerningTemperature) {
std::string prefix() const noexcept final
Prefix of output in the observation dictionary.
CpuTemperature(const char *temp_path="/sys/class/thermal/thermal_zone0/temp")
Open file to query temperature from the kernel.
void write(Dictionary &observation) final
Write output to a dictionary.
~CpuTemperature() override
Close file.
constexpr unsigned kCpuTemperatureBufferSize
Characters required to read the temperature in [mC] from the kernel.