summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2022-06-21 21:35:46 -0600
committerAaron Ball <nullspoon@oper.io>2022-06-21 21:37:25 -0600
commit2f875b8c71fcacea805bba947b3ecf9524279bbf (patch)
tree808ce5dcbb799393b370157b777e25f69a527f45 /src
parent14269261189b2c45addf0c67daf4b0ca52c7b381 (diff)
downloadcmon-2f875b8c71fcacea805bba947b3ecf9524279bbf.tar.gz
cmon-2f875b8c71fcacea805bba947b3ecf9524279bbf.tar.xz
Update meminfo values to include total
This renames `memmax` to `memusedmax`, and `memavg` to `memusedavg` and adds an additional data point `memtotal`.
Diffstat (limited to 'src')
-rw-r--r--src/main.c7
-rw-r--r--src/status.c57
-rw-r--r--src/status.h5
3 files changed, 37 insertions, 32 deletions
diff --git a/src/main.c b/src/main.c
index 42d2b5e..41b300f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -38,9 +38,10 @@ int main(int argc, char* argv[]) {
}
// Calculate max memory usage and average memory usage
- if(status.memmax < (minfo.used))
- status.memmax = minfo.used;
- status.memavg = (((status.count - 1) * status.memavg) + minfo.used) / status.count;
+ if(status.memusedmax < (minfo.used))
+ status.memusedmax = minfo.used;
+ status.memusedavg = (((status.count - 1) * status.memusedavg) + minfo.used) / status.count;
+ status.memtotal = minfo.total;
// Calculate load max and incremental load average
double load = cpuinfo_load1m();
diff --git a/src/status.c b/src/status.c
index 8cbf523..f7148f9 100644
--- a/src/status.c
+++ b/src/status.c
@@ -20,27 +20,29 @@
int status_init(struct status* s) {
int status = 0;
- s->memmax = 0;
- s->memavg = 0;
- s->loadavg = 0;
- s->loadmax = 0;
- s->nettx = 0;
- s->netrx = 0;
- s->count = 0;
- s->uptime = 0;
+ s->memtotal = 0;
+ s->memusedmax = 0;
+ s->memusedavg = 0;
+ s->loadavg = 0;
+ s->loadmax = 0;
+ s->nettx = 0;
+ s->netrx = 0;
+ s->count = 0;
+ s->uptime = 0;
FILE* fd = fopen("/tmp/cmon.status", "r");
if(fd) {
- status += fscanf(fd, "memmax:%ld\n", &s->memmax);
- status += fscanf(fd, "memavg:%ld\n", &s->memavg);
- status += fscanf(fd, "loadmax:%lf\n", &s->loadmax);
- status += fscanf(fd, "loadavg:%lf\n", &s->loadavg);
- status += fscanf(fd, "nprocs:%d\n", &s->nprocs);
- status += fscanf(fd, "nettx:%lld\n", &s->nettx);
- status += fscanf(fd, "netrx:%lld\n", &s->netrx);
- status += fscanf(fd, "uptime:%ld\n", &s->uptime);
- status += fscanf(fd, "count:%ld\n", &s->count);
- if(status != 9) {
+ status += fscanf(fd, "memtotal:%ld\n", &s->memtotal);
+ status += fscanf(fd, "memusedmax:%ld\n", &s->memusedmax);
+ status += fscanf(fd, "memusedavg:%ld\n", &s->memusedavg);
+ status += fscanf(fd, "loadmax:%lf\n", &s->loadmax);
+ status += fscanf(fd, "loadavg:%lf\n", &s->loadavg);
+ status += fscanf(fd, "nprocs:%d\n", &s->nprocs);
+ status += fscanf(fd, "nettx:%lld\n", &s->nettx);
+ status += fscanf(fd, "netrx:%lld\n", &s->netrx);
+ status += fscanf(fd, "uptime:%ld\n", &s->uptime);
+ status += fscanf(fd, "count:%ld\n", &s->count);
+ if(status != 10) {
fprintf(stderr, "ERROR reading status file\n");
return 0;
}
@@ -52,15 +54,16 @@ int status_init(struct status* s) {
int status_write(struct status* s) {
FILE* fd = fopen("/tmp/cmon.status", "w");
- fprintf(fd, "memmax:%ld\n", s->memmax);
- fprintf(fd, "memavg:%ld\n", s->memavg);
- fprintf(fd, "loadmax:%lf\n", s->loadmax);
- fprintf(fd, "loadavg:%lf\n", s->loadavg);
- fprintf(fd, "nprocs:%d\n", s->nprocs);
- fprintf(fd, "nettx:%lld\n", s->nettx);
- fprintf(fd, "netrx:%lld\n", s->netrx);
- fprintf(fd, "uptime:%ld\n", s->uptime);
- fprintf(fd, "count:%ld\n", s->count);
+ fprintf(fd, "memtotal:%ld\n", s->memtotal);
+ fprintf(fd, "memusedmax:%ld\n", s->memusedmax);
+ fprintf(fd, "memusedavg:%ld\n", s->memusedavg);
+ fprintf(fd, "loadmax:%lf\n", s->loadmax);
+ fprintf(fd, "loadavg:%lf\n", s->loadavg);
+ fprintf(fd, "nprocs:%d\n", s->nprocs);
+ fprintf(fd, "nettx:%lld\n", s->nettx);
+ fprintf(fd, "netrx:%lld\n", s->netrx);
+ fprintf(fd, "uptime:%ld\n", s->uptime);
+ fprintf(fd, "count:%ld\n", s->count);
fclose(fd);
return 1;
diff --git a/src/status.h b/src/status.h
index 92ac911..89d0102 100644
--- a/src/status.h
+++ b/src/status.h
@@ -19,8 +19,9 @@
#include <stdlib.h>
struct status {
- long memmax;
- long memavg;
+ long memtotal;
+ long memusedmax;
+ long memusedavg;
double loadmax;
double loadavg;
int nprocs;

Generated by cgit