mirror of https://github.com/Icinga/icinga2.git
livestatus: implement avg,min,max,std,invsum,invavg stats aggregators
fixes #4398
This commit is contained in:
parent
2a3b41f948
commit
cfb3c9cf9f
|
@ -16,6 +16,8 @@ liblivestatus_la_SOURCES = \
|
|||
attributefilter.h \
|
||||
andfilter.cpp \
|
||||
andfilter.h \
|
||||
avgaggregator.cpp \
|
||||
avgaggregator.h \
|
||||
column.cpp \
|
||||
column.h \
|
||||
combinerfilter.cpp \
|
||||
|
@ -40,9 +42,17 @@ liblivestatus_la_SOURCES = \
|
|||
hostgroupstable.h \
|
||||
hoststable.cpp \
|
||||
hoststable.h \
|
||||
invavgaggregator.cpp \
|
||||
invavgaggregator.h \
|
||||
invsumaggregator.cpp \
|
||||
invsumaggregator.h \
|
||||
livestatus-type.cpp \
|
||||
logtable.cpp \
|
||||
logtable.h \
|
||||
maxaggregator.cpp \
|
||||
maxaggregator.h \
|
||||
minaggregator.cpp \
|
||||
minaggregator.h \
|
||||
negatefilter.cpp \
|
||||
negatefilter.h \
|
||||
orfilter.cpp \
|
||||
|
@ -55,6 +65,8 @@ liblivestatus_la_SOURCES = \
|
|||
servicestable.h \
|
||||
statustable.cpp \
|
||||
statustable.h \
|
||||
stdaggregator.cpp \
|
||||
stdaggregator.h \
|
||||
sumaggregator.cpp \
|
||||
sumaggregator.h \
|
||||
timeperiodstable.cpp \
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "livestatus/avgaggregator.h"
|
||||
|
||||
using namespace livestatus;
|
||||
|
||||
AvgAggregator::AvgAggregator(const String& attr)
|
||||
: m_Avg(0), m_AvgCount(0)
|
||||
{
|
||||
m_AvgAttr = attr;
|
||||
}
|
||||
|
||||
void AvgAggregator::Apply(const Table::Ptr& table, const Value& row)
|
||||
{
|
||||
Column column = table->GetColumn(m_AvgAttr);
|
||||
|
||||
Value value = column.ExtractValue(row);
|
||||
|
||||
m_Avg += value;
|
||||
m_AvgCount++;
|
||||
}
|
||||
|
||||
double AvgAggregator::GetResult(void) const
|
||||
{
|
||||
return (m_Avg / m_AvgCount);
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef AVGAGGREGATOR_H
|
||||
#define AVGAGGREGATOR_H
|
||||
|
||||
#include "livestatus/table.h"
|
||||
#include "livestatus/aggregator.h"
|
||||
|
||||
namespace livestatus
|
||||
{
|
||||
|
||||
/**
|
||||
* @ingroup livestatus
|
||||
*/
|
||||
class AvgAggregator : public Aggregator
|
||||
{
|
||||
public:
|
||||
DECLARE_PTR_TYPEDEFS(AvgAggregator);
|
||||
|
||||
AvgAggregator(const String& attr);
|
||||
|
||||
virtual void Apply(const Table::Ptr& table, const Value& row);
|
||||
virtual double GetResult(void) const;
|
||||
|
||||
private:
|
||||
double m_Avg;
|
||||
double m_AvgCount;
|
||||
String m_AvgAttr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* AVGAGGREGATOR_H */
|
|
@ -0,0 +1,43 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "livestatus/invavgaggregator.h"
|
||||
|
||||
using namespace livestatus;
|
||||
|
||||
InvAvgAggregator::InvAvgAggregator(const String& attr)
|
||||
: m_InvAvg(0), m_InvAvgCount(0)
|
||||
{
|
||||
m_InvAvgAttr = attr;
|
||||
}
|
||||
|
||||
void InvAvgAggregator::Apply(const Table::Ptr& table, const Value& row)
|
||||
{
|
||||
Column column = table->GetColumn(m_InvAvgAttr);
|
||||
|
||||
Value value = column.ExtractValue(row);
|
||||
|
||||
m_InvAvg += (1.0 / value);
|
||||
m_InvAvgCount++;
|
||||
}
|
||||
|
||||
double InvAvgAggregator::GetResult(void) const
|
||||
{
|
||||
return (m_InvAvg / m_InvAvgCount);
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef INVAVGAGGREGATOR_H
|
||||
#define INVAVGAGGREGATOR_H
|
||||
|
||||
#include "livestatus/table.h"
|
||||
#include "livestatus/aggregator.h"
|
||||
|
||||
namespace livestatus
|
||||
{
|
||||
|
||||
/**
|
||||
* @ingroup livestatus
|
||||
*/
|
||||
class InvAvgAggregator : public Aggregator
|
||||
{
|
||||
public:
|
||||
DECLARE_PTR_TYPEDEFS(InvAvgAggregator);
|
||||
|
||||
InvAvgAggregator(const String& attr);
|
||||
|
||||
virtual void Apply(const Table::Ptr& table, const Value& row);
|
||||
virtual double GetResult(void) const;
|
||||
|
||||
private:
|
||||
double m_InvAvg;
|
||||
double m_InvAvgCount;
|
||||
String m_InvAvgAttr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* INVAVGAGGREGATOR_H */
|
|
@ -0,0 +1,42 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "livestatus/invsumaggregator.h"
|
||||
|
||||
using namespace livestatus;
|
||||
|
||||
InvSumAggregator::InvSumAggregator(const String& attr)
|
||||
: m_InvSum(0)
|
||||
{
|
||||
m_InvSumAttr = attr;
|
||||
}
|
||||
|
||||
void InvSumAggregator::Apply(const Table::Ptr& table, const Value& row)
|
||||
{
|
||||
Column column = table->GetColumn(m_InvSumAttr);
|
||||
|
||||
Value value = column.ExtractValue(row);
|
||||
|
||||
m_InvSum += (1.0 / value);
|
||||
}
|
||||
|
||||
double InvSumAggregator::GetResult(void) const
|
||||
{
|
||||
return m_InvSum;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef INVSUMAGGREGATOR_H
|
||||
#define INVSUMAGGREGATOR_H
|
||||
|
||||
#include "livestatus/table.h"
|
||||
#include "livestatus/aggregator.h"
|
||||
|
||||
namespace livestatus
|
||||
{
|
||||
|
||||
/**
|
||||
* @ingroup livestatus
|
||||
*/
|
||||
class InvSumAggregator : public Aggregator
|
||||
{
|
||||
public:
|
||||
DECLARE_PTR_TYPEDEFS(InvSumAggregator);
|
||||
|
||||
InvSumAggregator(const String& attr);
|
||||
|
||||
virtual void Apply(const Table::Ptr& table, const Value& row);
|
||||
virtual double GetResult(void) const;
|
||||
|
||||
private:
|
||||
double m_InvSum;
|
||||
String m_InvSumAttr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* INVSUMAGGREGATOR_H */
|
|
@ -22,6 +22,12 @@
|
|||
<ClInclude Include="aggregator.h" />
|
||||
<ClInclude Include="countaggregator.h" />
|
||||
<ClInclude Include="sumaggregator.h" />
|
||||
<ClInclude Include="avgaggregator.h" />
|
||||
<ClInclude Include="minaggregator.h" />
|
||||
<ClInclude Include="maxaggregator.h" />
|
||||
<ClInclude Include="stdaggregator.h" />
|
||||
<ClInclude Include="invsumaggregator.h" />
|
||||
<ClInclude Include="invavgaggregator.h" />
|
||||
<ClInclude Include="andfilter.h" />
|
||||
<ClInclude Include="attributefilter.h" />
|
||||
<ClInclude Include="column.h" />
|
||||
|
@ -50,6 +56,12 @@
|
|||
<ClCompile Include="aggregator.cpp" />
|
||||
<ClCompile Include="countaggregator.cpp" />
|
||||
<ClCompile Include="sumaggregator.cpp" />
|
||||
<ClInclude Include="avgaggregator.cpp" />
|
||||
<ClInclude Include="minaggregator.cpp" />
|
||||
<ClInclude Include="maxaggregator.cpp" />
|
||||
<ClInclude Include="stdaggregator.cpp" />
|
||||
<ClInclude Include="invsumaggregator.cpp" />
|
||||
<ClInclude Include="invavgaggregator.cpp" />
|
||||
<ClCompile Include="andfilter.cpp" />
|
||||
<ClCompile Include="attributefilter.cpp" />
|
||||
<ClCompile Include="column.cpp" />
|
||||
|
|
|
@ -51,6 +51,24 @@
|
|||
<ClInclude Include="sumaggregator.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="sumaggregator.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="minaggregator.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="maxaggregator.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="stdaggregator.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="invavgaggregator.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="invsumaggregator.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="andfilter.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
|
@ -131,6 +149,24 @@
|
|||
<ClCompile Include="sumaggregator.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="avgaggregator.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="minaggregator.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="maxaggregator.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="stdaggregator.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="invavgaggregator.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="invsumaggregator.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="attributefilter.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "livestatus/maxaggregator.h"
|
||||
|
||||
using namespace livestatus;
|
||||
|
||||
MaxAggregator::MaxAggregator(const String& attr)
|
||||
: m_Max(0)
|
||||
{
|
||||
m_MaxAttr = attr;
|
||||
}
|
||||
|
||||
void MaxAggregator::Apply(const Table::Ptr& table, const Value& row)
|
||||
{
|
||||
Column column = table->GetColumn(m_MaxAttr);
|
||||
|
||||
Value value = column.ExtractValue(row);
|
||||
|
||||
if (value > m_Max)
|
||||
m_Max = value;
|
||||
}
|
||||
|
||||
double MaxAggregator::GetResult(void) const
|
||||
{
|
||||
return m_Max;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef MAXAGGREGATOR_H
|
||||
#define MAXAGGREGATOR_H
|
||||
|
||||
#include "livestatus/table.h"
|
||||
#include "livestatus/aggregator.h"
|
||||
|
||||
namespace livestatus
|
||||
{
|
||||
|
||||
/**
|
||||
* @ingroup livestatus
|
||||
*/
|
||||
class MaxAggregator : public Aggregator
|
||||
{
|
||||
public:
|
||||
DECLARE_PTR_TYPEDEFS(MaxAggregator);
|
||||
|
||||
MaxAggregator(const String& attr);
|
||||
|
||||
virtual void Apply(const Table::Ptr& table, const Value& row);
|
||||
virtual double GetResult(void) const;
|
||||
|
||||
private:
|
||||
double m_Max;
|
||||
String m_MaxAttr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* MAXAGGREGATOR_H */
|
|
@ -0,0 +1,43 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "livestatus/minaggregator.h"
|
||||
|
||||
using namespace livestatus;
|
||||
|
||||
MinAggregator::MinAggregator(const String& attr)
|
||||
: m_Min(0)
|
||||
{
|
||||
m_MinAttr = attr;
|
||||
}
|
||||
|
||||
void MinAggregator::Apply(const Table::Ptr& table, const Value& row)
|
||||
{
|
||||
Column column = table->GetColumn(m_MinAttr);
|
||||
|
||||
Value value = column.ExtractValue(row);
|
||||
|
||||
if (value < m_Min)
|
||||
m_Min = value;
|
||||
}
|
||||
|
||||
double MinAggregator::GetResult(void) const
|
||||
{
|
||||
return m_Min;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef MINAGGREGATOR_H
|
||||
#define MINAGGREGATOR_H
|
||||
|
||||
#include "livestatus/table.h"
|
||||
#include "livestatus/aggregator.h"
|
||||
|
||||
namespace livestatus
|
||||
{
|
||||
|
||||
/**
|
||||
* @ingroup livestatus
|
||||
*/
|
||||
class MinAggregator : public Aggregator
|
||||
{
|
||||
public:
|
||||
DECLARE_PTR_TYPEDEFS(MinAggregator);
|
||||
|
||||
MinAggregator(const String& attr);
|
||||
|
||||
virtual void Apply(const Table::Ptr& table, const Value& row);
|
||||
virtual double GetResult(void) const;
|
||||
|
||||
private:
|
||||
double m_Min;
|
||||
String m_MinAttr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* MINAGGREGATOR_H */
|
|
@ -20,6 +20,12 @@
|
|||
#include "livestatus/query.h"
|
||||
#include "livestatus/countaggregator.h"
|
||||
#include "livestatus/sumaggregator.h"
|
||||
#include "livestatus/minaggregator.h"
|
||||
#include "livestatus/maxaggregator.h"
|
||||
#include "livestatus/avgaggregator.h"
|
||||
#include "livestatus/stdaggregator.h"
|
||||
#include "livestatus/invsumaggregator.h"
|
||||
#include "livestatus/invavgaggregator.h"
|
||||
#include "livestatus/attributefilter.h"
|
||||
#include "livestatus/negatefilter.h"
|
||||
#include "livestatus/orfilter.h"
|
||||
|
@ -116,17 +122,17 @@ Query::Query(const std::vector<String>& lines)
|
|||
if (aggregate_arg == "sum") {
|
||||
aggregator = boost::make_shared<SumAggregator>(aggregate_attr);
|
||||
} else if (aggregate_arg == "min") {
|
||||
/* TODO */
|
||||
aggregator = boost::make_shared<MinAggregator>(aggregate_attr);
|
||||
} else if (aggregate_arg == "max") {
|
||||
/* TODO */
|
||||
aggregator = boost::make_shared<MaxAggregator>(aggregate_attr);
|
||||
} else if (aggregate_arg == "avg") {
|
||||
/* TODO */
|
||||
aggregator = boost::make_shared<AvgAggregator>(aggregate_attr);
|
||||
} else if (aggregate_arg == "std") {
|
||||
/* TODO */
|
||||
aggregator = boost::make_shared<StdAggregator>(aggregate_attr);
|
||||
} else if (aggregate_arg == "suminv") {
|
||||
/* TODO */
|
||||
aggregator = boost::make_shared<InvSumAggregator>(aggregate_attr);
|
||||
} else if (aggregate_arg == "avginv") {
|
||||
/* TODO */
|
||||
aggregator = boost::make_shared<InvAvgAggregator>(aggregate_attr);
|
||||
} else {
|
||||
filter = ParseFilter(params);
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "livestatus/stdaggregator.h"
|
||||
#include <math.h>
|
||||
|
||||
using namespace livestatus;
|
||||
|
||||
StdAggregator::StdAggregator(const String& attr)
|
||||
: m_StdSum(0), m_StdQSum(0), m_StdCount(0)
|
||||
{
|
||||
m_StdAttr = attr;
|
||||
}
|
||||
|
||||
void StdAggregator::Apply(const Table::Ptr& table, const Value& row)
|
||||
{
|
||||
Column column = table->GetColumn(m_StdAttr);
|
||||
|
||||
Value value = column.ExtractValue(row);
|
||||
|
||||
m_StdSum += value;
|
||||
m_StdQSum += pow(value, 2);
|
||||
m_StdCount++;
|
||||
}
|
||||
|
||||
double StdAggregator::GetResult(void) const
|
||||
{
|
||||
return sqrt((m_StdQSum - (1 / m_StdCount) * pow(m_StdSum, 2)) / (m_StdCount - 1));
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef STDAGGREGATOR_H
|
||||
#define STDAGGREGATOR_H
|
||||
|
||||
#include "livestatus/table.h"
|
||||
#include "livestatus/aggregator.h"
|
||||
|
||||
namespace livestatus
|
||||
{
|
||||
|
||||
/**
|
||||
* @ingroup livestatus
|
||||
*/
|
||||
class StdAggregator : public Aggregator
|
||||
{
|
||||
public:
|
||||
DECLARE_PTR_TYPEDEFS(StdAggregator);
|
||||
|
||||
StdAggregator(const String& attr);
|
||||
|
||||
virtual void Apply(const Table::Ptr& table, const Value& row);
|
||||
virtual double GetResult(void) const;
|
||||
|
||||
private:
|
||||
double m_StdSum;
|
||||
double m_StdQSum;
|
||||
double m_StdCount;
|
||||
String m_StdAttr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* STDAGGREGATOR_H */
|
Loading…
Reference in New Issue