Skip to content

Commit

Permalink
information: add system uptime
Browse files Browse the repository at this point in the history
  • Loading branch information
blocktrron committed Mar 19, 2024
1 parent e08561b commit e763dba
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/information.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#include <string.h>
#include <unistd.h>
#include <stddef.h>

#include <linux/unistd.h>
#include <linux/kernel.h>
#include <sys/sysinfo.h>

#include "batadv.h"
#include "util.h"
#include "information.h"
Expand Down Expand Up @@ -85,6 +90,23 @@ int gluon_beacon_diagnostic_information_batman_adv_collect(uint8_t *buffer, size
return 3;
}

int gluon_beacon_diagnostic_information_uptime_collect(uint8_t *buffer, size_t buffer_size) {
struct sysinfo s_info;
uint32_t uptime_minutes;
int ret;

ret = sysinfo(&s_info);
if (ret) {
return -1;
}

uptime_minutes = s_info.uptime / 60;

memcpy(buffer, &uptime_minutes, sizeof(uptime_minutes));

return sizeof(uptime_minutes) / sizeof(uint8_t);
}

#else

int gluon_beacon_diagnostic_information_hostname_parse(const uint8_t *buffer, size_t buffer_size) {
Expand Down Expand Up @@ -117,12 +139,24 @@ int gluon_beacon_diagnostic_information_batman_adv_parse(const uint8_t *buffer,
return 0;
}

int gluon_beacon_diagnostic_information_uptime_parse(const uint8_t *buffer, size_t buffer_size) {
const uint8_t *ie_buf = &buffer[2];
uint8_t ie_len = buffer[1];
uint32_t uptime_minutes;

memcpy(&uptime_minutes, ie_buf, sizeof(uptime_minutes));
printf("Uptime: %d minutes\n", uptime_minutes);

return 0;
}

#endif


struct gluon_beacon_information_source information_sources[] = {
INFORMATION_SOURCE(hostname, 0),
INFORMATION_SOURCE(node_id, 1),
INFORMATION_SOURCE(uptime, 2),
INFORMATION_SOURCE(batman_adv, 20),
{},
};

0 comments on commit e763dba

Please sign in to comment.