diff --git a/src/lxcstat.c b/src/lxcstat.c index 1e54740..db93472 100644 --- a/src/lxcstat.c +++ b/src/lxcstat.c @@ -1,19 +1,20 @@ -#include -#include -#include - #include "lxcstat.h" + +#include +#include +#include + #include "parsing.h" int parseLxcConfigFile(lxcinfo *lxc, char *filedata) { - lxc->cpucount = 0; - lxc->memlimit = 0; - char *temp = filedata; lxc->cpucount = findAndParseField(&temp, "cores"); temp = filedata; lxc->memlimit = findAndParseField(&temp, "memory") * 1024 * 1024; + temp = filedata; + + lxc->swaplimit = findAndParseField(&temp, "swap") * 1024 * 1024; char *ptr = strstr(filedata, "hostname:"); ptr += strlen("hostname:"); @@ -48,7 +49,7 @@ lxcinfo *getLXCInfo(lxcinfo **lxcs, int lxcid) { lxc = lxc->next; } - lxc = malloc(sizeof(lxcinfo)); + lxc = calloc(1, sizeof(lxcinfo)); lxc->lxcid = lxcid; if (readLxcConfig(lxc, lxcid)) { diff --git a/src/lxcstat.h b/src/lxcstat.h index f96490b..5032b1d 100644 --- a/src/lxcstat.h +++ b/src/lxcstat.h @@ -8,6 +8,7 @@ typedef struct _lxc_info { int lxcid; int cpucount; int memlimit; + int swaplimit; char hostname[128]; } lxcinfo; diff --git a/src/server.c b/src/server.c index 6d0b393..d6f6a11 100644 --- a/src/server.c +++ b/src/server.c @@ -61,16 +61,8 @@ int parseStatFile(Process *proc, char *filedata) { proc->cpuTime += fast_str2ull(&location); location += 1; - // (16) cutime - %lu - proc->childCpuTime = fast_str2ull(&location); - location += 1; - - // (17) cstime - %lu - proc->childCpuTime += fast_str2ull(&location); - location += 1; - - // skip 18-19 - skipRange(18, 20); + // skip 16-19 + skipRange(16, 20); // (20) num_threads - %ld proc->nThreads = fast_str2ull(&location); @@ -118,9 +110,7 @@ char *readProcesses(char *procdir) { char first; FILE *file; - Process *cur = malloc(sizeof(Process)); - cur->prev = NULL; - cur->next = NULL; + Process *cur = calloc(1, sizeof(Process)); Process *head = cur; lxcinfo *lxcs = NULL; @@ -172,7 +162,7 @@ char *readProcesses(char *procdir) { } nextProcess: - cur->next = malloc(sizeof(Process)); + cur->next = calloc(1, sizeof(Process)); cur->next->prev = cur; cur = cur->next; } @@ -211,6 +201,7 @@ char *readProcesses(char *procdir) { sprintf(buffer, "lxc=\"%d\",lxcname=\"%s\"", lxc->lxcid, lxc->hostname); ptr += sprintf(ptr, "lxc_cpu_core_count{%s} %u\n", buffer, lxc->cpucount); ptr += sprintf(ptr, "lxc_memory_limit_bytes{%s} %llu\n", buffer, lxc->memlimit); + ptr += sprintf(ptr, "lxc_swap_limit_bytes{%s} %llu\n", buffer, lxc->swaplimit); // free and proceed lxcinfo *prev = lxc; lxc = lxc->next;