From 20cf08e2a1de6408feac467c8e5f1e6c4372559e Mon Sep 17 00:00:00 2001 From: Vladislav Ostapov Date: Thu, 9 Jan 2025 12:02:42 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20sysinf?= =?UTF-8?q?o=20=D0=B8=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=B0=D0=BF?= =?UTF-8?q?=D1=82=D0=B0=D0=B9=D0=BC=D0=B0=20=D0=B2=20=D0=B2=D0=B5=D0=B1-?= =?UTF-8?q?=D0=BC=D0=BE=D1=80=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 2 ++ src/terminal_api_driver.cpp | 40 +++++++++++++++++++++++++++++++++++++ src/terminal_api_driver.h | 2 ++ static/main-scpc.html | 17 ++++++++++++++++ static/main-tdma.html | 17 ++++++++++++++++ 5 files changed, 78 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 3cae31a..d7617a9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -206,6 +206,8 @@ public: rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)}); std::string result = R"({"mainState":)"; result += api->loadTerminalState(); + result += R"(,"sysinfo":)"; + result += api->loadSysInfo(); result += "}"; rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size()); })); diff --git a/src/terminal_api_driver.cpp b/src/terminal_api_driver.cpp index a41c66b..4bcde72 100644 --- a/src/terminal_api_driver.cpp +++ b/src/terminal_api_driver.cpp @@ -8,6 +8,8 @@ #include #include #include +#include + typedef boost::property_tree::ptree::path_type json_path; @@ -1091,4 +1093,42 @@ void api_driver::ApiDriver::executeInApi(const std::function& ca } } +std::string api_driver::ApiDriver::loadSysInfo() { + std::stringstream result; + struct sysinfo info{}; + sysinfo(&info); + + struct sysinfo { + long uptime; /* Seconds since boot */ + unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ + unsigned long totalram; /* Total usable main memory size */ + unsigned long freeram; /* Available memory size */ + unsigned long sharedram; /* Amount of shared memory */ + unsigned long bufferram; /* Memory used by buffers */ + unsigned long totalswap; /* Total swap space size */ + unsigned long freeswap; /* Swap space still available */ + unsigned short procs; /* Number of current processes */ + unsigned long totalhigh; /* Total high memory size */ + unsigned long freehigh; /* Available high memory size */ + unsigned int mem_unit; /* Memory unit size in bytes */ + }; + + result << "{\n\"uptime\":" << info.uptime; + result << ",\"load1min\":" << info.loads[0]; + result << ",\"load5min\":" << info.loads[1]; + result << ",\"load15min\":" << info.loads[2]; + result << ",\"totalram\":" << info.totalram; + result << ",\"freeram\":" << info.freeram; + result << ",\"sharedram\":" << info.sharedram; + result << ",\"bufferram\":" << info.bufferram; + result << ",\"totalswap\":" << info.totalswap; + result << ",\"freeswap\":" << info.freeswap; + result << ",\"procs\":" << static_cast(info.procs); + result << ",\"totalhigh\":" << info.totalhigh; + result << ",\"freehigh\":" << info.freehigh; + result << ",\"mem_unit\":" << info.mem_unit; + result << "\n}"; + return result.str(); +} + api_driver::ApiDriver::~ApiDriver() = default; diff --git a/src/terminal_api_driver.h b/src/terminal_api_driver.h index f1e8ae2..c173070 100644 --- a/src/terminal_api_driver.h +++ b/src/terminal_api_driver.h @@ -70,6 +70,8 @@ namespace api_driver { void executeInApi(const std::function& callback); + static std::string loadSysInfo(); + ~ApiDriver(); private: diff --git a/static/main-scpc.html b/static/main-scpc.html index 846e48b..c28e803 100644 --- a/static/main-scpc.html +++ b/static/main-scpc.html @@ -118,6 +118,7 @@ Температура ADRV{{ stat_device.adrv }} °C Температура ZYNQ{{ stat_device.zynq }} °C Температура FPGA{{ stat_device.fpga }} °C + Uptime{{ stat_os.uptime }} @@ -849,6 +850,7 @@ stat_device: { // температурные датчики adrv: 0, zynq: 0, fpga: 0 }, + stat_os: {uptime: '?'}, param: { general: { @@ -1037,6 +1039,21 @@ this.stat_device.fpga = vals["mainState"]["device.fpga"] this.testState = vals["mainState"]["testState"] + + // аптайм приходит в секундах, надо преобразовать его в человеко-читаемый вид + let uptime = vals["sysinfo"]["uptime"] + if (uptime) { + let secs = uptime % 60; uptime = Math.floor(uptime / 60) + let mins = uptime % 60; uptime = Math.floor(uptime / 60) + let hours = uptime % 24 + uptime = Math.floor( uptime / 24) + let res = `${mins}m ${secs}s` + if (hours > 0) { res = `${hours}h ` + res } + if (uptime > 0) { res = `${uptime}d ` + res } + this.stat_os.uptime = res + } else { + this.stat_os.uptime = '?' + } }, resetPacketsStatistics() { diff --git a/static/main-tdma.html b/static/main-tdma.html index 17769a5..eb81ef2 100644 --- a/static/main-tdma.html +++ b/static/main-tdma.html @@ -105,6 +105,7 @@ Температура ADRV{{ stat_device.adrv }} °C Температура ZYNQ{{ stat_device.zynq }} °C Температура FPGA{{ stat_device.fpga }} °C + Uptime{{ stat_os.uptime }} @@ -641,6 +642,7 @@ stat_device: { // температурные датчики adrv: 0, zynq: 0, fpga: 0 }, + stat_os: {uptime: '?'}, param: { tx: { @@ -775,6 +777,21 @@ this.stat_device.fpga = vals["mainState"]["device.fpga"] this.testState = vals["mainState"]["testState"] + + // аптайм приходит в секундах, надо преобразовать его в человеко-читаемый вид + let uptime = vals["sysinfo"]["uptime"] + if (uptime) { + let secs = uptime % 60; uptime = Math.floor(uptime / 60) + let mins = uptime % 60; uptime = Math.floor(uptime / 60) + let hours = uptime % 24 + uptime = Math.floor( uptime / 24) + let res = `${mins}m ${secs}s` + if (hours > 0) { res = `${hours}h ` + res } + if (uptime > 0) { res = `${uptime}d ` + res } + this.stat_os.uptime = res + } else { + this.stat_os.uptime = '?' + } }, resetPacketsStatistics() {