vulp  2.2.2
CpuTemperature.h
Go to the documentation of this file.
1 // Copyright 2022 Stéphane Caron
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include <string>
7 
9 
11 
13 constexpr unsigned kCpuTemperatureBufferSize = 12;
14 
19 class CpuTemperature : public Source {
20  public:
27  const char* temp_path = "/sys/class/thermal/thermal_zone0/temp");
28 
30  ~CpuTemperature() override;
31 
33  inline std::string prefix() const noexcept final { return "cpu_temperature"; }
34 
39  void write(Dictionary& observation) final;
40 
42  bool is_disabled() const { return is_disabled_; }
43 
44  private:
51  void check_temperature_warning(const double temperature) noexcept;
52 
53  private:
55  bool is_disabled_ = false;
56 
58  int fd_;
59 
61  char buffer_[kCpuTemperatureBufferSize];
62 
64  bool has_warned_;
65 };
66 
67 } // namespace vulp::observation::sources
Base class for sources.
Definition: Source.h:20
Source for CPU temperature readings.
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.
bool is_disabled() const
Check if temperature observations are disabled.
constexpr unsigned kCpuTemperatureBufferSize
Characters required to read the temperature in [mC] from the kernel.