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 char *format_above_threshold, 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__)
15 const char *selected_format = format;
17 bool colorful_output = false;
19 if (getloadavg(loadavg, 3) == -1)
22 if (loadavg[0] >= max_threshold) {
23 START_COLOR("color_bad");
24 colorful_output = true;
25 if (format_above_threshold != NULL)
26 selected_format = format_above_threshold;
29 for (walk = selected_format; *walk != '\0'; walk++) {
33 } else if (BEGINS_WITH(walk + 1, "1min")) {
34 outwalk += sprintf(outwalk, "%1.2f", loadavg[0]);
35 walk += strlen("1min");
37 } else if (BEGINS_WITH(walk + 1, "5min")) {
38 outwalk += sprintf(outwalk, "%1.2f", loadavg[1]);
39 walk += strlen("5min");
41 } else if (BEGINS_WITH(walk + 1, "15min")) {
42 outwalk += sprintf(outwalk, "%1.2f", loadavg[2]);
43 walk += strlen("15min");
54 OUTPUT_FULL_TEXT(buffer);
59 OUTPUT_FULL_TEXT("cant read load");
60 (void)fputs("i3status: Cannot read system load using getloadavg()\n", stderr);