Module: check_mk
Branch: master
Commit: 39ea41ac55570b399e8afc139886f219324e30b6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=39ea41ac55570b…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sat Nov 5 16:40:36 2011 +0100
Livestatus: New aggregation functions suminv and avginv
---
ChangeLog | 1 +
livestatus/src/DoubleAggregator.cc | 7 +++++++
livestatus/src/DoubleColumn.cc | 7 +++++++
livestatus/src/DoubleColumn.h | 1 +
livestatus/src/IntAggregator.cc | 13 +++++++++++++
livestatus/src/PerfdataAggregator.cc | 10 +++++++++-
livestatus/src/Query.cc | 4 ++++
livestatus/src/StatsColumn.h | 14 ++++++++------
8 files changed, 50 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9ad2a94..95438b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -31,6 +31,7 @@
Livestatus:
* New columns num_hosts and num_services in status table
+ * New aggregation functions suminv and avginv (see Documentation)
1.1.12p1:
diff --git a/livestatus/src/DoubleAggregator.cc b/livestatus/src/DoubleAggregator.cc
index 4b51947..7ee74b5 100644
--- a/livestatus/src/DoubleAggregator.cc
+++ b/livestatus/src/DoubleAggregator.cc
@@ -60,6 +60,11 @@ void DoubleAggregator::consume(void *data, Query *)
_aggr += value;
_sumq += value * value;
break;
+
+ case STATS_OP_SUMINV:
+ case STATS_OP_AVGINV:
+ _aggr += 1.0 / value;
+ break;
}
}
@@ -70,10 +75,12 @@ void DoubleAggregator::output(Query *q)
case STATS_OP_SUM:
case STATS_OP_MIN:
case STATS_OP_MAX:
+ case STATS_OP_SUMINV:
q->outputDouble(_aggr);
break;
case STATS_OP_AVG:
+ case STATS_OP_AVGINV:
if (_count == 0)
q->outputDouble(0.0);
else
diff --git a/livestatus/src/DoubleColumn.cc b/livestatus/src/DoubleColumn.cc
index 21e9590..02adadd 100644
--- a/livestatus/src/DoubleColumn.cc
+++ b/livestatus/src/DoubleColumn.cc
@@ -35,3 +35,10 @@ Filter *DoubleColumn::createFilter(int operator_id, char *value)
{
return new DoubleColumnFilter(this, operator_id, value);
}
+
+string DoubleColumn::valueAsString(void *data, Query *query)
+{
+ char buf[64];
+ snprintf(buf, sizeof(buf), "%.10e", getValue(data));
+ return buf;
+}
diff --git a/livestatus/src/DoubleColumn.h b/livestatus/src/DoubleColumn.h
index 55bd934..3c66df8 100644
--- a/livestatus/src/DoubleColumn.h
+++ b/livestatus/src/DoubleColumn.h
@@ -37,6 +37,7 @@ public:
virtual double getValue(void *data) = 0;
void output(void *, Query *);
int type() { return COLTYPE_DOUBLE; }
+ string valueAsString(void *data, Query *);
Filter *createFilter(int operator_id, char *value);
};
diff --git a/livestatus/src/IntAggregator.cc b/livestatus/src/IntAggregator.cc
index e9f82a3..2fbdbb8 100644
--- a/livestatus/src/IntAggregator.cc
+++ b/livestatus/src/IntAggregator.cc
@@ -37,6 +37,11 @@ void IntAggregator::consume(void *data, Query *query)
case STATS_OP_AVG:
_aggr += value; break;
+ case STATS_OP_SUMINV:
+ case STATS_OP_AVGINV:
+ _sumq += 1.0 / (double)value;
+ break;
+
case STATS_OP_MIN:
if (_count == 1)
_aggr = value;
@@ -68,10 +73,18 @@ void IntAggregator::output(Query *q)
q->outputInteger64(_aggr);
break;
+ case STATS_OP_SUMINV:
+ q->outputInteger64(_sumq);
+ break;
+
case STATS_OP_AVG:
q->outputDouble(double(_aggr) / _count);
break;
+ case STATS_OP_AVGINV:
+ q->outputInteger64(_sumq / _count);
+ break;
+
case STATS_OP_STD:
if (_count <= 1)
q->outputDouble(0.0);
diff --git a/livestatus/src/PerfdataAggregator.cc b/livestatus/src/PerfdataAggregator.cc
index 837ecb9..a0c67c6 100644
--- a/livestatus/src/PerfdataAggregator.cc
+++ b/livestatus/src/PerfdataAggregator.cc
@@ -76,7 +76,13 @@ void PerfdataAggregator::consumeVariable(const char *varname, double
value)
switch (_operation) {
case STATS_OP_SUM:
case STATS_OP_AVG:
- it->second._aggr += value; break;
+ it->second._aggr += value;
+ break;
+
+ case STATS_OP_SUMINV:
+ case STATS_OP_AVGINV:
+ it->second._aggr += 1.0 / value;
+ break;
case STATS_OP_MIN:
if (value < it->second._aggr)
@@ -110,10 +116,12 @@ void PerfdataAggregator::output(Query *q)
case STATS_OP_SUM:
case STATS_OP_MIN:
case STATS_OP_MAX:
+ case STATS_OP_SUMINV:
value = it->second._aggr;
break;
case STATS_OP_AVG:
+ case STATS_OP_AVGINV:
if (it->second._count == 0)
value = 0.00;
else
diff --git a/livestatus/src/Query.cc b/livestatus/src/Query.cc
index d1142d0..a80725c 100644
--- a/livestatus/src/Query.cc
+++ b/livestatus/src/Query.cc
@@ -377,6 +377,10 @@ void Query::parseStatsLine(char *line)
operation = STATS_OP_AVG;
else if (!strcmp(col_or_op, "std"))
operation = STATS_OP_STD;
+ else if (!strcmp(col_or_op, "suminv"))
+ operation = STATS_OP_SUMINV;
+ else if (!strcmp(col_or_op, "avginv"))
+ operation = STATS_OP_AVGINV;
char *column_name;
if (operation == STATS_OP_COUNT)
diff --git a/livestatus/src/StatsColumn.h b/livestatus/src/StatsColumn.h
index e4e95b7..526b313 100644
--- a/livestatus/src/StatsColumn.h
+++ b/livestatus/src/StatsColumn.h
@@ -25,12 +25,14 @@
#ifndef StatsColumn_h
#define StatsColumn_h
-#define STATS_OP_COUNT 0
-#define STATS_OP_SUM 1
-#define STATS_OP_MIN 2
-#define STATS_OP_MAX 3
-#define STATS_OP_AVG 4
-#define STATS_OP_STD 5
+#define STATS_OP_COUNT 0
+#define STATS_OP_SUM 1
+#define STATS_OP_MIN 2
+#define STATS_OP_MAX 3
+#define STATS_OP_AVG 4
+#define STATS_OP_STD 5
+#define STATS_OP_SUMINV 6
+#define STATS_OP_AVGINV 7
class Aggregator;
class Column;