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

View File

@ -58,10 +58,26 @@ void CheckResultReader::Start(bool runtimeCreated)
{
ObjectImpl<CheckResultReader>::Start(runtimeCreated);
Log(LogInformation, "CheckResultReader")
<< "'" << GetName() << "' started.";
#ifndef _WIN32
m_ReadTimer = new Timer();
m_ReadTimer->OnTimerExpired.connect(boost::bind(&CheckResultReader::ReadTimerHandler, this));
m_ReadTimer->SetInterval(5);
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:
virtual void Start(bool runtimeCreated) override;
virtual void Stop(bool runtimeRemoved) override;
private:
Timer::Ptr m_ReadTimer;

View File

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

View File

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

View File

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

View File

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

View File

@ -73,6 +73,9 @@ void StatusDataWriter::Start(bool runtimeCreated)
{
ObjectImpl<StatusDataWriter>::Start(runtimeCreated);
Log(LogInformation, "StatusDataWriter")
<< "'" << GetName() << "' started.";
m_ObjectsCacheOutdated = true;
m_StatusTimer = new Timer();
@ -85,6 +88,17 @@ void StatusDataWriter::Start(bool runtimeCreated)
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)
{
Host::Ptr host;

View File

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

View File

@ -72,10 +72,21 @@ void DbConnection::Start(bool runtimeCreated)
{
ObjectImpl<DbConnection>::Start(runtimeCreated);
Log(LogInformation, "DbConnection")
<< "'" << GetName() << "' started.";
DbObject::OnQuery.connect(boost::bind(&DbConnection::ExecuteQuery, 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)
{
if (!m_ActiveChangedHandler) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -43,6 +43,9 @@ void GelfWriter::Start(bool runtimeCreated)
{
ObjectImpl<GelfWriter>::Start(runtimeCreated);
Log(LogInformation, "GelfWriter")
<< "'" << GetName() << "' started.";
m_ReconnectTimer = new Timer();
m_ReconnectTimer->SetInterval(10);
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));
}
void GelfWriter::Stop(bool runtimeRemoved)
{
Log(LogInformation, "GelfWriter")
<< "'" << GetName() << "' stopped.";
ObjectImpl<GelfWriter>::Stop(runtimeRemoved);
}
void GelfWriter::ReconnectTimerHandler(void)
{
if (m_Stream)

View File

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

View File

@ -61,6 +61,9 @@ void GraphiteWriter::Start(bool runtimeCreated)
{
ObjectImpl<GraphiteWriter>::Start(runtimeCreated);
Log(LogInformation, "GraphiteWriter")
<< "'" << GetName() << "' started.";
m_ReconnectTimer = new Timer();
m_ReconnectTimer->SetInterval(10);
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));
}
void GraphiteWriter::Stop(bool runtimeRemoved)
{
Log(LogInformation, "GraphiteWriter")
<< "'" << GetName() << "' stopped.";
ObjectImpl<GraphiteWriter>::Stop(runtimeRemoved);
}
void GraphiteWriter::ReconnectTimerHandler(void)
{
if (m_Stream)

View File

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

View File

@ -69,6 +69,9 @@ void InfluxdbWriter::Start(bool runtimeCreated)
ObjectImpl<InfluxdbWriter>::Start(runtimeCreated);
Log(LogInformation, "InfluxdbWriter")
<< "'" << GetName() << "' started.";
m_FlushTimer = new Timer();
m_FlushTimer->SetInterval(GetFlushInterval());
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));
}
void InfluxdbWriter::Stop(bool runtimeRemoved)
{
Log(LogInformation, "InfluxdbWriter")
<< "'" << GetName() << "' stopped.";
ObjectImpl<InfluxdbWriter>::Stop(runtimeRemoved);
}
Stream::Ptr InfluxdbWriter::Connect(TcpSocket::Ptr& socket)
{
socket = new TcpSocket();

View File

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

View File

@ -61,6 +61,9 @@ void OpenTsdbWriter::Start(bool runtimeCreated)
{
ObjectImpl<OpenTsdbWriter>::Start(runtimeCreated);
Log(LogInformation, "OpentsdbWriter")
<< "'" << GetName() << "' started.";
m_ReconnectTimer = new Timer();
m_ReconnectTimer->SetInterval(10);
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));
}
void OpenTsdbWriter::Stop(bool runtimeRemoved)
{
Log(LogInformation, "OpentsdbWriter")
<< "'" << GetName() << "' stopped.";
ObjectImpl<OpenTsdbWriter>::Stop(runtimeRemoved);
}
void OpenTsdbWriter::ReconnectTimerHandler(void)
{
if (m_Stream)

View File

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

View File

@ -53,6 +53,9 @@ void PerfdataWriter::Start(bool runtimeCreated)
{
ObjectImpl<PerfdataWriter>::Start(runtimeCreated);
Log(LogInformation, "PerfdataWriter")
<< "'" << GetName() << "' started.";
Checkable::OnNewCheckResult.connect(boost::bind(&PerfdataWriter::CheckResultHandler, this, _1, _2));
m_RotationTimer = new Timer();
@ -64,6 +67,14 @@ void PerfdataWriter::Start(bool runtimeCreated)
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)
{
if (value.IsObjectType<Array>())

View File

@ -47,6 +47,7 @@ public:
protected:
virtual void Start(bool runtimeCreated) override;
virtual void Stop(bool runtimeRemoved) override;
private:
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)
{
Log(LogInformation, "ApiListener")
<< "'" << GetName() << "' started.";
SyncZoneDirs();
ObjectImpl<ApiListener>::Start(runtimeCreated);
@ -168,6 +171,9 @@ void ApiListener::Stop(bool runtimeDeleted)
{
ObjectImpl<ApiListener>::Stop(runtimeDeleted);
Log(LogInformation, "ApiListener")
<< "'" << GetName() << "' stopped.";
boost::mutex::scoped_lock lock(m_LogLock);
CloseLogFile();
}