1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #include "livestatus/avgaggregator.hpp"
5 using namespace icinga;
7 AvgAggregator::AvgAggregator(String attr)
8 : m_AvgAttr(std::move(attr))
11 AvgAggregatorState *AvgAggregator::EnsureState(AggregatorState **state)
14 *state = new AvgAggregatorState();
16 return static_cast<AvgAggregatorState *>(*state);
19 void AvgAggregator::Apply(const Table::Ptr& table, const Value& row, AggregatorState **state)
21 Column column = table->GetColumn(m_AvgAttr);
23 Value value = column.ExtractValue(row);
25 AvgAggregatorState *pstate = EnsureState(state);
31 double AvgAggregator::GetResultAndFreeState(AggregatorState *state) const
33 AvgAggregatorState *pstate = EnsureState(&state);
34 double result = pstate->Avg / pstate->AvgCount;