WorkQueue: Allow choosing stats log level

This commit is contained in:
Henrik Triem 2020-09-14 17:09:11 +02:00 committed by Alexander A. Klimov
parent d12bffe5f4
commit 312ea054b4
2 changed files with 8 additions and 3 deletions

View File

@ -14,7 +14,7 @@ using namespace icinga;
std::atomic<int> WorkQueue::m_NextID(1);
boost::thread_specific_ptr<WorkQueue *> l_ThreadWorkQueue;
WorkQueue::WorkQueue(size_t maxItems, int threadCount)
WorkQueue::WorkQueue(size_t maxItems, int threadCount, LogSeverity statsLogLevel)
: m_ID(m_NextID++), m_ThreadCount(threadCount), m_MaxItems(maxItems),
m_TaskStats(15 * 60)
{
@ -25,6 +25,8 @@ WorkQueue::WorkQueue(size_t maxItems, int threadCount)
m_StatusTimer->SetInterval(10);
m_StatusTimer->OnTimerExpired.connect(std::bind(&WorkQueue::StatusTimerHandler, this));
m_StatusTimer->Start();
m_StatsLogLevel = statsLogLevel;
}
WorkQueue::~WorkQueue()
@ -216,7 +218,7 @@ void WorkQueue::StatusTimerHandler()
/* Log if there are pending items, or 5 minute timeout is reached. */
if (pending > 0 || m_StatusTimerTimeout < now) {
Log(LogInformation, "WorkQueue")
Log(m_StatsLogLevel, "WorkQueue")
<< "#" << m_ID << " (" << m_Name << ") "
<< "items: " << pending << ", "
<< "rate: " << std::setw(2) << GetTaskCount(60) / 60.0 << "/s "

View File

@ -6,6 +6,7 @@
#include "base/i2-base.hpp"
#include "base/timer.hpp"
#include "base/ringbuffer.hpp"
#include "base/logger.hpp"
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
@ -52,7 +53,7 @@ class WorkQueue
public:
typedef std::function<void (boost::exception_ptr)> ExceptionCallback;
WorkQueue(size_t maxItems = 0, int threadCount = 1);
WorkQueue(size_t maxItems = 0, int threadCount = 1, LogSeverity statsLogLevel = LogInformation);
~WorkQueue();
void SetName(const String& name);
@ -138,6 +139,8 @@ private:
void StatusTimerHandler();
void RunTaskFunction(const TaskFunction& func);
LogSeverity m_StatsLogLevel;
};
}