Remove IcingaStatusWriter feature

fixes #10140
This commit is contained in:
Michael Friedrich 2015-11-26 19:30:40 +01:00
parent 3d4e48aa12
commit 9289971829
8 changed files with 3 additions and 302 deletions

View File

@ -658,31 +658,6 @@ Configuration Attributes:
enable_perfdata |**Optional.** Whether performance data processing is globally enabled. Defaults to true. enable_perfdata |**Optional.** Whether performance data processing is globally enabled. Defaults to true.
vars |**Optional.** A dictionary containing custom attributes that are available globally. vars |**Optional.** A dictionary containing custom attributes that are available globally.
## <a id="objecttype-icingastatuswriter"></a> IcingaStatusWriter
> **Note**
>
> This feature was deprecated in 2.4 and will be removed in future releases.
The IcingaStatusWriter feature periodically dumps the current status
and performance data from Icinga 2 and all registered features into
a defined JSON file.
Example:
object IcingaStatusWriter "status" {
status_path = LocalStateDir + "/cache/icinga2/status.json"
update_interval = 15s
}
Configuration Attributes:
Name |Description
--------------------------|--------------------------
status\_path |**Optional.** Path to cluster status file. Defaults to LocalStateDir + "/cache/icinga2/status.json"
update\_interval |**Optional.** The interval in which the status files are updated. Defaults to 15 seconds.
## <a id="objecttype-idomysqlconnection"></a> IdoMySqlConnection ## <a id="objecttype-idomysqlconnection"></a> IdoMySqlConnection
IDO database adapter for MySQL. IDO database adapter for MySQL.

View File

@ -1,10 +0,0 @@
/**
* The IcingaStatusWriter feature periodically dumps the
* current status and performance data from Icinga 2 and
* all registered features into a defined JSON file.
*/
/* NOTE: This feature was deprecated in 2.4 and will be removed in future releases. */
object IcingaStatusWriter "icinga-status" { }

View File

@ -27,7 +27,6 @@ mkclass_target(hostgroup.ti hostgroup.tcpp hostgroup.thpp)
mkclass_target(host.ti host.tcpp host.thpp) mkclass_target(host.ti host.tcpp host.thpp)
mkclass_target(icingaapplication.ti icingaapplication.tcpp icingaapplication.thpp) mkclass_target(icingaapplication.ti icingaapplication.tcpp icingaapplication.thpp)
mkclass_target(customvarobject.ti customvarobject.tcpp customvarobject.thpp) mkclass_target(customvarobject.ti customvarobject.tcpp customvarobject.thpp)
mkclass_target(icingastatuswriter.ti icingastatuswriter.tcpp icingastatuswriter.thpp)
mkclass_target(notificationcommand.ti notificationcommand.tcpp notificationcommand.thpp) mkclass_target(notificationcommand.ti notificationcommand.tcpp notificationcommand.thpp)
mkclass_target(notification.ti notification.tcpp notification.thpp) mkclass_target(notification.ti notification.tcpp notification.thpp)
mkclass_target(perfdatavalue.ti perfdatavalue.tcpp perfdatavalue.thpp) mkclass_target(perfdatavalue.ti perfdatavalue.tcpp perfdatavalue.thpp)
@ -44,7 +43,7 @@ set(icinga_SOURCES
cib.cpp clusterevents.cpp command.cpp command.thpp comment.cpp comment.thpp compatutility.cpp dependency.cpp dependency.thpp cib.cpp clusterevents.cpp command.cpp command.thpp comment.cpp comment.thpp compatutility.cpp dependency.cpp dependency.thpp
dependency-apply.cpp downtime.cpp downtime.thpp eventcommand.cpp eventcommand.thpp dependency-apply.cpp downtime.cpp downtime.thpp eventcommand.cpp eventcommand.thpp
externalcommandprocessor.cpp host.cpp host.thpp hostgroup.cpp hostgroup.thpp icingaapplication.cpp icingaapplication.thpp externalcommandprocessor.cpp host.cpp host.thpp hostgroup.cpp hostgroup.thpp icingaapplication.cpp icingaapplication.thpp
customvarobject.cpp customvarobject.thpp icingastatuswriter.cpp icingastatuswriter.thpp customvarobject.cpp customvarobject.thpp
legacytimeperiod.cpp macroprocessor.cpp notificationcommand.cpp notificationcommand.thpp notification.cpp notification.thpp legacytimeperiod.cpp macroprocessor.cpp notificationcommand.cpp notificationcommand.thpp notification.cpp notification.thpp
notification-apply.cpp objectutils.cpp perfdatavalue.cpp perfdatavalue.thpp pluginutility.cpp scheduleddowntime.cpp scheduleddowntime.thpp notification-apply.cpp objectutils.cpp perfdatavalue.cpp perfdatavalue.thpp pluginutility.cpp scheduleddowntime.cpp scheduleddowntime.thpp
scheduleddowntime-apply.cpp service-apply.cpp checkable-check.cpp checkable-comment.cpp scheduleddowntime-apply.cpp service-apply.cpp checkable-check.cpp checkable-comment.cpp

View File

@ -1,174 +0,0 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012-2015 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 "icinga/icingastatuswriter.hpp"
#include "icinga/icingastatuswriter.tcpp"
#include "icinga/cib.hpp"
#include "base/configtype.hpp"
#include "base/logger.hpp"
#include "base/exception.hpp"
#include "base/application.hpp"
#include "base/statsfunction.hpp"
#include "base/json.hpp"
#include <boost/foreach.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <fstream>
using namespace icinga;
REGISTER_TYPE(IcingaStatusWriter);
REGISTER_STATSFUNCTION(IcingaStatusWriter, &IcingaStatusWriter::StatsFunc);
void IcingaStatusWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
{
Dictionary::Ptr nodes = new Dictionary();
BOOST_FOREACH(const IcingaStatusWriter::Ptr& icingastatuswriter, ConfigType::GetObjectsByType<IcingaStatusWriter>()) {
nodes->Set(icingastatuswriter->GetName(), 1); //add more stats
}
status->Set("icingastatuswriter", nodes);
}
/**
* Hint: The reason why we're using "\n" rather than std::endl is because
* std::endl also _flushes_ the output stream which severely degrades
* performance (see http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch25s02.html).
*/
/**
* Starts the component.
*/
void IcingaStatusWriter::Start(bool runtimeCreated)
{
ObjectImpl<IcingaStatusWriter>::Start(runtimeCreated);
/* TODO: remove in versions > 2.4 */
Log(LogWarning, "IcingaStatusWriter", "This feature was deprecated in 2.4 and will be removed in future Icinga 2 releases.");
m_StatusTimer = new Timer();
m_StatusTimer->SetInterval(GetUpdateInterval());
m_StatusTimer->OnTimerExpired.connect(boost::bind(&IcingaStatusWriter::StatusTimerHandler, this));
m_StatusTimer->Start();
m_StatusTimer->Reschedule(0);
}
Dictionary::Ptr IcingaStatusWriter::GetStatusData(void)
{
Dictionary::Ptr bag = new Dictionary();
/* features */
std::pair<Dictionary::Ptr, Array::Ptr> stats = CIB::GetFeatureStats();
bag->Set("feature_status", stats.first);
bag->Set("feature_perfdata", stats.second);
/* icinga stats */
Dictionary::Ptr icinga_stats = new Dictionary();
double interval = Utility::GetTime() - Application::GetStartTime();
if (interval > 60)
interval = 60;
icinga_stats->Set("active_host_checks", CIB::GetActiveHostChecksStatistics(interval) / interval);
icinga_stats->Set("passive_host_checks", CIB::GetPassiveHostChecksStatistics(interval) / interval);
icinga_stats->Set("active_host_checks_1min", CIB::GetActiveHostChecksStatistics(60));
icinga_stats->Set("passive_host_checks_1min", CIB::GetPassiveHostChecksStatistics(60));
icinga_stats->Set("active_host_checks_5min", CIB::GetActiveHostChecksStatistics(60 * 5));
icinga_stats->Set("passive_host_checks_5min", CIB::GetPassiveHostChecksStatistics(60 * 5));
icinga_stats->Set("active_host_checks_15min", CIB::GetActiveHostChecksStatistics(60 * 15));
icinga_stats->Set("passive_host_checks_15min", CIB::GetPassiveHostChecksStatistics(60 * 15));
icinga_stats->Set("active_service_checks", CIB::GetActiveServiceChecksStatistics(interval) / interval);
icinga_stats->Set("passive_service_checks", CIB::GetPassiveServiceChecksStatistics(interval) / interval);
icinga_stats->Set("active_service_checks_1min", CIB::GetActiveServiceChecksStatistics(60));
icinga_stats->Set("passive_service_checks_1min", CIB::GetPassiveServiceChecksStatistics(60));
icinga_stats->Set("active_service_checks_5min", CIB::GetActiveServiceChecksStatistics(60 * 5));
icinga_stats->Set("passive_service_checks_5min", CIB::GetPassiveServiceChecksStatistics(60 * 5));
icinga_stats->Set("active_service_checks_15min", CIB::GetActiveServiceChecksStatistics(60 * 15));
icinga_stats->Set("passive_service_checks_15min", CIB::GetPassiveServiceChecksStatistics(60 * 15));
CheckableCheckStatistics scs = CIB::CalculateServiceCheckStats();
icinga_stats->Set("min_latency", scs.min_latency);
icinga_stats->Set("max_latency", scs.max_latency);
icinga_stats->Set("avg_latency", scs.avg_latency);
icinga_stats->Set("min_execution_time", scs.min_latency);
icinga_stats->Set("max_execution_time", scs.max_latency);
icinga_stats->Set("avg_execution_time", scs.avg_execution_time);
ServiceStatistics ss = CIB::CalculateServiceStats();
icinga_stats->Set("num_services_ok", ss.services_ok);
icinga_stats->Set("num_services_warning", ss.services_warning);
icinga_stats->Set("num_services_critical", ss.services_critical);
icinga_stats->Set("num_services_unknown", ss.services_unknown);
icinga_stats->Set("num_services_pending", ss.services_pending);
icinga_stats->Set("num_services_unreachable", ss.services_unreachable);
icinga_stats->Set("num_services_flapping", ss.services_flapping);
icinga_stats->Set("num_services_in_downtime", ss.services_in_downtime);
icinga_stats->Set("num_services_acknowledged", ss.services_acknowledged);
HostStatistics hs = CIB::CalculateHostStats();
icinga_stats->Set("num_hosts_up", hs.hosts_up);
icinga_stats->Set("num_hosts_down", hs.hosts_down);
icinga_stats->Set("num_hosts_unreachable", hs.hosts_unreachable);
icinga_stats->Set("num_hosts_flapping", hs.hosts_flapping);
icinga_stats->Set("num_hosts_in_downtime", hs.hosts_in_downtime);
icinga_stats->Set("num_hosts_acknowledged", hs.hosts_acknowledged);
bag->Set("icinga_status", icinga_stats);
return bag;
}
void IcingaStatusWriter::StatusTimerHandler(void)
{
Log(LogNotice, "IcingaStatusWriter", "Writing status.json file");
String statuspath = GetStatusPath();
String statuspathtmp = statuspath + ".tmp"; /* XXX make this a global definition */
std::ofstream statusfp;
statusfp.open(statuspathtmp.CStr(), std::ofstream::out | std::ofstream::trunc);
statusfp << std::fixed;
statusfp << JsonEncode(GetStatusData());
statusfp.close();
#ifdef _WIN32
_unlink(statuspath.CStr());
#endif /* _WIN32 */
if (rename(statuspathtmp.CStr(), statuspath.CStr()) < 0) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("rename")
<< boost::errinfo_errno(errno)
<< boost::errinfo_file_name(statuspathtmp));
}
Log(LogNotice, "IcingaStatusWriter", "Finished writing status.json file");
}

View File

@ -1,51 +0,0 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012-2015 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 ICINGASTATUSWRITER_H
#define ICINGASTATUSWRITER_H
#include "icinga/icingastatuswriter.thpp"
#include "base/timer.hpp"
namespace icinga
{
/**
* @ingroup compat
*/
class IcingaStatusWriter : public ObjectImpl<IcingaStatusWriter>
{
public:
DECLARE_OBJECT(IcingaStatusWriter);
DECLARE_OBJECTNAME(IcingaStatusWriter);
static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
static Dictionary::Ptr GetStatusData(void);
protected:
virtual void Start(bool runtimeCreated) override;
private:
Timer::Ptr m_StatusTimer;
void StatusTimerHandler(void);
};
}
#endif /* ICINGASTATUSWRITER_H */

View File

@ -1,38 +0,0 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012-2015 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 "icinga/customvarobject.hpp"
#include "base/application.hpp"
library icinga;
namespace icinga
{
class IcingaStatusWriter : ConfigObject
{
[config] String status_path {
default {{{ return Application::GetLocalStateDir() + "/cache/icinga2/status.json"; }}}
};
[config] double update_interval {
default {{{ return 15; }}}
};
};
}

View File

@ -10,7 +10,7 @@ icolor brightgreen "object[ \t]+(timeperiod|scheduleddowntime|dependency|perfd
icolor brightgreen "object[ \t]+(graphitewriter|idomysqlconnection|idomysqlconnection)" icolor brightgreen "object[ \t]+(graphitewriter|idomysqlconnection|idomysqlconnection)"
icolor brightgreen "object[ \t]+(livestatuslistener|statusdatawriter|externalcommandlistener)" icolor brightgreen "object[ \t]+(livestatuslistener|statusdatawriter|externalcommandlistener)"
icolor brightgreen "object[ \t]+(compatlogger|checkresultreader|checkcomponent|notificationcomponent)" icolor brightgreen "object[ \t]+(compatlogger|checkresultreader|checkcomponent|notificationcomponent)"
icolor brightgreen "object[ \t]+(filelogger|sysloglogger|icingastatuswriter|apilistener|endpoint|zone)" icolor brightgreen "object[ \t]+(filelogger|sysloglogger|apilistener|endpoint|zone)"
## apply def ## apply def
icolor brightgreen "apply[ \t]+(Service|Dependency|Notification|ScheduledDowntime)" icolor brightgreen "apply[ \t]+(Service|Dependency|Notification|ScheduledDowntime)"

View File

@ -51,7 +51,7 @@ syn match icinga2Objdef "object[ \t]\+\(timeperiod\|scheduleddowntime\|depende
syn match icinga2ObjDef "object[ \t]\+\(graphitewriter\|idomysqlconnection\|idomysqlconnection\)" syn match icinga2ObjDef "object[ \t]\+\(graphitewriter\|idomysqlconnection\|idomysqlconnection\)"
syn match icinga2ObjDef "object[ \t]\+\(livestatuslistener\|statusdatawriter\|externalcommandlistener\)" syn match icinga2ObjDef "object[ \t]\+\(livestatuslistener\|statusdatawriter\|externalcommandlistener\)"
syn match icinga2ObjDef "object[ \t]\+\(compatlogger\|checkresultreader\|checkcomponent\|notificationcomponent\)" syn match icinga2ObjDef "object[ \t]\+\(compatlogger\|checkresultreader\|checkcomponent\|notificationcomponent\)"
syn match icinga2ObjDef "object[ \t]\+\(filelogger\|sysloglogger\|icingastatuswriter\|icingaapplication\|apilistener\|apiuser\|endpoint\|zone\)" syn match icinga2ObjDef "object[ \t]\+\(filelogger\|sysloglogger\|icingaapplication\|apilistener\|apiuser\|endpoint\|zone\)"
" apply def " apply def