Icinga DB: log amount of history kept in memory every 10s

This commit is contained in:
Alexander A. Klimov 2022-01-26 12:35:41 +01:00
parent 8ea62f7fc7
commit ad0fe764f7
2 changed files with 26 additions and 0 deletions

View File

@ -38,6 +38,11 @@ public:
Container ConsumeMany(); Container ConsumeMany();
SizeType Size(); SizeType Size();
inline SizeType GetBulkSize() const noexcept
{
return m_BulkSize;
}
private: private:
typedef std::chrono::time_point<Clock> TimePoint; typedef std::chrono::time_point<Clock> TimePoint;

View File

@ -30,6 +30,7 @@
#include "icinga/timeperiod.hpp" #include "icinga/timeperiod.hpp"
#include "icinga/pluginutility.hpp" #include "icinga/pluginutility.hpp"
#include "remote/zone.hpp" #include "remote/zone.hpp"
#include <chrono>
#include <cstdint> #include <cstdint>
#include <iterator> #include <iterator>
#include <map> #include <map>
@ -2264,7 +2265,25 @@ void IcingaDB::SendAcknowledgementCleared(const Checkable::Ptr& checkable, const
void IcingaDB::ForwardHistoryEntries() void IcingaDB::ForwardHistoryEntries()
{ {
using clock = std::chrono::steady_clock;
const std::chrono::seconds logInterval (10);
auto nextLog (clock::now() + logInterval);
auto logPeriodically ([this, logInterval, &nextLog]() {
if (clock::now() > nextLog) {
nextLog += logInterval;
auto size (m_HistoryBulker.Size());
Log(size > m_HistoryBulker.GetBulkSize() ? LogInformation : LogNotice, "IcingaDB")
<< "Pending history queries: " << size;
}
});
for (;;) { for (;;) {
logPeriodically();
auto haystack (m_HistoryBulker.ConsumeMany()); auto haystack (m_HistoryBulker.ConsumeMany());
if (haystack.empty()) { if (haystack.empty()) {
@ -2288,6 +2307,8 @@ void IcingaDB::ForwardHistoryEntries()
}); });
for (;;) { for (;;) {
logPeriodically();
if (m_Rcon && m_Rcon->IsConnected()) { if (m_Rcon && m_Rcon->IsConnected()) {
try { try {
m_Rcon->GetResultsOfQueries(haystack, Prio::History); m_Rcon->GetResultsOfQueries(haystack, Prio::History);