summaryrefslogtreecommitdiff
path: root/src/print_cpu_usage.c
diff options
context:
space:
mode:
authorMihai Coman <mihai.cmn@gmail.com>2016-11-14 22:10:19 +0200
committerMihai Coman <mihai.cmn@gmail.com>2016-11-15 01:09:05 +0200
commit9375959b68d7c80dbad53a6eb0df1035bb33c6ce (patch)
tree3dfa11dde08cf6ef11fdcc7d803aa576dd09958d /src/print_cpu_usage.c
parentb0af4e4c8543d8cdfd8bc7cd68b760d9d66e927c (diff)
Add 'format_below_threshold' option for 'disk' module
Add 'format_above_threshold' option for 'cpu_temperature' module Add 'format_above_threshold' option for 'cpu_usage' module Add 'format_above_threshold' option for 'load' module
Diffstat (limited to 'src/print_cpu_usage.c')
-rw-r--r--src/print_cpu_usage.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/print_cpu_usage.c b/src/print_cpu_usage.c
index 1753cf5..45a5ef2 100644
--- a/src/print_cpu_usage.c
+++ b/src/print_cpu_usage.c
@@ -41,7 +41,8 @@ static int prev_idle = 0;
* percentage.
*
*/
-void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format, const float max_threshold, const float degraded_threshold) {
+void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format, const char *format_above_threshold, const char *format_above_degraded_threshold, const float max_threshold, const float degraded_threshold) {
+ const char *selected_format = format;
const char *walk;
char *outwalk = buffer;
int curr_user = 0, curr_nice = 0, curr_system = 0, curr_idle = 0, curr_total;
@@ -96,29 +97,34 @@ void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format, const
#else
goto error;
#endif
- for (walk = format; *walk != '\0'; walk++) {
+
+ if (diff_usage >= max_threshold) {
+ START_COLOR("color_bad");
+ colorful_output = true;
+ if (format_above_threshold != NULL)
+ selected_format = format_above_threshold;
+ } else if (diff_usage >= degraded_threshold) {
+ START_COLOR("color_degraded");
+ colorful_output = true;
+ if (format_above_degraded_threshold != NULL)
+ selected_format = format_above_degraded_threshold;
+ }
+
+ for (walk = selected_format; *walk != '\0'; walk++) {
if (*walk != '%') {
*(outwalk++) = *walk;
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;
}
+ if (colorful_output)
+ END_COLOR;
+
OUTPUT_FULL_TEXT(buffer);
return;
error: