![]() |
RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
|
Reads Raspberry Pi system health (temperature, voltage, throttling, memory, storage, WiFi, and IP) by running vcgencmd and other OS commands, and reports threshold crossings to the AlertManager. More...
#include <SystemHealthComponent.h>
Public Member Functions | |
| SystemHealthComponent () | |
| Builds the system-health component, seeding its command map with every OS command it will run. More... | |
| virtual | ~SystemHealthComponent () |
| Destroys the component, turning it off first. More... | |
| virtual void | TurnOn () override |
| Turns the component on, reporting the call through the AlertManager. More... | |
| virtual void | TurnOff () override |
| Turns the component off, reporting the call through the AlertManager. More... | |
| virtual void | ProcessRawValues () override |
| Runs every health command, caches the results, parses the storage figures out of the df output, refreshes the memory info, and checks all thresholds for alerts. More... | |
| virtual void | CheckForAlerts () |
| Hands each health reading and its thresholds to the AlertManager (temperature, 5V low/high, root-fs writable, disk usage, memory available/swap, and WiFi signal), which decides and notifies only on a change. More... | |
| virtual std::string | ToString () const override |
| Serializes every cached health reading (temperature, voltage, throttling, memory, storage, WiFi, IP) to a string. More... | |
| float | GetSystemTemperatureInC () const |
| Parses the system temperature (in Celsius) from the cached vcgencmd measure_temp output. More... | |
| double | GetFiveVoltPowerVoltage () const |
| Parses the external 5V rail voltage from the cached vcgencmd pmic_read_adc output. More... | |
| std::string | GetThrottledCodeAndDescription () const |
| Gets the throttled-status code (from the cached vcgencmd output) with its human-readable description. More... | |
| std::string | GetFirmwareVersion () const |
| Gets the firmware version from the cached vcgencmd version output. More... | |
| std::string | GetLocalIP () const |
| Gets the local IP address from the cached hostname -I output. More... | |
| float | GetWiFiSignalStrength () const |
| Parses the WiFi signal strength (in dBm) from the cached iw dev wlan0 link output. More... | |
| bool | GetIsRootFileSystemWritable () const |
| Determines whether the root ("/") file system is mounted writable by scanning /proc/mounts for its options. More... | |
| std::string | GetSystemStorageDevicePath () const |
| Gets the root file system's device path (parsed from the df output). More... | |
| std::string | GetSystemStorageTotalSize () const |
| Gets the root file system's total size (parsed from the df output). More... | |
| std::string | GetSystemStorageUsed () const |
| Gets the root file system's used size (parsed from the df output). More... | |
| std::string | GetSystemStorageAvailable () const |
| Gets the root file system's available size (parsed from the df output). More... | |
| float | GetSystemStorageUsedPercent () const |
| Parses the root file system's used-percentage (from the df output) as a float. More... | |
| SystemMemoryInformation | GetSystemMemoryInformation () const |
| Reads /proc/meminfo and builds a SystemMemoryInformation from the MemTotal/MemFree/MemAvailable/SwapTotal/ SwapFree lines. More... | |
Public Member Functions inherited from RumPi::BaseComponent | |
| BaseComponent () | |
| Builds a base component with an unknown type and an empty name. More... | |
| virtual | ~BaseComponent () |
| Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass. More... | |
| virtual void | TurnOn ()=0 |
| Turns the component on (e.g. More... | |
| virtual void | TurnOff ()=0 |
| Turns the component off. More... | |
| virtual std::string | ToString () const =0 |
| Serializes the component's current readings to a string (usually JSON). More... | |
| virtual void | ProcessRawValues ()=0 |
| Reads and processes the component's latest raw values (called once per poll). More... | |
| virtual EComponentType | GetComponentType () const |
| Gets the component's type. More... | |
| const std::string & | GetName () const |
| Gets the component's unique per-instance name. More... | |
| void | SetName (const std::string &name) |
| Sets the component's unique per-instance name. More... | |
Protected Attributes | |
| SystemMemoryInformation | mySystemMemoryInfo |
| The most recently read system memory information. More... | |
| std::map< std::string, std::string > | myCommandData |
| Raw output of each health command, keyed by command. More... | |
| std::mutex | myCommandDataMutex |
| Guards myCommandData: ProcessRawValues (writer) vs the getters/ToString (readers). More... | |
Protected Attributes inherited from RumPi::BaseComponent | |
| EComponentType | myComponentType |
| The kind of component this is (set by each concrete subclass). More... | |
| std::string | myName |
| A unique per-instance name, assigned when the component is added to the manager. More... | |
Private Member Functions | |
| std::string | ExecuteCommand (const std::string &command) |
| Runs an OS command by tokenizing it, spawning the process with posix_spawnp with its stdout redirected to a pipe, reading the output, and returning it (or a descriptive error string on failure). More... | |
| std::string | GetThrottledCodeDescription (const std::string &code) const |
| Parses a vcgencmd throttled code and describes it, decoding each active/past error bit (under-voltage, ARM frequency capped, throttled, soft temperature limit). More... | |
| std::string | GetCommandOutput (const std::string &command) const |
| Thread-safe read of one command's cached output: copies the value out under the command-data lock so a caller never holds a reference into the map while ProcessRawValues replaces it. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from RumPi::BaseComponent | |
| static std::string | ComponentTypeToString (const EComponentType theComponentTypeToConvert) |
| Maps an EComponentType to its string name. More... | |
| static EComponentType | StringToComponentType (const std::string &theComponentTypeName) |
| Maps a type name back to its EComponentType (the inverse of ComponentTypeToString), so the client can turn the type carried on the wire back into a value it can look an icon up with. More... | |
Reads Raspberry Pi system health (temperature, voltage, throttling, memory, storage, WiFi, and IP) by running vcgencmd and other OS commands, and reports threshold crossings to the AlertManager.
| RumPi::SystemHealthComponent::SystemHealthComponent | ( | ) |
Builds the system-health component, seeding its command map with every OS command it will run.
|
virtual |
Destroys the component, turning it off first.
|
virtual |
Hands each health reading and its thresholds to the AlertManager (temperature, 5V low/high, root-fs writable, disk usage, memory available/swap, and WiFi signal), which decides and notifies only on a change.
|
private |
Runs an OS command by tokenizing it, spawning the process with posix_spawnp with its stdout redirected to a pipe, reading the output, and returning it (or a descriptive error string on failure).
| [in] | command | The command to run. |
|
private |
Thread-safe read of one command's cached output: copies the value out under the command-data lock so a caller never holds a reference into the map while ProcessRawValues replaces it.
| [in] | command | The command key to read. |
| std::string RumPi::SystemHealthComponent::GetFirmwareVersion | ( | ) | const |
Gets the firmware version from the cached vcgencmd version output.
| double RumPi::SystemHealthComponent::GetFiveVoltPowerVoltage | ( | ) | const |
Parses the external 5V rail voltage from the cached vcgencmd pmic_read_adc output.
| bool RumPi::SystemHealthComponent::GetIsRootFileSystemWritable | ( | ) | const |
Determines whether the root ("/") file system is mounted writable by scanning /proc/mounts for its options.
| std::string RumPi::SystemHealthComponent::GetLocalIP | ( | ) | const |
Gets the local IP address from the cached hostname -I output.
| SystemMemoryInformation RumPi::SystemHealthComponent::GetSystemMemoryInformation | ( | ) | const |
Reads /proc/meminfo and builds a SystemMemoryInformation from the MemTotal/MemFree/MemAvailable/SwapTotal/ SwapFree lines.
| std::string RumPi::SystemHealthComponent::GetSystemStorageAvailable | ( | ) | const |
Gets the root file system's available size (parsed from the df output).
| std::string RumPi::SystemHealthComponent::GetSystemStorageDevicePath | ( | ) | const |
Gets the root file system's device path (parsed from the df output).
| std::string RumPi::SystemHealthComponent::GetSystemStorageTotalSize | ( | ) | const |
Gets the root file system's total size (parsed from the df output).
| std::string RumPi::SystemHealthComponent::GetSystemStorageUsed | ( | ) | const |
Gets the root file system's used size (parsed from the df output).
| float RumPi::SystemHealthComponent::GetSystemStorageUsedPercent | ( | ) | const |
Parses the root file system's used-percentage (from the df output) as a float.
| float RumPi::SystemHealthComponent::GetSystemTemperatureInC | ( | ) | const |
Parses the system temperature (in Celsius) from the cached vcgencmd measure_temp output.
| std::string RumPi::SystemHealthComponent::GetThrottledCodeAndDescription | ( | ) | const |
Gets the throttled-status code (from the cached vcgencmd output) with its human-readable description.
|
private |
Parses a vcgencmd throttled code and describes it, decoding each active/past error bit (under-voltage, ARM frequency capped, throttled, soft temperature limit).
| [in] | code | The raw throttled-status string containing a "0x..." code. |
| float RumPi::SystemHealthComponent::GetWiFiSignalStrength | ( | ) | const |
Parses the WiFi signal strength (in dBm) from the cached iw dev wlan0 link output.
|
overridevirtual |
Runs every health command, caches the results, parses the storage figures out of the df output, refreshes the memory info, and checks all thresholds for alerts.
Implements RumPi::BaseComponent.
|
overridevirtual |
Serializes every cached health reading (temperature, voltage, throttling, memory, storage, WiFi, IP) to a string.
Implements RumPi::BaseComponent.
|
overridevirtual |
Turns the component off, reporting the call through the AlertManager.
Implements RumPi::BaseComponent.
|
overridevirtual |
Turns the component on, reporting the call through the AlertManager.
Implements RumPi::BaseComponent.
|
protected |
Raw output of each health command, keyed by command.
|
mutableprotected |
Guards myCommandData: ProcessRawValues (writer) vs the getters/ToString (readers).
|
protected |
The most recently read system memory information.