Merge pull request #8325 from Icinga/feature/improve-ido-logging

Improve new IDO logging
This commit is contained in:
Alexander Aleksandrovič Klimov 2020-10-13 13:52:11 +02:00 committed by GitHub
commit a237dedaea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 15 deletions

View File

@ -77,6 +77,8 @@ void DbConnection::Resume()
m_CleanUpTimer->OnTimerExpired.connect(std::bind(&DbConnection::CleanUpHandler, this));
m_CleanUpTimer->Start();
m_LogStatsTimeout = 0;
m_LogStatsTimer = new Timer();
m_LogStatsTimer->SetInterval(10);
m_LogStatsTimer->OnTimerExpired.connect([this](const Timer * const&) { LogStatsHandler(); });
@ -243,35 +245,34 @@ void DbConnection::CleanUpHandler()
void DbConnection::LogStatsHandler()
{
if (!GetConnected())
return;
auto pending = m_PendingQueries.load();
if (pending == 0u) {
auto now = Utility::GetTime();
bool timeoutReached = m_LogStatsTimeout < now;
if (pending == 0u && !timeoutReached) {
return;
}
auto now = Utility::GetTime();
auto output = round(m_OutputQueries.CalculateRate(now, 10));
if (pending < output * 2) {
if (pending < output * 5 && !timeoutReached) {
return;
}
auto input = round(m_InputQueries.CalculateRate(now, 10));
String timeInfo = " empty in ";
{
auto rate = output - input;
if (rate <= 0)
timeInfo += "infinite time, your task handler isn't able to keep up";
else
timeInfo += Utility::FormatDuration(pending / rate);
}
Log(LogInformation, GetReflectionType()->GetName())
<< "Pending queries: " << pending << " (Input: " << input
<< "/s; Output: " << output << "/s)" << timeInfo;
<< "/s; Output: " << output << "/s)";
/* Reschedule next log entry in 5 minutes. */
if (timeoutReached) {
m_LogStatsTimeout = now + 60 * 5;
}
}
void DbConnection::CleanUpExecuteQuery(const String&, const String&, double)

View File

@ -108,6 +108,8 @@ private:
Timer::Ptr m_CleanUpTimer;
Timer::Ptr m_LogStatsTimer;
double m_LogStatsTimeout;
void CleanUpHandler();
void LogStatsHandler();