COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
cpustruc Struct Reference

CPU information. More...

#include <jsondef.h>

Collaboration diagram for cpustruc:

Public Member Functions

json11::Json to_json () const
 Convert class contents to JSON object. More...
 
void from_json (const string &s)
 Set class contents from JSON string. More...
 

Public Attributes

uint32_t uptime = 0
 Seconds CPU has been up. More...
 
float load = 0.f
 Current load. More...
 
float maxload = 0.f
 Maximum load. More...
 
float maxgib = 0.f
 Maximum memory capacity in GiB. More...
 
float gib = 0.f
 Current memory usage in GiB. More...
 
uint32_t boot_count = 0
 Number of reboots. More...
 

Detailed Description

CPU information.

Member Function Documentation

json11::Json cpustruc::to_json ( ) const
inline

Convert class contents to JSON object.

Returns a json11 JSON object of the class

Returns
A json11 JSON object containing every member variable within the class
2079  {
2080  return json11::Json::object {
2081  { "uptime" , static_cast<int>(uptime) },
2082  { "load" , load },
2083  { "maxload", maxload },
2084  { "maxgib" , maxgib },
2085  { "gib" , gib },
2086  { "boot_count", static_cast<int>(boot_count) },
2087  };
2088  }
std::map< std::string, Json > object
Definition: json11.hpp:88
uint32_t boot_count
Number of reboots.
Definition: jsondef.h:2073
float maxload
Maximum load.
Definition: jsondef.h:2064
uint32_t uptime
Seconds CPU has been up.
Definition: jsondef.h:2060
float maxgib
Maximum memory capacity in GiB.
Definition: jsondef.h:2068
float load
Current load.
Definition: jsondef.h:2062
float gib
Current memory usage in GiB.
Definition: jsondef.h:2070
void cpustruc::from_json ( const string &  s)
inline

Set class contents from JSON string.

Parses the provided JSON-formatted string and sets the class data. String should be formatted like the string returned from to_json()

Parameters
sJSON-formatted string to set class contents to
Returns
n/a
2096  {
2097  string error;
2098  json11::Json parsed = json11::Json::parse(s,error);
2099  if(error.empty()) {
2100  if(!parsed["uptime"].is_null()) { uptime = parsed["uptime"].int_value(); }
2101  if(!parsed["load"].is_null()) { load = parsed["load"].number_value(); }
2102  if(!parsed["maxload"].is_null()) { maxload = parsed["maxload"].number_value(); }
2103  if(!parsed["maxgib"].is_null()) { maxgib = parsed["maxgib"].number_value(); }
2104  if(!parsed["gib"].is_null()) { gib = parsed["gib"].number_value(); }
2105  if(!parsed["boot_count"].is_null()) { boot_count = parsed["boot_count"].int_value(); }
2106  } else {
2107  cerr<<"ERROR: <"<<error<<">"<<endl;
2108  }
2109  return;
2110  }
Definition: json11.hpp:79
uint32_t boot_count
Number of reboots.
Definition: jsondef.h:2073
float maxload
Maximum load.
Definition: jsondef.h:2064
static Json parse(const std::string &in, std::string &err, JsonParse strategy=JsonParse::STANDARD)
uint32_t uptime
Seconds CPU has been up.
Definition: jsondef.h:2060
float maxgib
Maximum memory capacity in GiB.
Definition: jsondef.h:2068
float load
Current load.
Definition: jsondef.h:2062
int int_value() const
Definition: json11.cpp:281
float gib
Current memory usage in GiB.
Definition: jsondef.h:2070
double number_value() const
Definition: json11.cpp:280

Member Data Documentation

uint32_t cpustruc::uptime = 0

Seconds CPU has been up.

float cpustruc::load = 0.f

Current load.

float cpustruc::maxload = 0.f

Maximum load.

float cpustruc::maxgib = 0.f

Maximum memory capacity in GiB.

float cpustruc::gib = 0.f

Current memory usage in GiB.

uint32_t cpustruc::boot_count = 0

Number of reboots.


The documentation for this struct was generated from the following file: