mirror of https://git.48k.eu/ogserver
#915 add seconds since ogserver has been launched
Extend GET /stats to show the number of seconds since the ogserver started. { "time": { "now": 1647262765, /* Seconds since 1970 */ "boot": 2151909 /* Seconds since boot */ "start" : 1647262854,, /* Seconds since 1970 */ }, [...]master
parent
3b4aa721a4
commit
f3422f6afa
|
@ -3,6 +3,7 @@
|
|||
|
||||
extern int socket_rest, socket_agent_rest;
|
||||
extern struct ev_loop *og_loop;
|
||||
extern time_t start_time;
|
||||
|
||||
int og_socket_server_init(const char *port);
|
||||
void og_server_accept_cb(struct ev_loop *loop, struct ev_io *io, int events);
|
||||
|
|
|
@ -34,12 +34,16 @@ struct og_server_cfg ogconfig = {
|
|||
},
|
||||
};
|
||||
|
||||
time_t start_time;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char config_file[PATH_MAX + 1] = OG_SERVER_CFG_JSON;
|
||||
struct ev_io ev_io_server_rest, ev_io_agent_rest;
|
||||
int val;
|
||||
|
||||
start_time = time(NULL);
|
||||
|
||||
og_loop = ev_default_loop(0);
|
||||
|
||||
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "utils.h"
|
||||
#include "list.h"
|
||||
#include "rest.h"
|
||||
#include "core.h"
|
||||
#include "wol.h"
|
||||
#include "cfg.h"
|
||||
#include "schedule.h"
|
||||
|
@ -5424,6 +5425,7 @@ static int og_cmd_get_server_stats(char *buffer_reply)
|
|||
.data = buffer_reply
|
||||
};
|
||||
struct sysinfo stats;
|
||||
time_t now;
|
||||
|
||||
sysinfo(&stats);
|
||||
|
||||
|
@ -5449,8 +5451,10 @@ static int og_cmd_get_server_stats(char *buffer_reply)
|
|||
return -1;
|
||||
}
|
||||
|
||||
json_object_set_new(time_obj, "now", json_integer(time(NULL)));
|
||||
now = time(NULL);
|
||||
json_object_set_new(time_obj, "now", json_integer(now));
|
||||
json_object_set_new(time_obj, "boot", json_integer(stats.uptime));
|
||||
json_object_set_new(time_obj, "start", json_integer(now - start_time));
|
||||
json_object_set_new(root, "time", time_obj);
|
||||
|
||||
json_object_set_new(memory, "size", json_integer(stats.totalram));
|
||||
|
|
Loading…
Reference in New Issue