Add logging for started/stopped features

fixes #3557
This commit is contained in:
Michael Friedrich 2017-02-08 14:53:52 +01:00
parent 336deea02f
commit e5f5284838
27 changed files with 176 additions and 1 deletions

View File

@ -75,6 +75,10 @@ void CheckerComponent::Start(bool runtimeCreated)
{ {
ObjectImpl<CheckerComponent>::Start(runtimeCreated); ObjectImpl<CheckerComponent>::Start(runtimeCreated);
Log(LogInformation, "CheckerComponent")
<< "'" << GetName() << "' started.";
m_Thread = boost::thread(boost::bind(&CheckerComponent::CheckThreadProc, this)); m_Thread = boost::thread(boost::bind(&CheckerComponent::CheckThreadProc, this));
m_ResultTimer = new Timer(); m_ResultTimer = new Timer();
@ -85,7 +89,8 @@ void CheckerComponent::Start(bool runtimeCreated)
void CheckerComponent::Stop(bool runtimeRemoved) void CheckerComponent::Stop(bool runtimeRemoved)
{ {
Log(LogInformation, "CheckerComponent", "Checker stopped."); Log(LogInformation, "CheckerComponent")
<< "'" << GetName() << "' stopped.";
{ {
boost::mutex::scoped_lock lock(m_Mutex); boost::mutex::scoped_lock lock(m_Mutex);

View File

@ -58,10 +58,26 @@ void CheckResultReader::Start(bool runtimeCreated)
{ {
ObjectImpl<CheckResultReader>::Start(runtimeCreated); ObjectImpl<CheckResultReader>::Start(runtimeCreated);
Log(LogInformation, "CheckResultReader")
<< "'" << GetName() << "' started.";
#ifndef _WIN32
m_ReadTimer = new Timer(); m_ReadTimer = new Timer();
m_ReadTimer->OnTimerExpired.connect(boost::bind(&CheckResultReader::ReadTimerHandler, this)); m_ReadTimer->OnTimerExpired.connect(boost::bind(&CheckResultReader::ReadTimerHandler, this));
m_ReadTimer->SetInterval(5); m_ReadTimer->SetInterval(5);
m_ReadTimer->Start(); m_ReadTimer->Start();
#endif /* _WIN32 */
}
/**
* @threadsafety Always.
*/
void CheckResultReader::Stop(bool runtimeRemoved)
{
Log(LogInformation, "CheckResultReader")
<< "'" << GetName() << "' stopped.";
ObjectImpl<CheckResultReader>::Stop(runtimeRemoved);
} }
/** /**

View File

@ -42,6 +42,7 @@ public:
protected: protected:
virtual void Start(bool runtimeCreated) override; virtual void Start(bool runtimeCreated) override;
virtual void Stop(bool runtimeRemoved) override;
private: private:
Timer::Ptr m_ReadTimer; Timer::Ptr m_ReadTimer;

View File

@ -60,6 +60,9 @@ void CompatLogger::Start(bool runtimeCreated)
{ {
ObjectImpl<CompatLogger>::Start(runtimeCreated); ObjectImpl<CompatLogger>::Start(runtimeCreated);
Log(LogInformation, "CompatLogger")
<< "'" << GetName() << "' started.";
Checkable::OnNewCheckResult.connect(bind(&CompatLogger::CheckResultHandler, this, _1, _2)); Checkable::OnNewCheckResult.connect(bind(&CompatLogger::CheckResultHandler, this, _1, _2));
Checkable::OnNotificationSentToUser.connect(bind(&CompatLogger::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6, _7, _8)); Checkable::OnNotificationSentToUser.connect(bind(&CompatLogger::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6, _7, _8));
Downtime::OnDowntimeTriggered.connect(boost::bind(&CompatLogger::TriggerDowntimeHandler, this, _1)); Downtime::OnDowntimeTriggered.connect(boost::bind(&CompatLogger::TriggerDowntimeHandler, this, _1));
@ -79,6 +82,17 @@ void CompatLogger::Start(bool runtimeCreated)
ScheduleNextRotation(); ScheduleNextRotation();
} }
/**
* @threadsafety Always.
*/
void CompatLogger::Stop(bool runtimeRemoved)
{
Log(LogInformation, "CompatLogger")
<< "'" << GetName() << "' stopped.";
ObjectImpl<CompatLogger>::Stop(runtimeRemoved);
}
/** /**
* @threadsafety Always. * @threadsafety Always.
*/ */

View File

@ -45,6 +45,7 @@ public:
protected: protected:
virtual void Start(bool runtimeCreated) override; virtual void Start(bool runtimeCreated) override;
virtual void Stop(bool runtimeRemoved) override;
private: private:
void WriteLine(const String& line); void WriteLine(const String& line);

View File

@ -50,12 +50,26 @@ void ExternalCommandListener::Start(bool runtimeCreated)
{ {
ObjectImpl<ExternalCommandListener>::Start(runtimeCreated); ObjectImpl<ExternalCommandListener>::Start(runtimeCreated);
Log(LogInformation, "ExternalCommandListener")
<< "'" << GetName() << "' started.";
#ifndef _WIN32 #ifndef _WIN32
m_CommandThread = boost::thread(boost::bind(&ExternalCommandListener::CommandPipeThread, this, GetCommandPath())); m_CommandThread = boost::thread(boost::bind(&ExternalCommandListener::CommandPipeThread, this, GetCommandPath()));
m_CommandThread.detach(); m_CommandThread.detach();
#endif /* _WIN32 */ #endif /* _WIN32 */
} }
/**
* Stops the component.
*/
void ExternalCommandListener::Stop(bool runtimeRemoved)
{
Log(LogInformation, "ExternalCommandListener")
<< "'" << GetName() << "' stopped.";
ObjectImpl<ExternalCommandListener>::Stop(runtimeRemoved);
}
#ifndef _WIN32 #ifndef _WIN32
void ExternalCommandListener::CommandPipeThread(const String& commandPath) void ExternalCommandListener::CommandPipeThread(const String& commandPath)
{ {

View File

@ -43,6 +43,7 @@ public:
protected: protected:
virtual void Start(bool runtimeCreated) override; virtual void Start(bool runtimeCreated) override;
virtual void Stop(bool runtimeRemoved) override;
private: private:
#ifndef _WIN32 #ifndef _WIN32

View File

@ -73,6 +73,9 @@ void StatusDataWriter::Start(bool runtimeCreated)
{ {
ObjectImpl<StatusDataWriter>::Start(runtimeCreated); ObjectImpl<StatusDataWriter>::Start(runtimeCreated);
Log(LogInformation, "StatusDataWriter")
<< "'" << GetName() << "' started.";
m_ObjectsCacheOutdated = true; m_ObjectsCacheOutdated = true;
m_StatusTimer = new Timer(); m_StatusTimer = new Timer();
@ -85,6 +88,17 @@ void StatusDataWriter::Start(bool runtimeCreated)
ConfigObject::OnActiveChanged.connect(boost::bind(&StatusDataWriter::ObjectHandler, this)); ConfigObject::OnActiveChanged.connect(boost::bind(&StatusDataWriter::ObjectHandler, this));
} }
/**
* Stops the component.
*/
void StatusDataWriter::Stop(bool runtimeRemoved)
{
Log(LogInformation, "StatusDataWriter")
<< "'" << GetName() << "' stopped.";
ObjectImpl<StatusDataWriter>::Stop(runtimeRemoved);
}
void StatusDataWriter::DumpComments(std::ostream& fp, const Checkable::Ptr& checkable) void StatusDataWriter::DumpComments(std::ostream& fp, const Checkable::Ptr& checkable)
{ {
Host::Ptr host; Host::Ptr host;

View File

@ -47,6 +47,7 @@ public:
protected: protected:
virtual void Start(bool runtimeCreated) override; virtual void Start(bool runtimeCreated) override;
virtual void Stop(bool runtimeRemoved) override;
private: private:
Timer::Ptr m_StatusTimer; Timer::Ptr m_StatusTimer;

View File

@ -72,10 +72,21 @@ void DbConnection::Start(bool runtimeCreated)
{ {
ObjectImpl<DbConnection>::Start(runtimeCreated); ObjectImpl<DbConnection>::Start(runtimeCreated);
Log(LogInformation, "DbConnection")
<< "'" << GetName() << "' started.";
DbObject::OnQuery.connect(boost::bind(&DbConnection::ExecuteQuery, this, _1)); DbObject::OnQuery.connect(boost::bind(&DbConnection::ExecuteQuery, this, _1));
DbObject::OnMultipleQueries.connect(boost::bind(&DbConnection::ExecuteMultipleQueries, this, _1)); DbObject::OnMultipleQueries.connect(boost::bind(&DbConnection::ExecuteMultipleQueries, this, _1));
} }
void DbConnection::Stop(bool runtimeRemoved)
{
Log(LogInformation, "DbConnection")
<< "'" << GetName() << "' stopped.";
ObjectImpl<DbConnection>::Stop(runtimeRemoved);
}
void DbConnection::EnableActiveChangedHandler(void) void DbConnection::EnableActiveChangedHandler(void)
{ {
if (!m_ActiveChangedHandler) { if (!m_ActiveChangedHandler) {

View File

@ -81,6 +81,7 @@ public:
protected: protected:
virtual void OnConfigLoaded(void) override; virtual void OnConfigLoaded(void) override;
virtual void Start(bool runtimeCreated) override; virtual void Start(bool runtimeCreated) override;
virtual void Stop(bool runtimeRemoved) override;
virtual void Resume(void) override; virtual void Resume(void) override;
virtual void Pause(void) override; virtual void Pause(void) override;

View File

@ -77,6 +77,9 @@ void IdoMysqlConnection::Resume(void)
{ {
DbConnection::Resume(); DbConnection::Resume();
Log(LogInformation, "IdoMysqlConnection")
<< "'" << GetName() << "' resumed.";
SetConnected(false); SetConnected(false);
m_QueryQueue.SetExceptionCallback(boost::bind(&IdoMysqlConnection::ExceptionHandler, this, _1)); m_QueryQueue.SetExceptionCallback(boost::bind(&IdoMysqlConnection::ExceptionHandler, this, _1));
@ -97,6 +100,9 @@ void IdoMysqlConnection::Resume(void)
void IdoMysqlConnection::Pause(void) void IdoMysqlConnection::Pause(void)
{ {
Log(LogInformation, "IdoMysqlConnection")
<< "'" << GetName() << "' paused.";
m_ReconnectTimer.reset(); m_ReconnectTimer.reset();
DbConnection::Pause(); DbConnection::Pause();

View File

@ -81,6 +81,9 @@ void IdoPgsqlConnection::Resume(void)
{ {
DbConnection::Resume(); DbConnection::Resume();
Log(LogInformation, "IdoPgsqlConnection")
<< "'" << GetName() << "' resumed.";
SetConnected(false); SetConnected(false);
m_QueryQueue.SetExceptionCallback(boost::bind(&IdoPgsqlConnection::ExceptionHandler, this, _1)); m_QueryQueue.SetExceptionCallback(boost::bind(&IdoPgsqlConnection::ExceptionHandler, this, _1));
@ -101,6 +104,9 @@ void IdoPgsqlConnection::Resume(void)
void IdoPgsqlConnection::Pause(void) void IdoPgsqlConnection::Pause(void)
{ {
Log(LogInformation, "IdoPgsqlConnection")
<< "'" << GetName() << "' paused.";
m_ReconnectTimer.reset(); m_ReconnectTimer.reset();
DbConnection::Pause(); DbConnection::Pause();

View File

@ -66,6 +66,9 @@ void LivestatusListener::Start(bool runtimeCreated)
{ {
ObjectImpl<LivestatusListener>::Start(runtimeCreated); ObjectImpl<LivestatusListener>::Start(runtimeCreated);
Log(LogInformation, "LivestatusListener")
<< "'" << GetName() << "' started.";
if (GetSocketType() == "tcp") { if (GetSocketType() == "tcp") {
TcpSocket::Ptr socket = new TcpSocket(); TcpSocket::Ptr socket = new TcpSocket();
@ -123,6 +126,9 @@ void LivestatusListener::Stop(bool runtimeRemoved)
{ {
ObjectImpl<LivestatusListener>::Stop(runtimeRemoved); ObjectImpl<LivestatusListener>::Stop(runtimeRemoved);
Log(LogInformation, "LivestatusListener")
<< "'" << GetName() << "' stopped.";
m_Listener->Close(); m_Listener->Close();
if (m_Thread.joinable()) if (m_Thread.joinable())

View File

@ -52,6 +52,9 @@ void NotificationComponent::Start(bool runtimeCreated)
{ {
ObjectImpl<NotificationComponent>::Start(runtimeCreated); ObjectImpl<NotificationComponent>::Start(runtimeCreated);
Log(LogInformation, "NotificationComponent")
<< "'" << GetName() << "' started.";
Checkable::OnNotificationsRequested.connect(boost::bind(&NotificationComponent::SendNotificationsHandler, this, _1, Checkable::OnNotificationsRequested.connect(boost::bind(&NotificationComponent::SendNotificationsHandler, this, _1,
_2, _3, _4, _5)); _2, _3, _4, _5));
@ -61,6 +64,14 @@ void NotificationComponent::Start(bool runtimeCreated)
m_NotificationTimer->Start(); m_NotificationTimer->Start();
} }
void NotificationComponent::Stop(bool runtimeRemoved)
{
Log(LogInformation, "NotificationComponent")
<< "'" << GetName() << "' stopped.";
ObjectImpl<NotificationComponent>::Stop(runtimeRemoved);
}
/** /**
* Periodically sends notifications. * Periodically sends notifications.
* *

View File

@ -40,6 +40,7 @@ public:
static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata); static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
virtual void Start(bool runtimeCreated) override; virtual void Start(bool runtimeCreated) override;
virtual void Stop(bool runtimeRemoved) override;
private: private:
Timer::Ptr m_NotificationTimer; Timer::Ptr m_NotificationTimer;

View File

@ -43,6 +43,9 @@ void GelfWriter::Start(bool runtimeCreated)
{ {
ObjectImpl<GelfWriter>::Start(runtimeCreated); ObjectImpl<GelfWriter>::Start(runtimeCreated);
Log(LogInformation, "GelfWriter")
<< "'" << GetName() << "' started.";
m_ReconnectTimer = new Timer(); m_ReconnectTimer = new Timer();
m_ReconnectTimer->SetInterval(10); m_ReconnectTimer->SetInterval(10);
m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&GelfWriter::ReconnectTimerHandler, this)); m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&GelfWriter::ReconnectTimerHandler, this));
@ -57,6 +60,14 @@ void GelfWriter::Start(bool runtimeCreated)
Service::OnStateChange.connect(boost::bind(&GelfWriter::StateChangeHandler, this, _1, _2, _3)); Service::OnStateChange.connect(boost::bind(&GelfWriter::StateChangeHandler, this, _1, _2, _3));
} }
void GelfWriter::Stop(bool runtimeRemoved)
{
Log(LogInformation, "GelfWriter")
<< "'" << GetName() << "' stopped.";
ObjectImpl<GelfWriter>::Stop(runtimeRemoved);
}
void GelfWriter::ReconnectTimerHandler(void) void GelfWriter::ReconnectTimerHandler(void)
{ {
if (m_Stream) if (m_Stream)

View File

@ -43,6 +43,7 @@ public:
protected: protected:
virtual void Start(bool runtimeCreated) override; virtual void Start(bool runtimeCreated) override;
virtual void Stop(bool runtimeRemoved) override;
private: private:
Stream::Ptr m_Stream; Stream::Ptr m_Stream;

View File

@ -61,6 +61,9 @@ void GraphiteWriter::Start(bool runtimeCreated)
{ {
ObjectImpl<GraphiteWriter>::Start(runtimeCreated); ObjectImpl<GraphiteWriter>::Start(runtimeCreated);
Log(LogInformation, "GraphiteWriter")
<< "'" << GetName() << "' started.";
m_ReconnectTimer = new Timer(); m_ReconnectTimer = new Timer();
m_ReconnectTimer->SetInterval(10); m_ReconnectTimer->SetInterval(10);
m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&GraphiteWriter::ReconnectTimerHandler, this)); m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&GraphiteWriter::ReconnectTimerHandler, this));
@ -70,6 +73,14 @@ void GraphiteWriter::Start(bool runtimeCreated)
Service::OnNewCheckResult.connect(boost::bind(&GraphiteWriter::CheckResultHandler, this, _1, _2)); Service::OnNewCheckResult.connect(boost::bind(&GraphiteWriter::CheckResultHandler, this, _1, _2));
} }
void GraphiteWriter::Stop(bool runtimeRemoved)
{
Log(LogInformation, "GraphiteWriter")
<< "'" << GetName() << "' stopped.";
ObjectImpl<GraphiteWriter>::Stop(runtimeRemoved);
}
void GraphiteWriter::ReconnectTimerHandler(void) void GraphiteWriter::ReconnectTimerHandler(void)
{ {
if (m_Stream) if (m_Stream)

View File

@ -48,6 +48,7 @@ public:
protected: protected:
virtual void Start(bool runtimeCreated) override; virtual void Start(bool runtimeCreated) override;
virtual void Stop(bool runtimeRemoved) override;
private: private:
Stream::Ptr m_Stream; Stream::Ptr m_Stream;

View File

@ -69,6 +69,9 @@ void InfluxdbWriter::Start(bool runtimeCreated)
ObjectImpl<InfluxdbWriter>::Start(runtimeCreated); ObjectImpl<InfluxdbWriter>::Start(runtimeCreated);
Log(LogInformation, "InfluxdbWriter")
<< "'" << GetName() << "' started.";
m_FlushTimer = new Timer(); m_FlushTimer = new Timer();
m_FlushTimer->SetInterval(GetFlushInterval()); m_FlushTimer->SetInterval(GetFlushInterval());
m_FlushTimer->OnTimerExpired.connect(boost::bind(&InfluxdbWriter::FlushTimeout, this)); m_FlushTimer->OnTimerExpired.connect(boost::bind(&InfluxdbWriter::FlushTimeout, this));
@ -78,6 +81,14 @@ void InfluxdbWriter::Start(bool runtimeCreated)
Service::OnNewCheckResult.connect(boost::bind(&InfluxdbWriter::CheckResultHandler, this, _1, _2)); Service::OnNewCheckResult.connect(boost::bind(&InfluxdbWriter::CheckResultHandler, this, _1, _2));
} }
void InfluxdbWriter::Stop(bool runtimeRemoved)
{
Log(LogInformation, "InfluxdbWriter")
<< "'" << GetName() << "' stopped.";
ObjectImpl<InfluxdbWriter>::Stop(runtimeRemoved);
}
Stream::Ptr InfluxdbWriter::Connect(TcpSocket::Ptr& socket) Stream::Ptr InfluxdbWriter::Connect(TcpSocket::Ptr& socket)
{ {
socket = new TcpSocket(); socket = new TcpSocket();

View File

@ -48,6 +48,7 @@ public:
protected: protected:
virtual void Start(bool runtimeCreated) override; virtual void Start(bool runtimeCreated) override;
virtual void Stop(bool runtimeRemoved) override;
private: private:
Timer::Ptr m_FlushTimer; Timer::Ptr m_FlushTimer;

View File

@ -61,6 +61,9 @@ void OpenTsdbWriter::Start(bool runtimeCreated)
{ {
ObjectImpl<OpenTsdbWriter>::Start(runtimeCreated); ObjectImpl<OpenTsdbWriter>::Start(runtimeCreated);
Log(LogInformation, "OpentsdbWriter")
<< "'" << GetName() << "' started.";
m_ReconnectTimer = new Timer(); m_ReconnectTimer = new Timer();
m_ReconnectTimer->SetInterval(10); m_ReconnectTimer->SetInterval(10);
m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&OpenTsdbWriter::ReconnectTimerHandler, this)); m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&OpenTsdbWriter::ReconnectTimerHandler, this));
@ -70,6 +73,14 @@ void OpenTsdbWriter::Start(bool runtimeCreated)
Service::OnNewCheckResult.connect(boost::bind(&OpenTsdbWriter::CheckResultHandler, this, _1, _2)); Service::OnNewCheckResult.connect(boost::bind(&OpenTsdbWriter::CheckResultHandler, this, _1, _2));
} }
void OpenTsdbWriter::Stop(bool runtimeRemoved)
{
Log(LogInformation, "OpentsdbWriter")
<< "'" << GetName() << "' stopped.";
ObjectImpl<OpenTsdbWriter>::Stop(runtimeRemoved);
}
void OpenTsdbWriter::ReconnectTimerHandler(void) void OpenTsdbWriter::ReconnectTimerHandler(void)
{ {
if (m_Stream) if (m_Stream)

View File

@ -45,6 +45,7 @@ public:
protected: protected:
virtual void Start(bool runtimeCreated) override; virtual void Start(bool runtimeCreated) override;
virtual void Stop(bool runtimeRemoved) override;
private: private:
Stream::Ptr m_Stream; Stream::Ptr m_Stream;

View File

@ -53,6 +53,9 @@ void PerfdataWriter::Start(bool runtimeCreated)
{ {
ObjectImpl<PerfdataWriter>::Start(runtimeCreated); ObjectImpl<PerfdataWriter>::Start(runtimeCreated);
Log(LogInformation, "PerfdataWriter")
<< "'" << GetName() << "' started.";
Checkable::OnNewCheckResult.connect(boost::bind(&PerfdataWriter::CheckResultHandler, this, _1, _2)); Checkable::OnNewCheckResult.connect(boost::bind(&PerfdataWriter::CheckResultHandler, this, _1, _2));
m_RotationTimer = new Timer(); m_RotationTimer = new Timer();
@ -64,6 +67,14 @@ void PerfdataWriter::Start(bool runtimeCreated)
RotateFile(m_HostOutputFile, GetHostTempPath(), GetHostPerfdataPath()); RotateFile(m_HostOutputFile, GetHostTempPath(), GetHostPerfdataPath());
} }
void PerfdataWriter::Stop(bool runtimeRemoved)
{
Log(LogInformation, "PerfdataWriter")
<< "'" << GetName() << "' stopped.";
ObjectImpl<PerfdataWriter>::Stop(runtimeRemoved);
}
Value PerfdataWriter::EscapeMacroMetric(const Value& value) Value PerfdataWriter::EscapeMacroMetric(const Value& value)
{ {
if (value.IsObjectType<Array>()) if (value.IsObjectType<Array>())

View File

@ -47,6 +47,7 @@ public:
protected: protected:
virtual void Start(bool runtimeCreated) override; virtual void Start(bool runtimeCreated) override;
virtual void Stop(bool runtimeRemoved) override;
private: private:
void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr); void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);

View File

@ -127,6 +127,9 @@ void ApiListener::OnAllConfigLoaded(void)
*/ */
void ApiListener::Start(bool runtimeCreated) void ApiListener::Start(bool runtimeCreated)
{ {
Log(LogInformation, "ApiListener")
<< "'" << GetName() << "' started.";
SyncZoneDirs(); SyncZoneDirs();
ObjectImpl<ApiListener>::Start(runtimeCreated); ObjectImpl<ApiListener>::Start(runtimeCreated);
@ -168,6 +171,9 @@ void ApiListener::Stop(bool runtimeDeleted)
{ {
ObjectImpl<ApiListener>::Stop(runtimeDeleted); ObjectImpl<ApiListener>::Stop(runtimeDeleted);
Log(LogInformation, "ApiListener")
<< "'" << GetName() << "' stopped.";
boost::mutex::scoped_lock lock(m_LogLock); boost::mutex::scoped_lock lock(m_LogLock);
CloseLogFile(); CloseLogFile();
} }