diff options
author | Michael Stapelberg <stapelberg@users.noreply.github.com> | 2016-07-30 19:23:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-30 19:23:20 +0200 |
commit | 8e852fa94554f4caa162256e5f6ce2413027100b (patch) | |
tree | 373a3fbf687ff7fb8d5d0ee405b46dd8736d499f /src | |
parent | dd0f6bf4b76e6431b3d51abceef42fd60bfb16b5 (diff) | |
parent | dbc0f9bd8c3561eb7b9c2d7c13518cb825695d23 (diff) |
Merge pull request #139 from Gjum/wb-colored-cpu-usage
Add CPU usage color thresholds
Diffstat (limited to 'src')
-rw-r--r-- | src/print_cpu_usage.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/print_cpu_usage.c b/src/print_cpu_usage.c index adf2d04..1753cf5 100644 --- a/src/print_cpu_usage.c +++ b/src/print_cpu_usage.c @@ -41,11 +41,12 @@ static int prev_idle = 0; * percentage. * */ -void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format) { +void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format, const float max_threshold, const float degraded_threshold) { const char *walk; char *outwalk = buffer; int curr_user = 0, curr_nice = 0, curr_system = 0, curr_idle = 0, curr_total; int diff_idle, diff_total, diff_usage; + bool colorful_output = false; #if defined(LINUX) static char statpath[512]; @@ -101,10 +102,21 @@ void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format) { continue; } + if (diff_usage >= max_threshold) { + START_COLOR("color_bad"); + colorful_output = true; + } else if (diff_usage >= degraded_threshold) { + START_COLOR("color_degraded"); + colorful_output = true; + } + if (BEGINS_WITH(walk + 1, "usage")) { outwalk += sprintf(outwalk, "%02d%s", diff_usage, pct_mark); walk += strlen("usage"); } + + if (colorful_output) + END_COLOR; } OUTPUT_FULL_TEXT(buffer); |