20#include "../../libMagAOX/libMagAOX.hpp"
21#include "../../magaox_git_version.h"
130 const std::string& line
140 const std::string& line
150 const std::string& line
207 const std::string& line
371 config.add(
"sysType",
"",
"sysType", argType::Required,
"",
"sysType",
false,
"string",
"The system type, Intel (default) or AMD");
372 config.add(
"diskNames",
"",
"diskNames", argType::Required,
"",
"diskNames",
false,
"vector<string>",
"The names (/dev/sdX) of the drives to monitor");
373 config.add(
"warningCoreTemp",
"",
"warningCoreTemp", argType::Required,
"",
"warningCoreTemp",
false,
"int",
"The warning temperature for CPU cores.");
374 config.add(
"criticalCoreTemp",
"",
"criticalCoreTemp", argType::Required,
"",
"criticalCoreTemp",
false,
"int",
"The critical temperature for CPU cores.");
375 config.add(
"warningDiskTemp",
"",
"warningDiskTemp", argType::Required,
"",
"warningDiskTemp",
false,
"int",
"The warning temperature for the disk.");
376 config.add(
"criticalDiskTemp",
"",
"criticalDiskTemp", argType::Required,
"",
"criticalDiskTemp",
false,
"int",
"The critical temperature for disk.");
393 config(
st,
"sysType");
398 else if (
st ==
"AMD")
629 const std::string& line
650 const std::string& line
653 if (line.length() <= 1)
659 std::string str = line.substr(0, 5);
660 if (str.compare(
"Core ") == 0)
662 size_t st = line.find(
':', 0);
663 if (
st == std::string::npos)
672 size_t ed = line.find(
'C',
st);
673 if (
ed == std::string::npos)
688 catch (
const std::invalid_argument&
e)
697 std::istringstream
iss(line);
698 std::vector<std::string>
tokens{ std::istream_iterator<std::string>{
iss},std::istream_iterator<std::string>{} };
708 catch (
const std::invalid_argument&
e)
716 std::istringstream
iss(line);
717 std::vector<std::string>
tokens{ std::istream_iterator<std::string>{
iss},std::istream_iterator<std::string>{} };
727 catch (
const std::invalid_argument&
e)
745 const std::string& line
748 if (line.length() <= 1)
754 std::string str = line.substr(0, 6);
755 if (str.compare(
"Tctl: ") == 0)
757 size_t ed = line.find(
'C', 0);
758 if (
ed == std::string::npos)
765 str = line.substr(7, ((
ed - 1) - 7));
769 temp = std::stof(str);
794 std::cout <<
"Warning temperature for Core " <<
coreNum << std::endl;
802 std::cout <<
"Critical temperature for Core " <<
coreNum << std::endl;
812 std::vector<std::string>
commandList{
"mpstat",
"-P",
"ALL",
"1",
"1" };
849 const std::string & line
852 if (line.length() <= 1)
857 std::istringstream
iss(line);
859 std::vector<std::string>
tokens(std::istream_iterator<std::string>{
iss}, std::istream_iterator<std::string>{});
860 if (
tokens.size() < 8)
return 1;
867 catch (
const std::invalid_argument&
e)
872 catch (
const std::out_of_range&
e)
883 std::vector<float>& hdd_temps
927 const std::string& line
931 if (line.length() <= 6)
938 size_t sp = line.find(
':', 0);
941 std::istringstream
iss(line);
942 std::vector<std::string>
tokens{ std::istream_iterator<std::string>{
iss},std::istream_iterator<std::string>{} };
956 catch (
const std::invalid_argument&
e)
975 catch (
const std::out_of_range&
e)
996 std::cout <<
"Warning temperature for Disk" << std::endl;
1004 std::cout <<
"Critical temperature for Disk " << std::endl;
1045 if (line.length() <= 1)
1050 std::istringstream
iss(line);
1051 std::vector<std::string>
tokens{ std::istream_iterator<std::string>{
iss},std::istream_iterator<std::string>{} };
1054 if (
tokens.at(5).compare(
"/") == 0)
1062 catch (
const std::invalid_argument&
e)
1068 else if (
tokens.at(5).compare(
"/data") == 0)
1076 catch (
const std::invalid_argument&
e)
1082 else if (
tokens.at(5).compare(
"/boot") == 0)
1090 catch (
const std::invalid_argument&
e)
1097 catch (
const std::out_of_range&
e) {
1105 std::vector<std::string>
commandList{
"free",
"-m" };
1135 if (line.length() <= 1)
1139 std::istringstream
iss(line);
1140 std::vector<std::string>
tokens{ std::istream_iterator<std::string>{
iss},std::istream_iterator<std::string>{} };
1143 if (
tokens.at(0).compare(
"Mem:") != 0)
1155 catch (
const std::invalid_argument&
e)
1160 catch (
const std::out_of_range&
e) {
1167 std::vector<std::string>
commandList{
"chronyc",
"-c",
"tracking" };
1191 std::vector<std::string>
results;
1242 float min, max,
mean;
1302 s->setlatThreadExec();
1327 std::string
cpuFile =
"/sys/devices/system/cpu/cpu";
1329 cpuFile +=
"/cpufreq/scaling_governor";
1347 if (write(
fd, &
l,
sizeof(
l)) !=
sizeof(
l))
1371 std::string
cpuFile =
"/sys/devices/system/cpu/cpu";
1373 cpuFile +=
"/cpufreq/scaling_governor";
1399 if (
ipRecv.getName() != m_indiP_setlat.getName())
1401 log<software_error>({ __FILE__,__LINE__,
"wrong INDI property received." });
1405 if (!
ipRecv.find(
"toggle"))
return 0;
1407 if (
ipRecv[
"toggle"].getSwitchState() == pcf::IndiElement::Off)
1409 m_setLatency =
false;
1412 if (
ipRecv[
"toggle"].getSwitchState() == pcf::IndiElement::On)
1414 m_setLatency =
true;
Internal class to manage setuid privilege escalation with RAII.
The base-class for MagAO-X applications.
void updateIfChanged(pcf::IndiProperty &p, const std::string &el, const T &newVal, pcf::IndiProperty::PropertyStateType ipState=pcf::IndiProperty::Ok)
Update an INDI property element value if it has changed.
stateCodes::stateCodeT state()
Get the current state code.
int registerIndiPropertyNew(pcf::IndiProperty &prop, int(*)(void *, const pcf::IndiProperty &))
Register an INDI property which is exposed for others to request a New Property for.
int createStandardIndiToggleSw(pcf::IndiProperty &prop, const std::string &name, const std::string &label="", const std::string &group="")
Create a standard R/W INDI switch with a single toggle element.
int m_shutdown
Flag to signal it's time to shutdown. When not 0, the main loop exits.
void updateSwitchIfChanged(pcf::IndiProperty &p, const std::string &el, const pcf::IndiElement::SwitchStateType &newVal, pcf::IndiProperty::PropertyStateType ipState=pcf::IndiProperty::Ok)
Update an INDI switch element value if it has changed.
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
int threadStart(std::thread &thrd, bool &thrdInit, pid_t &tpid, pcf::IndiProperty &thProp, int thrdPrio, const std::string &cpuset, const std::string &thrdName, thisPtr *thrdThis, Function &&thrdStart)
Start a thread, using this class's privileges to set priority, etc.
int m_criticalDiskTemp
User defined critical temperature for drives.
std::string m_chronySourceMac
pcf::IndiProperty m_indiP_core_temps
Indi variable for reporting CPU core temperature(s)
int findRamUsage(float &)
Finds current RAM usage.
int findDiskUsage(float &, float &, float &)
Finds usages of space for following directory paths: /; /data; /boot.
pcf::IndiProperty m_indiP_chronyStatus
void setlatThreadExec()
Execute the frame grabber main loop.
double m_chronyRootDispersion
float m_bootUsage
Disk usage in /boot path as a value out of 100.
int parseDiskTemperature(std::string &driveName, float &temp, const std::string &line)
Parses string from system call to find drive temperatures.
int recordChronyStats(bool force=false)
float m_rootUsage
Disk usage in root path as a value out of 100.
int recordDriveTemps(bool force=false)
int recordTelem(const telem_coreloads *)
int parseCPUTemperaturesAMD(float &temp, const std::string &line)
Parses string from system call to find CPU temperatures on an AMD system.
int recordChronyStatus(bool force=false)
std::vector< std::string > m_diskNames
vector of names of the hard disks returned by hdd_temp
virtual void setupConfig()
Setup the user-defined warning and critical values for core and drive temperatures.
int parseCPUTemperatures(float &temp, const std::string &line)
Parses string from system call to find CPU temperatures.
~sysMonitor() noexcept
D'tor, declared and defined for noexcept.
virtual int appLogic()
Implementation of reading and logging each of the measured statistics.
int parseCPULoads(float &, const std::string &)
Parses string from system call to find CPU usage loads.
std::thread m_setlatThread
A separate thread for the actual setting of low latency.
pcf::IndiProperty m_setlatThreadProp
The property to hold the setlat thread details.
int m_warningDiskTemp
User defined warning temperature for drives.
pid_t m_setlatThreadID
Set latency thread ID.
pcf::IndiProperty m_indiP_setlat
std::vector< float > m_coreLoads
List of current core load(s)
int findCPUTemperatures(std::vector< float > &)
Finds all CPU core temperatures.
std::vector< float > m_coreTemps
List of current core temperature(s)
std::string m_chronySynch
int recordCoreLoads(bool force=false)
int updateVals()
Updates Indi property values of all system statistics.
double m_chronyLastOffset
virtual void loadConfig()
Load the warning and critical temperature values for core and drive temperatures.
int findDiskTemperature(std::vector< std::string > &hdd_names, std::vector< float > &hdd_temps)
Finds all drive temperatures.
INDI_NEWCALLBACK_DECL(sysMonitor, m_indiP_setlat)
int m_criticalCoreTemp
User defined critical temperature for CPU cores.
virtual int appStartup()
Registers all new Indi properties for each of the reported values to publish.
bool m_setlatThreadInit
Synchronizer to ensure set lat thread initializes before doing dangerous things.
pcf::IndiProperty m_indiP_drive_temps
Indi variable for reporting drive temperature(s)
int recordCoreTemps(bool force=false)
static void setlatThreadStart(sysMonitor *s)
Thread starter, called by threadStart on thread construction. Calls setlatThreadExec.
int parseCPUTemperaturesIntel(float &temp, const std::string &line)
Parses string from system call to find CPU temperatures on an Intel system.
int m_warningCoreTemp
User defined warning temperature for CPU cores.
float m_dataUsage
Disk usage in /data path as a value out of 100.
int criticalCoreTemperature(std::vector< float > &)
Checks if any core temperatures are warning or critical levels.
virtual int appShutdown()
Do any needed shutdown tasks; currently nothing in this app.
std::vector< std::string > m_diskNameList
vector of names of the hard disks to monitor
std::vector< float > m_diskTemps
vector of current disk temperature(s)
pcf::IndiProperty m_indiP_usage
Indi variable for reporting drive usage of all paths.
int criticalDiskTemperature(std::vector< float > &)
Checks if any drive temperatures are warning or critical levels.
float m_ramUsage
RAM usage as a decimal value between 0 and 1.
int m_setlatThreadPrio
Priority of the set latency thread, should normally be > 00.
std::string m_chronySourceIP
pcf::IndiProperty m_indiP_core_loads
Indi variable for reporting CPU core loads.
sysMonitor()
Default c'tor.
int findChronyStatus()
Finds current chronyd status.
int parseDiskUsage(std::string, float &, float &, float &)
Parses string from system call to find drive usage space.
pcf::IndiProperty m_indiP_chronyStats
double m_chronySystemTime
int findCPULoads(std::vector< float > &)
Finds all CPU core usage loads.
int parseRamUsage(std::string, float &)
Parses string from system call to find RAM usage.
int recordUsage(bool force=false)
#define INDI_NEWCALLBACK_DEFN(class, prop)
Define the callback for a new property request.
#define REG_INDI_NEWPROP_NOCB(prop, propName, type)
Register a NEW INDI property with the class, with no callback.
#define INDI_NEWCALLBACK(prop)
Get the name of the static callback wrapper for a new property.
@ READY
The device is ready for operation, but is not operating.
int runCommand(std::vector< std::string > &commandOutput, std::vector< std::string > &commandStderr, std::vector< std::string > &commandList)
Runs a command (with parameters) passed in using fork/exec.
#define INDI_VALIDATE_CALLBACK_PROPS(prop1, prop2)
Standard check for matching INDI properties in a callback.
const pcf::IndiProperty & ipRecv
static constexpr logPrioT LOG_NOTICE
A normal but significant condition.
static constexpr logPrioT LOG_WARNING
A condition has occurred which may become an error, but the process continues.
static constexpr logPrioT LOG_ALERT
This should only be used if some action is required by operators to keep the system safe.
A device base class which saves telemetry.
int appShutdown()
Perform telemeter application shutdown.
int loadConfig(appConfigurator &config)
Load the device section from an application configurator.
int setupConfig(appConfigurator &config)
Setup an application configurator for the device section.
Log entry recording the statistics from chrony.
Log entry recording the status of chrony.
Log entry recording CPU loads.
Log entry recording CPU temperatures.
Log entry recording hdd temperatures.
Log entry recording hdd temperatures.