WorkQueue: Allow choosing stats log level

This commit is contained in:
Henrik Triem 2020-09-14 17:09:11 +02:00 committed by Noah Hilverling
parent 2dfe777f48
commit 3c556350c8
2 changed files with 6 additions and 4 deletions

View File

@ -14,9 +14,9 @@ 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)
m_TaskStats(15 * 60), m_StatsLogLevel(statsLogLevel)
{
/* Initialize logger. */
m_StatusTimerTimeout = Utility::GetTime();
@ -216,7 +216,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);
@ -129,6 +130,7 @@ private:
std::vector<boost::exception_ptr> m_Exceptions;
Timer::Ptr m_StatusTimer;
double m_StatusTimerTimeout;
LogSeverity m_StatsLogLevel;
RingBuffer m_TaskStats;
size_t m_PendingTasks{0};