]> granicus.if.org Git - icinga2/commitdiff
livestatus: implement avg,min,max,std,invsum,invavg stats aggregators
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 12 Jul 2013 10:07:32 +0000 (12:07 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 12 Jul 2013 10:07:32 +0000 (12:07 +0200)
fixes #4398

16 files changed:
components/livestatus/Makefile.am
components/livestatus/avgaggregator.cpp [new file with mode: 0644]
components/livestatus/avgaggregator.h [new file with mode: 0644]
components/livestatus/invavgaggregator.cpp [new file with mode: 0644]
components/livestatus/invavgaggregator.h [new file with mode: 0644]
components/livestatus/invsumaggregator.cpp [new file with mode: 0644]
components/livestatus/invsumaggregator.h [new file with mode: 0644]
components/livestatus/livestatus.vcxproj
components/livestatus/livestatus.vcxproj.filters
components/livestatus/maxaggregator.cpp [new file with mode: 0644]
components/livestatus/maxaggregator.h [new file with mode: 0644]
components/livestatus/minaggregator.cpp [new file with mode: 0644]
components/livestatus/minaggregator.h [new file with mode: 0644]
components/livestatus/query.cpp
components/livestatus/stdaggregator.cpp [new file with mode: 0644]
components/livestatus/stdaggregator.h [new file with mode: 0644]

index aaac41339c15b0e1b314e932cf5caf84a83a1fbc..4fdd7939c8a41c79651d2702da62b01fdb57ffe8 100644 (file)
@@ -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 \
diff --git a/components/livestatus/avgaggregator.cpp b/components/livestatus/avgaggregator.cpp
new file mode 100644 (file)
index 0000000..b9eb187
--- /dev/null
@@ -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);
+}
diff --git a/components/livestatus/avgaggregator.h b/components/livestatus/avgaggregator.h
new file mode 100644 (file)
index 0000000..a27bf80
--- /dev/null
@@ -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 */
diff --git a/components/livestatus/invavgaggregator.cpp b/components/livestatus/invavgaggregator.cpp
new file mode 100644 (file)
index 0000000..d80cb6c
--- /dev/null
@@ -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);
+}
diff --git a/components/livestatus/invavgaggregator.h b/components/livestatus/invavgaggregator.h
new file mode 100644 (file)
index 0000000..cffd305
--- /dev/null
@@ -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 */
diff --git a/components/livestatus/invsumaggregator.cpp b/components/livestatus/invsumaggregator.cpp
new file mode 100644 (file)
index 0000000..c0ee0de
--- /dev/null
@@ -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;
+}
diff --git a/components/livestatus/invsumaggregator.h b/components/livestatus/invsumaggregator.h
new file mode 100644 (file)
index 0000000..b912a5b
--- /dev/null
@@ -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 */
index 96c391fdb9bf2ad949ec1d7aafa207df493e015d..e01505d227019b3d9a748bbda541e27c53b81434 100644 (file)
     <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" />
     <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" />
index f65abb3d8a15d84fc7ebe7ed83b9bb0a3b92714b..41854e11c2d3ac5a4c4de2e5ff75b5b6709afbb4 100644 (file)
     <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>
     <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>
diff --git a/components/livestatus/maxaggregator.cpp b/components/livestatus/maxaggregator.cpp
new file mode 100644 (file)
index 0000000..5157512
--- /dev/null
@@ -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;
+}
diff --git a/components/livestatus/maxaggregator.h b/components/livestatus/maxaggregator.h
new file mode 100644 (file)
index 0000000..391873b
--- /dev/null
@@ -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 */
diff --git a/components/livestatus/minaggregator.cpp b/components/livestatus/minaggregator.cpp
new file mode 100644 (file)
index 0000000..a18fda8
--- /dev/null
@@ -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;
+}
diff --git a/components/livestatus/minaggregator.h b/components/livestatus/minaggregator.h
new file mode 100644 (file)
index 0000000..d410e70
--- /dev/null
@@ -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 */
index 6fd8f47d95e57c723890ea1216dac2952f84e999..9c19b3ac14d85b0b7e1423796bc4336d8b2fe088 100644 (file)
 #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);
 
diff --git a/components/livestatus/stdaggregator.cpp b/components/livestatus/stdaggregator.cpp
new file mode 100644 (file)
index 0000000..f7ba521
--- /dev/null
@@ -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));
+}
diff --git a/components/livestatus/stdaggregator.h b/components/livestatus/stdaggregator.h
new file mode 100644 (file)
index 0000000..118823a
--- /dev/null
@@ -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 */