feat(memory): Add memory used/free ramp

Closes #1037
This commit is contained in:
patrick96 2018-02-19 18:04:55 +01:00 committed by NBonaparte
parent 0fd614b0a9
commit 2f62a6fbad
2 changed files with 16 additions and 1 deletions

View File

@ -19,12 +19,16 @@ namespace modules {
static constexpr const char* TAG_LABEL{"<label>"};
static constexpr const char* TAG_BAR_USED{"<bar-used>"};
static constexpr const char* TAG_BAR_FREE{"<bar-free>"};
static constexpr const char* TAG_RAMP_USED{"<ramp-used>"};
static constexpr const char* TAG_RAMP_FREE{"<ramp-free>"};
label_t m_label;
progressbar_t m_bar_memused;
progressbar_t m_bar_memfree;
int m_perc_memused{0};
int m_perc_memfree{0};
ramp_t m_ramp_memused;
ramp_t m_ramp_memfree;
};
}

View File

@ -4,6 +4,7 @@
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp"
#include "modules/memory.hpp"
#include "utils/math.hpp"
@ -17,7 +18,7 @@ namespace modules {
memory_module::memory_module(const bar_settings& bar, string name_) : timer_module<memory_module>(bar, move(name_)) {
m_interval = m_conf.get<decltype(m_interval)>(name(), "interval", 1s);
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR_USED, TAG_BAR_FREE});
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR_USED, TAG_BAR_FREE, TAG_RAMP_USED, TAG_RAMP_FREE});
if (m_formatter->has(TAG_BAR_USED)) {
m_bar_memused = load_progressbar(m_bar, m_conf, name(), TAG_BAR_USED);
@ -25,6 +26,12 @@ namespace modules {
if (m_formatter->has(TAG_BAR_FREE)) {
m_bar_memfree = load_progressbar(m_bar, m_conf, name(), TAG_BAR_FREE);
}
if(m_formatter->has(TAG_RAMP_USED)) {
m_ramp_memused = load_ramp(m_conf, name(), TAG_RAMP_USED);
}
if(m_formatter->has(TAG_RAMP_FREE)) {
m_ramp_memfree = load_ramp(m_conf, name(), TAG_RAMP_FREE);
}
if (m_formatter->has(TAG_LABEL)) {
m_label = load_optional_label(m_conf, name(), TAG_LABEL, "%percentage_used%%");
}
@ -91,6 +98,10 @@ namespace modules {
builder->node(m_bar_memfree->output(m_perc_memfree));
} else if (tag == TAG_LABEL) {
builder->node(m_label);
} else if (tag == TAG_RAMP_FREE) {
builder->node(m_ramp_memfree->get_by_percentage(m_perc_memfree));
} else if (tag == TAG_RAMP_USED) {
builder->node(m_ramp_memused->get_by_percentage(m_perc_memused));
} else {
return false;
}