summaryrefslogtreecommitdiff
path: root/src/print_load.c
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@users.noreply.github.com>2016-11-16 13:45:59 -0800
committerGitHub <noreply@github.com>2016-11-16 13:45:59 -0800
commitb91e2a4b71911bf2767865580e519c93b26390e8 (patch)
treeddd829d68420558612fcf189e214d842757fb5b8 /src/print_load.c
parent7b63102b9d646ef40edd76a3132f11ab74d5efd6 (diff)
parent562f6e383d84e16ad3ff9d9c777c89e8150a924f (diff)
Merge pull request #179 from mihaicmn/feature-threshold-format
Provide format_above_threshold/format_below_threshold options
Diffstat (limited to 'src/print_load.c')
-rw-r--r--src/print_load.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/print_load.c b/src/print_load.c
index 7ba4ae1..6da2519 100644
--- a/src/print_load.c
+++ b/src/print_load.c
@@ -6,28 +6,31 @@
#include <yajl/yajl_gen.h>
#include <yajl/yajl_version.h>
-void print_load(yajl_gen json_gen, char *buffer, const char *format, const float max_threshold) {
+void print_load(yajl_gen json_gen, char *buffer, const char *format, const char *format_above_threshold, const float 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 *selected_format = format;
const char *walk;
bool colorful_output = false;
if (getloadavg(loadavg, 3) == -1)
goto error;
- for (walk = format; *walk != '\0'; walk++) {
+ if (loadavg[0] >= max_threshold) {
+ START_COLOR("color_bad");
+ colorful_output = true;
+ if (format_above_threshold != NULL)
+ selected_format = format_above_threshold;
+ }
+
+ for (walk = selected_format; *walk != '\0'; walk++) {
if (*walk != '%') {
*(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]);
walk += strlen("1min");
@@ -42,10 +45,11 @@ void print_load(yajl_gen json_gen, char *buffer, const char *format, const float
outwalk += sprintf(outwalk, "%1.2f", loadavg[2]);
walk += strlen("15min");
}
- if (colorful_output)
- END_COLOR;
}
+ if (colorful_output)
+ END_COLOR;
+
*outwalk = '\0';
OUTPUT_FULL_TEXT(buffer);