summaryrefslogtreecommitdiff
path: root/src/get_load.c
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2009-07-21 19:07:30 +0200
committerMichael Stapelberg <michael@stapelberg.de>2009-07-21 19:07:30 +0200
commit6fda988f360b3145d5772b6964f336dd652357ea (patch)
tree31647729cafbadf3d9e8213f148e8510d4e9dfed /src/get_load.c
parent045c88dfe39c488340e0296e36ea785e9aa77e84 (diff)
Use own files for each function, add get_ipv6_addr.c
Diffstat (limited to 'src/get_load.c')
-rw-r--r--src/get_load.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/get_load.c b/src/get_load.c
new file mode 100644
index 0000000..7d5349f
--- /dev/null
+++ b/src/get_load.c
@@ -0,0 +1,25 @@
+#include "i3status.h"
+
+const char *get_load() {
+ static char part[512];
+
+/* Get load */
+#ifdef LINUX
+ slurp("/proc/loadavg", part, sizeof(part));
+ *skip_character(part, ' ', 3) = '\0';
+#else
+ /* TODO: correctly check for NetBSD, check if it works the same on *BSD */
+ struct loadavg load;
+ size_t length = sizeof(struct loadavg);
+ int mib[2] = { CTL_VM, VM_LOADAVG };
+ if (sysctl(mib, 2, &load, &length, NULL, 0) < 0)
+ die("Could not sysctl({ CTL_VM, VM_LOADAVG })\n");
+ double scale = load.fscale;
+ (void)snprintf(part, sizeof(part), "%.02f %.02f %.02f",
+ (double)load.ldavg[0] / scale,
+ (double)load.ldavg[1] / scale,
+ (double)load.ldavg[2] / scale);
+#endif
+
+ return part;
+}