#include <yajl/yajl_gen.h>
#include <yajl/yajl_version.h>
-void print_load(yajl_gen json_gen, char *buffer, const char *format) {
+void print_load(yajl_gen json_gen, char *buffer, const char *format, const int max_threshold) {
char *outwalk = buffer;
/* Get load */
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(linux) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(sun)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(linux) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(sun) || defined(__DragonFly__)
double loadavg[3];
const char *walk;
+ bool colorful_output = false;
if (getloadavg(loadavg, 3) == -1)
goto error;
*(outwalk++) = *walk;
continue;
}
+ if (loadavg[0] >= max_threshold) {
+ START_COLOR("color_bad");
+ colorful_output = true;
+ }
if (BEGINS_WITH(walk+1, "1min")) {
outwalk += sprintf(outwalk, "%1.2f", loadavg[0]);
outwalk += sprintf(outwalk, "%1.2f", loadavg[2]);
walk += strlen("15min");
}
+ if (colorful_output)
+ END_COLOR;
}
*outwalk = '\0';