Merge pull request #8761 from Icinga/feature/icingadb-perfdata

Icinga DB: introduce icinga:*:state#normalized_performance_data
This commit is contained in:
Alexander Aleksandrovič Klimov 2021-07-07 12:29:21 +02:00 committed by GitHub
commit bad8059969
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 5 deletions

View File

@ -651,7 +651,7 @@ Icinga sets `LC_NUMERIC=C` to enforce this locale on plugin execution.
```
The UoMs are written as-is into the [core backends](14-features.md#core-backends)
(Icinga DB, IDO, API). I.e. 12.445000ms remain 12.445000ms.
(IDO, API). I.e. 12.445000ms remain 12.445000ms.
In contrast, the [metric backends](14-features.md#metrics)
(Graphite, InfluxDB, etc.) get perfdata (including warn, crit, min, max)
@ -660,6 +660,8 @@ normalized by Icinga. E.g. 12.445000ms become 0.012445 seconds.
Some plugins change the UoM for different sizing, e.g. returning the disk usage in MB and later GB
for the same performance data label. This is to ensure that graphs always look the same.
[Icinga DB](14-features.md#core-backends-icingadb) gets both the as-is and the normalized perfdata.
What metric backends get... | ... from which perfdata UoMs (case-insensitive if possible)
----------------------------|---------------------------------------
bytes (B) | B, KB, MB, ..., YB, KiB, MiB, ..., YiB

View File

@ -176,7 +176,7 @@ Array::Ptr PluginUtility::SplitPerfdata(const String& perfdata)
return new Array(std::move(result));
}
String PluginUtility::FormatPerfdata(const Array::Ptr& perfdata)
String PluginUtility::FormatPerfdata(const Array::Ptr& perfdata, bool normalize)
{
if (!perfdata)
return "";
@ -192,10 +192,25 @@ String PluginUtility::FormatPerfdata(const Array::Ptr& perfdata)
else
first = false;
if (pdv.IsObjectType<PerfdataValue>())
if (pdv.IsObjectType<PerfdataValue>()) {
result << static_cast<PerfdataValue::Ptr>(pdv)->Format();
else
} else if (normalize) {
PerfdataValue::Ptr normalized;
try {
normalized = PerfdataValue::Parse(pdv);
} catch (const std::invalid_argument& ex) {
Log(LogDebug, "PerfdataValue") << ex.what();
}
if (normalized) {
result << normalized->Format();
} else {
result << pdv;
}
} else {
result << pdv;
}
}
return result.str();

View File

@ -31,7 +31,7 @@ public:
static std::pair<String, String> ParseCheckOutput(const String& output);
static Array::Ptr SplitPerfdata(const String& perfdata);
static String FormatPerfdata(const Array::Ptr& perfdata);
static String FormatPerfdata(const Array::Ptr& perfdata, bool normalize = false);
private:
PluginUtility();

View File

@ -2193,6 +2193,10 @@ Dictionary::Ptr IcingaDB::SerializeState(const Checkable::Ptr& checkable)
if (!perfData.IsEmpty())
attrs->Set("performance_data", perfData);
String normedPerfData = PluginUtility::FormatPerfdata(cr->GetPerformanceData(), true);
if (!normedPerfData.IsEmpty())
attrs->Set("normalized_performance_data", normedPerfData);
if (!cr->GetCommand().IsEmpty())
attrs->Set("commandline", FormatCommandLine(cr->GetCommand()));
attrs->Set("execution_time", TimestampToMilliseconds(fmax(0.0, cr->CalculateExecutionTime())));

View File

@ -143,6 +143,7 @@ add_boost_test(base
icinga_perfdata/simple
icinga_perfdata/quotes
icinga_perfdata/multiple
icinga_perfdata/normalize
icinga_perfdata/uom
icinga_perfdata/warncritminmax
icinga_perfdata/ignore_invalid_warn_crit_min_max

View File

@ -43,6 +43,15 @@ BOOST_AUTO_TEST_CASE(multiple)
BOOST_CHECK(str == "testA=123456 testB=123456");
}
BOOST_AUTO_TEST_CASE(normalize)
{
Array::Ptr pd = PluginUtility::SplitPerfdata("testA=2m;3;4;1;5 testB=2foobar");
BOOST_CHECK(pd->GetLength() == 2);
String str = PluginUtility::FormatPerfdata(pd, true);
BOOST_CHECK(str == "testA=120s;180;240;60;300 testB=2");
}
BOOST_AUTO_TEST_CASE(uom)
{
PerfdataValue::Ptr pv = PerfdataValue::Parse("test=123456B");