summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-12-23 20:56:19 +0100
committerBenBE <BenBE@geshi.org>2020-12-26 13:32:29 +0100
commit2c06566405e8708c6c4813e79c74bb64ea61661c (patch)
treef25713f5ab32b5562a756476c2dd3bb1e9d9510e
parentd609c04fe4fa38c35465a152d7dccdf8f64e7a0d (diff)
LoadMeter: dynamically adjust color and total of bar
Change the color and total based on the actual 1min load value: < 1 : green and total of 1.0 < cpu-count : yellow and total of cpu-count else : red and total of 2*cpu-count Closes: #32
-rw-r--r--LoadAverageMeter.c42
-rw-r--r--Meter.c4
-rw-r--r--Meter.h1
3 files changed, 44 insertions, 3 deletions
diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c
index 248d65cd..0c7b8339 100644
--- a/LoadAverageMeter.c
+++ b/LoadAverageMeter.c
@@ -24,8 +24,36 @@ static const int LoadMeter_attributes[] = {
LOAD
};
+static const int OK_attributes[] = {
+ METER_VALUE_OK
+};
+
+static const int Medium_attributes[] = {
+ METER_VALUE_WARN
+};
+
+static const int High_attributes[] = {
+ METER_VALUE_ERROR
+};
+
static void LoadAverageMeter_updateValues(Meter* this, char* buffer, size_t size) {
Platform_getLoadAverage(&this->values[0], &this->values[1], &this->values[2]);
+
+ // only show bar for 1min value
+ this->curItems = 1;
+
+ // change bar color and total based on value
+ if (this->values[0] < 1.0) {
+ this->curAttributes = OK_attributes;
+ this->total = 1.0;
+ } else if (this->values[0] < this->pl->cpuCount) {
+ this->curAttributes = Medium_attributes;
+ this->total = this->pl->cpuCount;
+ } else {
+ this->curAttributes = High_attributes;
+ this->total = 2 * this->pl->cpuCount;
+ }
+
xSnprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]);
}
@@ -43,9 +71,19 @@ static void LoadAverageMeter_display(const Object* cast, RichString* out) {
static void LoadMeter_updateValues(Meter* this, char* buffer, size_t size) {
double five, fifteen;
Platform_getLoadAverage(&this->values[0], &five, &fifteen);
- if (this->values[0] > this->total) {
- this->total = this->values[0];
+
+ // change bar color and total based on value
+ if (this->values[0] < 1.0) {
+ this->curAttributes = OK_attributes;
+ this->total = 1.0;
+ } else if (this->values[0] < this->pl->cpuCount) {
+ this->curAttributes = Medium_attributes;
+ this->total = this->pl->cpuCount;
+ } else {
+ this->curAttributes = High_attributes;
+ this->total = 2 * this->pl->cpuCount;
}
+
xSnprintf(buffer, size, "%.2f", this->values[0]);
}
diff --git a/Meter.c b/Meter.c
index 3b3b438d..ad5c1575 100644
--- a/Meter.c
+++ b/Meter.c
@@ -39,6 +39,7 @@ Meter* Meter_new(const struct ProcessList_* pl, int param, const MeterClass* typ
this->param = param;
this->pl = pl;
this->curItems = type->maxItems;
+ this->curAttributes = NULL;
this->values = type->maxItems ? xCalloc(type->maxItems, sizeof(double)) : NULL;
this->total = type->total;
this->caption = xStrdup(type->caption);
@@ -252,7 +253,8 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
// ...then print the buffer.
offset = 0;
for (uint8_t i = 0; i < this->curItems; i++) {
- RichString_setAttrn(&bar, CRT_colors[Meter_attributes(this)[i]], startPos + offset, startPos + offset + blockSizes[i] - 1);
+ int attr = this->curAttributes ? this->curAttributes[i] : Meter_attributes(this)[i];
+ RichString_setAttrn(&bar, CRT_colors[attr], startPos + offset, startPos + offset + blockSizes[i] - 1);
RichString_printoffnVal(bar, y, x + offset, startPos + offset, MINIMUM(blockSizes[i], w - offset));
offset += blockSizes[i];
offset = CLAMP(offset, 0, w);
diff --git a/Meter.h b/Meter.h
index cb054057..2a78fd10 100644
--- a/Meter.h
+++ b/Meter.h
@@ -100,6 +100,7 @@ struct Meter_ {
int h;
const ProcessList* pl;
uint8_t curItems;
+ const int* curAttributes;
double* values;
double total;
void* meterData;

© 2014-2024 Faster IT GmbH | imprint | privacy policy