summaryrefslogtreecommitdiff
path: root/src/status/memusage.c
diff options
context:
space:
mode:
authornorly <ny-git@enpas.org>2013-02-15 01:19:41 +0000
committernorly <ny-git@enpas.org>2013-02-15 01:30:22 +0000
commit430ce2a8749eb90ca0f8cdf18f5b217128c43e79 (patch)
tree8c838780bda4c7ebf4f778ca307f01b2d39bdfbe /src/status/memusage.c
parent2ddbfa53a31360e50565345a1ac08c0799c8243e (diff)
Better file structure and build system
Also fix some warnings
Diffstat (limited to 'src/status/memusage.c')
-rw-r--r--src/status/memusage.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/status/memusage.c b/src/status/memusage.c
new file mode 100644
index 0000000..6a6cb21
--- /dev/null
+++ b/src/status/memusage.c
@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "status/memusage.h"
+#include "tools.h"
+
+
+void status_memusage()
+{
+ char *stline = NULL;
+ size_t stlen;
+ FILE *stfile;
+
+ int memtotal = 0;
+ int memfree = 0;
+ int memused;
+ int membuffers = 0;
+ int memcached = 0;
+
+
+ stfile = fopen("/proc/meminfo", "r");
+ if (stfile != NULL) {
+ stlen = getline(&stline, &stlen, stfile);
+ memtotal = atoi(&stline[17]);
+
+ stlen = getline(&stline, &stlen, stfile);
+ memfree = atoi(&stline[17]);
+
+ stlen = getline(&stline, &stlen, stfile);
+ membuffers = atoi(&stline[17]);
+
+ stlen = getline(&stline, &stlen, stfile);
+ memcached = atoi(&stline[17]);
+ free(stline);
+
+ fclose(stfile);
+
+ memused = memtotal - memfree - memcached - membuffers;
+
+ memused /= 1024; // Just show MBs used
+
+ /* Change color based on % of RAM used */
+ if ((float)memused / (float)memtotal < 0.85) {
+ fputs("^fg(green)", stdout);
+ } else {
+ fputs("^fg(red)", stdout);
+ }
+
+ printf(" Mem: %d M ", memused);
+ }
+}