1 // vim:ts=4:sw=4:expandtab
6 #include <yajl/yajl_gen.h>
7 #include <yajl/yajl_version.h>
9 void print_load(yajl_gen json_gen, char *buffer, const char *format, const float max_threshold) {
10 char *outwalk = buffer;
13 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(linux) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(sun) || defined(__DragonFly__)
16 bool colorful_output = false;
18 if (getloadavg(loadavg, 3) == -1)
21 for (walk = format; *walk != '\0'; walk++) {
26 if (loadavg[0] >= max_threshold) {
27 START_COLOR("color_bad");
28 colorful_output = true;
31 if (BEGINS_WITH(walk + 1, "1min")) {
32 outwalk += sprintf(outwalk, "%1.2f", loadavg[0]);
33 walk += strlen("1min");
36 if (BEGINS_WITH(walk + 1, "5min")) {
37 outwalk += sprintf(outwalk, "%1.2f", loadavg[1]);
38 walk += strlen("5min");
41 if (BEGINS_WITH(walk + 1, "15min")) {
42 outwalk += sprintf(outwalk, "%1.2f", loadavg[2]);
43 walk += strlen("15min");
50 OUTPUT_FULL_TEXT(buffer);
55 OUTPUT_FULL_TEXT("cant read load");
56 (void)fputs("i3status: Cannot read system load using getloadavg()\n", stderr);