Module: check_mk
Branch: master
Commit: f9302844ec51c498f2ae93193d9c484a8b2ae124
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f9302844ec51c4…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Feb 26 16:59:26 2019 +0100
Nuked global variable num_cached_log_messages.
Change-Id: I0f9a239a2c1da43af15a1bb49f6754f747ee6649
---
livestatus/src/LogCache.cc | 35 +++++++++++++++++---------------
livestatus/src/LogCache.h | 2 ++
livestatus/src/MonitoringCore.h | 1 +
livestatus/src/StatusSpecialIntColumn.cc | 2 ++
livestatus/src/StatusSpecialIntColumn.h | 3 ++-
livestatus/src/Store.cc | 5 ++++-
livestatus/src/Store.h | 2 ++
livestatus/src/TableStatus.cc | 7 +++----
livestatus/src/module.cc | 4 ++++
9 files changed, 39 insertions(+), 22 deletions(-)
diff --git a/livestatus/src/LogCache.cc b/livestatus/src/LogCache.cc
index a3c9681..9ca69ab 100644
--- a/livestatus/src/LogCache.cc
+++ b/livestatus/src/LogCache.cc
@@ -37,10 +37,9 @@ namespace {
constexpr unsigned long check_mem_cycle = 1000;
} // namespace
-int num_cached_log_messages = 0;
-
LogCache::LogCache(MonitoringCore *mc, unsigned long max_cached_messages)
: _mc(mc)
+ , _num_cached_log_messages(0)
, _max_cached_messages(max_cached_messages)
, _num_at_last_check(0) {
update();
@@ -66,7 +65,7 @@ void LogCache::update() {
Informational(logger()) << "updating log file index";
_logfiles.clear();
- num_cached_log_messages = 0;
+ _num_cached_log_messages = 0;
_last_index_update = std::chrono::system_clock::now();
// We need to find all relevant logfiles. This includes directory, the
@@ -115,7 +114,7 @@ void LogCache::addToIndex(std::unique_ptr<Logfile> logfile) {
not the messages that just has been loaded.
*/
void LogCache::logLineHasBeenAdded(Logfile *logfile, unsigned logclasses) {
- if (static_cast<unsigned long>(++num_cached_log_messages) <=
+ if (static_cast<unsigned long>(++_num_cached_log_messages) <=
_max_cached_messages) {
return; // current message count still allowed, everything ok
}
@@ -126,7 +125,7 @@ void LogCache::logLineHasBeenAdded(Logfile *logfile, unsigned
logclasses) {
memory can be freed. We do this by suppressing the check when
the number of messages loaded into memory has not grown
by at least check_mem_cycle messages */
- if (static_cast<unsigned long>(num_cached_log_messages) <
+ if (static_cast<unsigned long>(_num_cached_log_messages) <
_num_at_last_check + check_mem_cycle) {
return; // Do not check this time
}
@@ -140,14 +139,14 @@ void LogCache::logLineHasBeenAdded(Logfile *logfile, unsigned
logclasses) {
break;
}
if (it->second->size() > 0) {
- num_cached_log_messages -= it->second->size();
+ _num_cached_log_messages -= it->second->size();
it->second->flush(); // drop all messages of that file
- if (static_cast<unsigned long>(num_cached_log_messages) <=
+ if (static_cast<unsigned long>(_num_cached_log_messages) <=
_max_cached_messages) {
// remember the number of log messages in cache when
// the last memory-release was done. No further
// release-check shall be done until that number changes.
- _num_at_last_check = num_cached_log_messages;
+ _num_at_last_check = _num_cached_log_messages;
return;
}
}
@@ -167,10 +166,10 @@ void LogCache::logLineHasBeenAdded(Logfile *logfile, unsigned
logclasses) {
<< it->second->path();
// flush only messages not needed for current query
long freed = it->second->freeMessages(~logclasses);
- num_cached_log_messages -= freed;
- if (static_cast<unsigned long>(num_cached_log_messages) <=
+ _num_cached_log_messages -= freed;
+ if (static_cast<unsigned long>(_num_cached_log_messages) <=
_max_cached_messages) {
- _num_at_last_check = num_cached_log_messages;
+ _num_at_last_check = _num_cached_log_messages;
return;
}
}
@@ -184,23 +183,27 @@ void LogCache::logLineHasBeenAdded(Logfile *logfile, unsigned
logclasses) {
if (it->second->size() > 0) {
Debug(logger()) << "flush newer log, " <<
it->second->size()
<< " number of entries";
- num_cached_log_messages -= it->second->size();
+ _num_cached_log_messages -= it->second->size();
it->second->flush();
- if (static_cast<unsigned long>(num_cached_log_messages) <=
+ if (static_cast<unsigned long>(_num_cached_log_messages) <=
_max_cached_messages) {
- _num_at_last_check = num_cached_log_messages;
+ _num_at_last_check = _num_cached_log_messages;
return;
}
}
}
- _num_at_last_check = num_cached_log_messages;
+ _num_at_last_check = _num_cached_log_messages;
// If we reach this point, no more logfiles can be unloaded,
// despite the fact that there are still too many messages
// loaded.
Debug(logger()) << "cannot unload more messages, still "
- << num_cached_log_messages << " loaded (max is
"
+ << _num_cached_log_messages << " loaded (max is
"
<< _max_cached_messages << ")";
}
+size_t LogCache::numCachedLogMessages() const {
+ return _num_cached_log_messages;
+}
+
Logger *LogCache::logger() const { return _mc->loggerLivestatus(); }
diff --git a/livestatus/src/LogCache.h b/livestatus/src/LogCache.h
index de3d265..138f4d1 100644
--- a/livestatus/src/LogCache.h
+++ b/livestatus/src/LogCache.h
@@ -45,6 +45,7 @@ public:
#ifdef CMC
void setMaxCachedMessages(unsigned long m);
#endif
+ size_t numCachedLogMessages() const;
void logLineHasBeenAdded(Logfile *logfile, unsigned logclasses);
void update();
auto begin() { return _logfiles.begin(); }
@@ -52,6 +53,7 @@ public:
private:
MonitoringCore *const _mc;
+ size_t _num_cached_log_messages;
unsigned long _max_cached_messages;
unsigned long _num_at_last_check;
logfiles_t _logfiles;
diff --git a/livestatus/src/MonitoringCore.h b/livestatus/src/MonitoringCore.h
index 033ba0b..f507fd1 100644
--- a/livestatus/src/MonitoringCore.h
+++ b/livestatus/src/MonitoringCore.h
@@ -120,6 +120,7 @@ public:
virtual size_t numQueuedNotifications() = 0;
virtual size_t numQueuedAlerts() = 0;
+ virtual size_t numCachedLogMessages() = 0;
// Our escape hatch, this should die in the long run...
template <typename T>
diff --git a/livestatus/src/StatusSpecialIntColumn.cc
b/livestatus/src/StatusSpecialIntColumn.cc
index fe7d091..6c5e588 100644
--- a/livestatus/src/StatusSpecialIntColumn.cc
+++ b/livestatus/src/StatusSpecialIntColumn.cc
@@ -39,6 +39,8 @@ int32_t StatusSpecialIntColumn::getValue(Row /* row */,
return static_cast<int32_t>(_mc->numQueuedNotifications());
case Type::num_queued_alerts:
return static_cast<int32_t>(_mc->numQueuedAlerts());
+ case Type::num_cached_log_messages:
+ return static_cast<int32_t>(_mc->numCachedLogMessages());
}
// never reached, make -Wall happy
return 0;
diff --git a/livestatus/src/StatusSpecialIntColumn.h
b/livestatus/src/StatusSpecialIntColumn.h
index c923a97..e6217f9 100644
--- a/livestatus/src/StatusSpecialIntColumn.h
+++ b/livestatus/src/StatusSpecialIntColumn.h
@@ -38,7 +38,8 @@ public:
enum class Type {
mk_inventory_last,
num_queued_notifications,
- num_queued_alerts
+ num_queued_alerts,
+ num_cached_log_messages
};
StatusSpecialIntColumn(const std::string& name,
diff --git a/livestatus/src/Store.cc b/livestatus/src/Store.cc
index 7875659..a862898 100644
--- a/livestatus/src/Store.cc
+++ b/livestatus/src/Store.cc
@@ -23,7 +23,6 @@
// Boston, MA 02110-1301 USA.
#include "Store.h"
-#include <cstring>
#include <ctime>
#include <memory>
#include <sstream>
@@ -311,3 +310,7 @@ bool Store::answerGetRequest(const std::list<std::string>
&lines,
}
Logger *Store::logger() const { return _mc->loggerLivestatus(); }
+
+size_t Store::numCachedLogMessages() const {
+ return _log_cache.numCachedLogMessages();
+}
diff --git a/livestatus/src/Store.h b/livestatus/src/Store.h
index 3fe911f..669ac4d 100644
--- a/livestatus/src/Store.h
+++ b/livestatus/src/Store.h
@@ -26,6 +26,7 @@
#define Store_h
#include "config.h" // IWYU pragma: keep
+#include <cstddef>
#include <list>
#include <map>
#include <string>
@@ -100,6 +101,7 @@ public:
void registerComment(nebstruct_comment_data *data);
#endif
Logger *logger() const;
+ size_t numCachedLogMessages() const;
private:
struct TableDummy : public Table {
diff --git a/livestatus/src/TableStatus.cc b/livestatus/src/TableStatus.cc
index b09aebc..323d915 100644
--- a/livestatus/src/TableStatus.cc
+++ b/livestatus/src/TableStatus.cc
@@ -57,7 +57,6 @@ extern int check_host_freshness;
extern int enable_flap_detection;
extern int process_performance_data;
extern int check_external_commands;
-extern int num_cached_log_messages;
extern int interval_length;
extern int g_num_hosts;
extern int g_num_services;
@@ -212,10 +211,10 @@ TableStatus::TableStatus(MonitoringCore *mc) : Table(mc) {
#endif // NAGIOS4
// Livestatus' own status
- addColumn(std::make_unique<IntPointerColumn>(
+ addColumn(std::make_unique<StatusSpecialIntColumn>(
"cached_log_messages",
- "The current number of log messages MK Livestatus keeps in memory",
- &num_cached_log_messages));
+ "The current number of log messages MK Livestatus keeps in memory",
-1,
+ -1, -1, 0, mc, StatusSpecialIntColumn::Type::num_cached_log_messages));
addColumn(std::make_unique<StringPointerColumn>(
"livestatus_version", "The version of the MK Livestatus
module",
VERSION));
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index 1ce093d..b19f0fb 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -700,6 +700,10 @@ public:
size_t numQueuedNotifications() override { return 0; }
size_t numQueuedAlerts() override { return 0; }
+ size_t numCachedLogMessages() override {
+ return fl_store->numCachedLogMessages();
+ }
+
private:
void *implInternal() const override { return fl_store; }