1 // vim:ts=4:sw=4:expandtab
7 #include <yajl/yajl_gen.h>
8 #include <yajl/yajl_version.h>
10 void print_load(yajl_gen json_gen, char *buffer, const char *format, const char *format_above_threshold, const float max_threshold) {
11 char *outwalk = buffer;
14 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(linux) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(sun) || defined(__DragonFly__)
16 const char *selected_format = format;
18 bool colorful_output = false;
20 if (getloadavg(loadavg, 3) == -1)
23 if (loadavg[0] >= max_threshold) {
24 START_COLOR("color_bad");
25 colorful_output = true;
26 if (format_above_threshold != NULL)
27 selected_format = format_above_threshold;
30 for (walk = selected_format; *walk != '\0'; walk++) {
34 } else if (BEGINS_WITH(walk + 1, "1min")) {
35 outwalk += sprintf(outwalk, "%1.2f", loadavg[0]);
36 walk += strlen("1min");
38 } else if (BEGINS_WITH(walk + 1, "5min")) {
39 outwalk += sprintf(outwalk, "%1.2f", loadavg[1]);
40 walk += strlen("5min");
42 } else if (BEGINS_WITH(walk + 1, "15min")) {
43 outwalk += sprintf(outwalk, "%1.2f", loadavg[2]);
44 walk += strlen("15min");
55 OUTPUT_FULL_TEXT(buffer);
60 OUTPUT_FULL_TEXT("cant read load");
61 (void)fputs("i3status: Cannot read system load using getloadavg()\n", stderr);