Adding uptime and memory.

This commit is contained in:
stephb9959
2022-03-17 14:27:27 -07:00
parent 2b3ef020f8
commit 6ad843f94e
6 changed files with 33 additions and 2 deletions

View File

@@ -216,6 +216,11 @@ components:
format: int64
locale:
type: string
memory:
type: number
uptime:
type: integer
format: int64
DeviceInfoList:
type: object

View File

@@ -21,7 +21,22 @@ namespace OpenWifi {
// find radios first to get associations.
try {
DI_.lastState = (*State)["unit"]["localtime"];
if(State->contains("unit")) {
auto unit = (*State)["unit"];
GetJSON("localtime", unit, DI_.lastState, (uint64_t) 0);
GetJSON("uptime", unit, DI_.uptime, (uint64_t) 0);
if(unit.contains("memory")) {
auto memory = unit["memory"];
uint64_t free_mem, total_mem;
GetJSON("free", memory, free_mem, (uint64_t) 0);
GetJSON("total", memory, total_mem, (uint64_t) 0);
if(total_mem) {
DI_.memory = ((double) (total_mem - free_mem) / (double)total_mem) * 100.0;
} else {
DI_.memory = 0.0;
}
}
}
std::map<uint, uint> radio_band;
if(State->contains("radios") && (*State)["radios"].is_array()) {

View File

@@ -37,7 +37,7 @@ namespace OpenWifi {
class UE {
public:
UE(uint64_t Station):
explicit UE(uint64_t Station):
Station_(Station) {
}

View File

@@ -79,6 +79,8 @@ namespace OpenWifi::AnalyticsObjects {
field_to_json(Obj,"health",health);
field_to_json(Obj,"lastHealth",lastHealth);
field_to_json(Obj,"locale",locale);
field_to_json(Obj,"uptime",uptime);
field_to_json(Obj,"memory",memory);
}
bool DeviceInfo::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -104,6 +106,8 @@ namespace OpenWifi::AnalyticsObjects {
field_from_json(Obj,"health",health);
field_from_json(Obj,"lastHealth",lastHealth);
field_from_json(Obj,"locale",locale);
field_from_json(Obj,"uptime",uptime);
field_from_json(Obj,"memory",memory);
return true;
} catch(...) {

View File

@@ -68,6 +68,8 @@ namespace OpenWifi {
uint64_t health;
uint64_t lastHealth;
std::string locale;
uint64_t uptime;
double memory;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);

View File

@@ -280,6 +280,11 @@ namespace OpenWifi::RESTAPI_utils {
S = Obj->get(Field).toString();
}
inline void field_from_json(Poco::JSON::Object::Ptr Obj, const char *Field, double & V) {
if(Obj->has(Field))
V = Obj->get(Field);
}
inline void field_from_json(Poco::JSON::Object::Ptr Obj, const char *Field, uint64_t &V) {
if(Obj->has(Field))
V = Obj->get(Field);