diff --git a/openwrt/node-whisperer/files/node-whisperer.uci b/openwrt/node-whisperer/files/node-whisperer.uci index a126ca8..9fc97c1 100644 --- a/openwrt/node-whisperer/files/node-whisperer.uci +++ b/openwrt/node-whisperer/files/node-whisperer.uci @@ -7,4 +7,5 @@ config settings 'settings' list information 'uptime' list information 'site_code' list information 'domain' + list information 'system_load' list information 'batman_adv' diff --git a/src/information.c b/src/information.c index 1c8bbb2..f7a5b28 100644 --- a/src/information.c +++ b/src/information.c @@ -195,6 +195,21 @@ int node_whisperer_information_domain_collect(uint8_t *buffer, size_t buffer_siz return ret; } +int node_whisperer_information_system_load_collect(uint8_t *buffer, size_t buffer_size) { + double samples[3]; + + if (buffer_size < 1) { + return -1; + } + + if (getloadavg(samples, 3) < 3) { + return -1; + } + + buffer[0] = (uint8_t) samples[0] * 10; + return 1; +} + #else int node_whisperer_information_hostname_parse(const uint8_t *ie_buf, size_t ie_len) { @@ -280,6 +295,17 @@ int node_whisperer_information_domain_parse(const uint8_t *ie_buf, size_t ie_len return 0; } +int node_whisperer_information_system_load_parse(const uint8_t *ie_buf, size_t ie_len) { + double load; + + if (ie_len < 1) + return -1; + + load = (double)ie_buf[0] / 0.1; + printf("System load: %.1f\n", load); + return 0; +} + #endif @@ -289,6 +315,7 @@ struct nw_information_source information_sources[] = { INFORMATION_SOURCE(uptime, 2), INFORMATION_SOURCE(site_code, 3), INFORMATION_SOURCE(domain, 4), + INFORMATION_SOURCE(system_load, 5), INFORMATION_SOURCE(batman_adv, 20), {}, };