diff options
author | Raphael Michel <webmaster@raphaelmichel.de> | 2012-12-31 18:13:36 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-02-22 14:09:58 +0100 |
commit | 6279964c6b29a549757f59c5a05c9b821a2a4bc5 (patch) | |
tree | f64a7a4704f75fe06b00fd39d009de97eac818fa /src/print_load.c | |
parent | 67c2c1a7ead6bcdcd07080e581013fa7a0b58b6f (diff) |
Add colorized output for load avg
Diffstat (limited to 'src/print_load.c')
-rw-r--r-- | src/print_load.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/print_load.c b/src/print_load.c index 5281472..4e026cc 100644 --- a/src/print_load.c +++ b/src/print_load.c @@ -6,13 +6,14 @@ #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) || defined(__DragonFly__) double loadavg[3]; const char *walk; + bool colorful_output = false; if (getloadavg(loadavg, 3) == -1) goto error; @@ -22,6 +23,10 @@ void print_load(yajl_gen json_gen, char *buffer, const char *format) { *(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]); @@ -37,6 +42,8 @@ void print_load(yajl_gen json_gen, char *buffer, const char *format) { outwalk += sprintf(outwalk, "%1.2f", loadavg[2]); walk += strlen("15min"); } + if (colorful_output) + END_COLOR; } *outwalk = '\0'; |