Skip to content

Commit

Permalink
information: add system-load
Browse files Browse the repository at this point in the history
  • Loading branch information
blocktrron committed Apr 5, 2024
1 parent d426f05 commit 491cb5d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions openwrt/node-whisperer/files/node-whisperer.uci
Original file line number Diff line number Diff line change
Expand Up @@ -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'
27 changes: 27 additions & 0 deletions src/information.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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


Expand All @@ -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),
{},
};

0 comments on commit 491cb5d

Please sign in to comment.