X-Git-Url: https://git.wpitchoune.net/gitweb/?p=psensor.git;a=blobdiff_plain;f=src%2Fserver%2Fsysinfo.c;h=9c371d5621500be52105eb82d2e53b5f997d5976;hp=7ff70f45d579ddc429ce443c8b10ca603b50626a;hb=c1e20f2631a1249720e9c75d753eacfcb0f6c7b9;hpb=c97de26994a67a9d07941b95a3ad2a9323e64ddf diff --git a/src/server/sysinfo.c b/src/server/sysinfo.c index 7ff70f4..9c371d5 100644 --- a/src/server/sysinfo.c +++ b/src/server/sysinfo.c @@ -1,29 +1,33 @@ /* - Copyright (C) 2010-2011 jeanfi@gmail.com - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - + * Copyright (C) 2010-2016 jeanfi@gmail.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ #include #include #include #include -#include +#include "config.h" + +#ifdef HAVE_JSON_0 #include +#else +#include +#endif #include "sysinfo.h" @@ -36,8 +40,6 @@ void sysinfo_update(struct psysinfo *info) unsigned long int used = 0; unsigned long int dt; glibtop_netlist buf; - char **interfaces; - guint32 i; /* cpu */ if (!cpu) @@ -55,48 +57,50 @@ void sysinfo_update(struct psysinfo *info) last_used = used; last_total = cpu->total; - /* memory */ - sysinfo(&info->sysinfo); + glibtop_get_loadavg(&info->loadavg); + glibtop_get_mem(&info->mem); + glibtop_get_swap(&info->swap); + glibtop_get_uptime(&info->uptime); /* network */ if (!info->interfaces) info->interfaces = glibtop_get_netlist(&buf); } -void sysinfo_cleanup() +void sysinfo_cleanup(void) { if (cpu) - free(cpu); + g_free(cpu); } -static json_object *ram_to_json_object(const struct sysinfo *s) +static json_object *ram_to_json_object(const struct psysinfo *s) { json_object *obj = json_object_new_object(); json_object_object_add(obj, "total", - json_object_new_double(s->totalram)); + json_object_new_double(s->mem.total)); json_object_object_add(obj, "free", - json_object_new_double(s->freeram)); + json_object_new_double(s->mem.free)); json_object_object_add(obj, "shared", - json_object_new_double(s->sharedram)); + json_object_new_double(s->mem.shared)); json_object_object_add(obj, "buffer", - json_object_new_double(s->bufferram)); + json_object_new_double(s->mem.buffer)); return obj; } -static json_object *swap_to_json_object(const struct sysinfo *s) +static json_object *swap_to_json_object(const struct psysinfo *s) { json_object *obj = json_object_new_object(); json_object_object_add(obj, "total", - json_object_new_double(s->totalswap)); + json_object_new_double(s->swap.total)); json_object_object_add(obj, "free", - json_object_new_double(s->freeswap)); + json_object_new_double(s->swap.free)); return obj; } @@ -135,34 +139,33 @@ static json_object *net_to_json_object(const struct psysinfo *s) static json_object *sysinfo_to_json_object(const struct psysinfo *s) { - static float load_scale = 1 << SI_LOAD_SHIFT; - json_object *mo; - json_object *obj = json_object_new_object(); - struct measure *m; + json_object *obj; + + obj = json_object_new_object(); json_object_object_add(obj, "load", json_object_new_double(s->cpu_rate)); json_object_object_add (obj, "load_1", - json_object_new_double(s->sysinfo.loads[0] / load_scale)); + json_object_new_double(s->loadavg.loadavg[0])); json_object_object_add (obj, "load_5", - json_object_new_double(s->sysinfo.loads[1] / load_scale)); + json_object_new_double(s->loadavg.loadavg[1])); json_object_object_add (obj, "load_15", - json_object_new_double(s->sysinfo.loads[2] / load_scale)); + json_object_new_double(s->loadavg.loadavg[2])); json_object_object_add - (obj, "uptime", json_object_new_double(s->sysinfo.uptime)); + (obj, "uptime", json_object_new_double(s->uptime.uptime)); json_object_object_add - (obj, "mem_unit", json_object_new_double(s->sysinfo.mem_unit)); + (obj, "mem_unit", json_object_new_double(1)); - json_object_object_add(obj, "ram", ram_to_json_object(&s->sysinfo)); - json_object_object_add(obj, "swap", swap_to_json_object(&s->sysinfo)); + json_object_object_add(obj, "ram", ram_to_json_object(s)); + json_object_object_add(obj, "swap", swap_to_json_object(s)); json_object_object_add(obj, "net", net_to_json_object(s)); return obj;