mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-29 08:34:20 +02:00
IcingaDB: use XADD MAXLEN instead of custom Lua script for heartbeats
The existing Lua script adds a new entry to a stream and then deletes all older entries. The same can be achieved by using `XADD ... MAXLEN 1`.
This commit is contained in:
parent
9dd210df84
commit
a5dc52dea5
@ -17,25 +17,6 @@ using namespace icinga;
|
|||||||
|
|
||||||
using Prio = RedisConnection::QueryPriority;
|
using Prio = RedisConnection::QueryPriority;
|
||||||
|
|
||||||
static const char * const l_LuaPublishStats = R"EOF(
|
|
||||||
|
|
||||||
local xa = {'XADD', KEYS[1], '*'}
|
|
||||||
|
|
||||||
for i = 1, #ARGV do
|
|
||||||
table.insert(xa, ARGV[i])
|
|
||||||
end
|
|
||||||
|
|
||||||
local id = redis.call(unpack(xa))
|
|
||||||
|
|
||||||
local xr = redis.call('XRANGE', KEYS[1], '-', '+')
|
|
||||||
for i = 1, #xr - 1 do
|
|
||||||
redis.call('XDEL', KEYS[1], xr[i][1])
|
|
||||||
end
|
|
||||||
|
|
||||||
return id
|
|
||||||
|
|
||||||
)EOF";
|
|
||||||
|
|
||||||
String IcingaDB::m_EnvironmentId;
|
String IcingaDB::m_EnvironmentId;
|
||||||
boost::once_flag IcingaDB::m_EnvironmentIdOnce = BOOST_ONCE_INIT;
|
boost::once_flag IcingaDB::m_EnvironmentIdOnce = BOOST_ONCE_INIT;
|
||||||
|
|
||||||
@ -129,17 +110,17 @@ void IcingaDB::PublishStats()
|
|||||||
status->Set("config_dump_in_progress", m_ConfigDumpInProgress);
|
status->Set("config_dump_in_progress", m_ConfigDumpInProgress);
|
||||||
status->Set("timestamp", TimestampToMilliseconds(Utility::GetTime()));
|
status->Set("timestamp", TimestampToMilliseconds(Utility::GetTime()));
|
||||||
|
|
||||||
std::vector<String> eval ({"EVAL", l_LuaPublishStats, "1", "icinga:stats"});
|
std::vector<String> query {"XADD", "icinga:stats", "MAXLEN", "1", "*"};
|
||||||
|
|
||||||
{
|
{
|
||||||
ObjectLock statusLock (status);
|
ObjectLock statusLock (status);
|
||||||
for (auto& kv : status) {
|
for (auto& kv : status) {
|
||||||
eval.emplace_back(kv.first);
|
query.emplace_back(kv.first);
|
||||||
eval.emplace_back(JsonEncode(kv.second));
|
query.emplace_back(JsonEncode(kv.second));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Rcon->FireAndForgetQuery(std::move(eval), Prio::Heartbeat);
|
m_Rcon->FireAndForgetQuery(std::move(query), Prio::Heartbeat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IcingaDB::Stop(bool runtimeRemoved)
|
void IcingaDB::Stop(bool runtimeRemoved)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user