From ad0fe764f79f1d6d2cc493c9d5c8b975cd87be3c Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 26 Jan 2022 12:35:41 +0100 Subject: [PATCH] Icinga DB: log amount of history kept in memory every 10s --- lib/base/bulker.hpp | 5 +++++ lib/icingadb/icingadb-objects.cpp | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/base/bulker.hpp b/lib/base/bulker.hpp index 711aae04f..2c30dc38b 100644 --- a/lib/base/bulker.hpp +++ b/lib/base/bulker.hpp @@ -38,6 +38,11 @@ public: Container ConsumeMany(); SizeType Size(); + inline SizeType GetBulkSize() const noexcept + { + return m_BulkSize; + } + private: typedef std::chrono::time_point TimePoint; diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index 5f2117e57..265b78063 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -30,6 +30,7 @@ #include "icinga/timeperiod.hpp" #include "icinga/pluginutility.hpp" #include "remote/zone.hpp" +#include #include #include #include @@ -2264,7 +2265,25 @@ void IcingaDB::SendAcknowledgementCleared(const Checkable::Ptr& checkable, const 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 (;;) { + logPeriodically(); + auto haystack (m_HistoryBulker.ConsumeMany()); if (haystack.empty()) { @@ -2288,6 +2307,8 @@ void IcingaDB::ForwardHistoryEntries() }); for (;;) { + logPeriodically(); + if (m_Rcon && m_Rcon->IsConnected()) { try { m_Rcon->GetResultsOfQueries(haystack, Prio::History);