RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RumPi::SystemHealthComponent Class Reference

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>

Inheritance diagram for RumPi::SystemHealthComponent:
[legend]
Collaboration diagram for RumPi::SystemHealthComponent:
[legend]

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...
 

Detailed Description

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.

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ SystemHealthComponent()

RumPi::SystemHealthComponent::SystemHealthComponent ( )

Builds the system-health component, seeding its command map with every OS command it will run.

Author
Eddie O'Hagan
Date
8/13/2026
SystemHealthComponent systemHealth;
SystemHealthComponent()
Builds the system-health component, seeding its command map with every OS command it will run.
Definition: SystemHealthComponent.cpp:21

◆ ~SystemHealthComponent()

RumPi::SystemHealthComponent::~SystemHealthComponent ( )
virtual

Destroys the component, turning it off first.

Author
Eddie O'Hagan
Date
8/13/2026
delete systemHealth;

Member Function Documentation

◆ CheckForAlerts()

void RumPi::SystemHealthComponent::CheckForAlerts ( )
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.

Author
Eddie O'Hagan
Date
8/13/2026
systemHealth.CheckForAlerts();

◆ ExecuteCommand()

std::string RumPi::SystemHealthComponent::ExecuteCommand ( const std::string &  command)
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).

Author
Eddie O'Hagan
Date
8/13/2026
std::string temperature = ExecuteCommand("vcgencmd measure_temp");
std::string ExecuteCommand(const std::string &command)
Runs an OS command by tokenizing it, spawning the process with posix_spawnp with its stdout redirecte...
Definition: SystemHealthComponent.cpp:73
Parameters
[in]commandThe command to run.
Returns
The command's trimmed output, or a descriptive error string on failure.

◆ GetCommandOutput()

std::string RumPi::SystemHealthComponent::GetCommandOutput ( const std::string &  command) const
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.

Author
Eddie O'Hagan
Date
8/13/2026
std::string ip = GetCommandOutput("hostname -I");
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 ...
Definition: SystemHealthComponent.cpp:403
Parameters
[in]commandThe command key to read.
Returns
A copy of the command's output, or an empty string if it has not been run yet.

◆ GetFirmwareVersion()

std::string RumPi::SystemHealthComponent::GetFirmwareVersion ( ) const

Gets the firmware version from the cached vcgencmd version output.

Author
Eddie O'Hagan
Date
8/13/2026
std::string version = systemHealth.GetFirmwareVersion();
Returns
The firmware version string.

◆ GetFiveVoltPowerVoltage()

double RumPi::SystemHealthComponent::GetFiveVoltPowerVoltage ( ) const

Parses the external 5V rail voltage from the cached vcgencmd pmic_read_adc output.

Author
Eddie O'Hagan
Date
8/13/2026
double voltage = systemHealth.GetFiveVoltPowerVoltage();
Returns
The 5V rail voltage, or -1 on failure.

◆ GetIsRootFileSystemWritable()

bool RumPi::SystemHealthComponent::GetIsRootFileSystemWritable ( ) const

Determines whether the root ("/") file system is mounted writable by scanning /proc/mounts for its options.

Author
Eddie O'Hagan
Date
8/13/2026
bool writable = systemHealth.GetIsRootFileSystemWritable();
Returns
True if the root file system is writable, false if read-only or the mount point was not found.

◆ GetLocalIP()

std::string RumPi::SystemHealthComponent::GetLocalIP ( ) const

Gets the local IP address from the cached hostname -I output.

Author
Eddie O'Hagan
Date
8/13/2026
std::string ip = systemHealth.GetLocalIP();
Returns
The local IP address string.

◆ GetSystemMemoryInformation()

SystemMemoryInformation RumPi::SystemHealthComponent::GetSystemMemoryInformation ( ) const

Reads /proc/meminfo and builds a SystemMemoryInformation from the MemTotal/MemFree/MemAvailable/SwapTotal/ SwapFree lines.

Author
Eddie O'Hagan
Date
8/13/2026
SystemMemoryInformation memory = systemHealth.GetSystemMemoryInformation();
Returns
The current system memory information.

◆ GetSystemStorageAvailable()

std::string RumPi::SystemHealthComponent::GetSystemStorageAvailable ( ) const

Gets the root file system's available size (parsed from the df output).

Author
Eddie O'Hagan
Date
8/13/2026
std::string available = systemHealth.GetSystemStorageAvailable();
Returns
The available storage size.

◆ GetSystemStorageDevicePath()

std::string RumPi::SystemHealthComponent::GetSystemStorageDevicePath ( ) const

Gets the root file system's device path (parsed from the df output).

Author
Eddie O'Hagan
Date
8/13/2026
std::string device = systemHealth.GetSystemStorageDevicePath();
Returns
The storage device path.

◆ GetSystemStorageTotalSize()

std::string RumPi::SystemHealthComponent::GetSystemStorageTotalSize ( ) const

Gets the root file system's total size (parsed from the df output).

Author
Eddie O'Hagan
Date
8/13/2026
std::string total = systemHealth.GetSystemStorageTotalSize();
Returns
The total storage size.

◆ GetSystemStorageUsed()

std::string RumPi::SystemHealthComponent::GetSystemStorageUsed ( ) const

Gets the root file system's used size (parsed from the df output).

Author
Eddie O'Hagan
Date
8/13/2026
std::string used = systemHealth.GetSystemStorageUsed();
Returns
The used storage size.

◆ GetSystemStorageUsedPercent()

float RumPi::SystemHealthComponent::GetSystemStorageUsedPercent ( ) const

Parses the root file system's used-percentage (from the df output) as a float.

Author
Eddie O'Hagan
Date
8/13/2026
float usedPercent = systemHealth.GetSystemStorageUsedPercent();
Returns
The used storage percent, or -1 on failure.

◆ GetSystemTemperatureInC()

float RumPi::SystemHealthComponent::GetSystemTemperatureInC ( ) const

Parses the system temperature (in Celsius) from the cached vcgencmd measure_temp output.

Author
Eddie O'Hagan
Date
8/13/2026
float temperature = systemHealth.GetSystemTemperatureInC();
Returns
The system temperature in Celsius, or -1 on failure.

◆ GetThrottledCodeAndDescription()

std::string RumPi::SystemHealthComponent::GetThrottledCodeAndDescription ( ) const

Gets the throttled-status code (from the cached vcgencmd output) with its human-readable description.

Author
Eddie O'Hagan
Date
8/13/2026
std::string status = systemHealth.GetThrottledCodeAndDescription();
Returns
The throttled code and its description.

◆ GetThrottledCodeDescription()

std::string RumPi::SystemHealthComponent::GetThrottledCodeDescription ( const std::string &  code) const
private

Parses a vcgencmd throttled code and describes it, decoding each active/past error bit (under-voltage, ARM frequency capped, throttled, soft temperature limit).

Author
Eddie O'Hagan
Date
8/13/2026
std::string description = GetThrottledCodeDescription("throttled=0x50005");
std::string GetThrottledCodeDescription(const std::string &code) const
Parses a vcgencmd throttled code and describes it, decoding each active/past error bit (under-voltage...
Definition: SystemHealthComponent.cpp:450
Parameters
[in]codeThe raw throttled-status string containing a "0x..." code.
Returns
A description of the active and past errors, or an error string if the code could not be parsed.

◆ GetWiFiSignalStrength()

float RumPi::SystemHealthComponent::GetWiFiSignalStrength ( ) const

Parses the WiFi signal strength (in dBm) from the cached iw dev wlan0 link output.

Author
Eddie O'Hagan
Date
8/13/2026
float signal = systemHealth.GetWiFiSignalStrength();
Returns
The WiFi signal strength in dBm, or -1 on failure.

◆ ProcessRawValues()

void RumPi::SystemHealthComponent::ProcessRawValues ( )
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.

Author
Eddie O'Hagan
Date
8/13/2026
systemHealth.ProcessRawValues();

Implements RumPi::BaseComponent.

◆ ToString()

std::string RumPi::SystemHealthComponent::ToString ( ) const
overridevirtual

Serializes every cached health reading (temperature, voltage, throttling, memory, storage, WiFi, IP) to a string.

Author
Eddie O'Hagan
Date
8/13/2026
std::string data = systemHealth.ToString();
Returns
A multi-line string describing the system's health.

Implements RumPi::BaseComponent.

◆ TurnOff()

void RumPi::SystemHealthComponent::TurnOff ( )
overridevirtual

Turns the component off, reporting the call through the AlertManager.

Author
Eddie O'Hagan
Date
8/13/2026
systemHealth.TurnOff();

Implements RumPi::BaseComponent.

◆ TurnOn()

void RumPi::SystemHealthComponent::TurnOn ( )
overridevirtual

Turns the component on, reporting the call through the AlertManager.

Author
Eddie O'Hagan
Date
8/13/2026
systemHealth.TurnOn();

Implements RumPi::BaseComponent.

Member Data Documentation

◆ myCommandData

std::map<std::string, std::string> RumPi::SystemHealthComponent::myCommandData
protected

Raw output of each health command, keyed by command.

◆ myCommandDataMutex

std::mutex RumPi::SystemHealthComponent::myCommandDataMutex
mutableprotected

Guards myCommandData: ProcessRawValues (writer) vs the getters/ToString (readers).

◆ mySystemMemoryInfo

SystemMemoryInformation RumPi::SystemHealthComponent::mySystemMemoryInfo
protected

The most recently read system memory information.


The documentation for this class was generated from the following files: