Fix that RingBuffer does not get updated if nothing is written

refs #5750
This commit is contained in:
Noah Hilverling 2017-11-13 16:17:59 +01:00
parent e4466307a7
commit 2acaccd028
7 changed files with 15 additions and 12 deletions

View File

@ -19,6 +19,7 @@
#include "base/ringbuffer.hpp"
#include "base/objectlock.hpp"
#include "base/utility.hpp"
using namespace icinga;
@ -58,8 +59,10 @@ void RingBuffer::InsertValue(RingBuffer::SizeType tv, int num)
m_Slots[offsetTarget] += num;
}
int RingBuffer::GetValues(RingBuffer::SizeType span) const
int RingBuffer::UpdateAndGetValues(RingBuffer::SizeType tv, RingBuffer::SizeType span)
{
InsertValue(tv, 0);
ObjectLock olock(this);
if (span > m_Slots.size())

View File

@ -43,7 +43,7 @@ public:
SizeType GetLength(void) const;
void InsertValue(SizeType tv, int num);
int GetValues(SizeType span) const;
int UpdateAndGetValues(SizeType tv, SizeType span);
private:
std::vector<int> m_Slots;

View File

@ -296,8 +296,8 @@ void WorkQueue::IncreaseTaskCount(void)
m_TaskStats.InsertValue(now, 1);
}
int WorkQueue::GetTaskCount(RingBuffer::SizeType span) const
int WorkQueue::GetTaskCount(RingBuffer::SizeType span)
{
boost::mutex::scoped_lock lock(m_StatsMutex);
return m_TaskStats.GetValues(span);
return m_TaskStats.UpdateAndGetValues(Utility::GetTime(), span);
}

View File

@ -94,7 +94,7 @@ public:
bool IsWorkerThread(void) const;
size_t GetLength(void) const;
int GetTaskCount(RingBuffer::SizeType span) const;
int GetTaskCount(RingBuffer::SizeType span);
void SetExceptionCallback(const ExceptionCallback& callback);

View File

@ -474,10 +474,10 @@ void DbConnection::IncreaseQueryCount(void)
m_QueryStats.InsertValue(now, 1);
}
int DbConnection::GetQueryCount(RingBuffer::SizeType span) const
int DbConnection::GetQueryCount(RingBuffer::SizeType span)
{
boost::mutex::scoped_lock lock(m_StatsMutex);
return m_QueryStats.GetValues(span);
return m_QueryStats.UpdateAndGetValues(Utility::GetTime(), span);
}
bool DbConnection::IsIDCacheValid(void) const

View File

@ -73,7 +73,7 @@ public:
void SetStatusUpdate(const DbObject::Ptr& dbobj, bool hasupdate);
bool GetStatusUpdate(const DbObject::Ptr& dbobj) const;
int GetQueryCount(RingBuffer::SizeType span) const;
int GetQueryCount(RingBuffer::SizeType span);
virtual int GetPendingQueryCount(void) const = 0;
virtual void ValidateFailoverTimeout(double value, const ValidationUtils& utils) override;

View File

@ -45,12 +45,12 @@ void CIB::UpdateActiveServiceChecksStatistics(long tv, int num)
int CIB::GetActiveHostChecksStatistics(long timespan)
{
return m_ActiveHostChecksStatistics.GetValues(timespan);
return m_ActiveHostChecksStatistics.UpdateAndGetValues(Utility::GetTime(), timespan);
}
int CIB::GetActiveServiceChecksStatistics(long timespan)
{
return m_ActiveServiceChecksStatistics.GetValues(timespan);
return m_ActiveServiceChecksStatistics.UpdateAndGetValues(Utility::GetTime(), timespan);
}
void CIB::UpdatePassiveHostChecksStatistics(long tv, int num)
@ -65,12 +65,12 @@ void CIB::UpdatePassiveServiceChecksStatistics(long tv, int num)
int CIB::GetPassiveHostChecksStatistics(long timespan)
{
return m_PassiveHostChecksStatistics.GetValues(timespan);
return m_PassiveHostChecksStatistics.UpdateAndGetValues(Utility::GetTime(), timespan);
}
int CIB::GetPassiveServiceChecksStatistics(long timespan)
{
return m_PassiveServiceChecksStatistics.GetValues(timespan);
return m_PassiveServiceChecksStatistics.UpdateAndGetValues(Utility::GetTime(), timespan);
}
CheckableCheckStatistics CIB::CalculateHostCheckStats(void)