mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 13:45:04 +02:00
Combine all Redis connections' logs
This commit is contained in:
parent
e6a9631a02
commit
67c4ebedd3
@ -63,7 +63,7 @@ void IcingaDB::Start(bool runtimeCreated)
|
||||
if (!ctype)
|
||||
continue;
|
||||
|
||||
RedisConnection::Ptr rCon (new RedisConnection(GetHost(), GetPort(), GetPath(), GetPassword(), GetDbIndex()));
|
||||
RedisConnection::Ptr rCon (new RedisConnection(GetHost(), GetPort(), GetPath(), GetPassword(), GetDbIndex(), m_Rcon));
|
||||
rCon->Start();
|
||||
m_Rcons[ctype] = std::move(rCon);
|
||||
}
|
||||
|
@ -24,15 +24,17 @@
|
||||
using namespace icinga;
|
||||
namespace asio = boost::asio;
|
||||
|
||||
RedisConnection::RedisConnection(const String& host, const int port, const String& path, const String& password, const int db) :
|
||||
RedisConnection(IoEngine::Get().GetIoContext(), host, port, path, password, db)
|
||||
RedisConnection::RedisConnection(const String& host, const int port, const String& path,
|
||||
const String& password, const int db, const RedisConnection::Ptr& parent) :
|
||||
RedisConnection(IoEngine::Get().GetIoContext(), host, port, path, password, db, parent)
|
||||
{
|
||||
}
|
||||
|
||||
RedisConnection::RedisConnection(boost::asio::io_context& io, String host, int port, String path, String password, int db)
|
||||
RedisConnection::RedisConnection(boost::asio::io_context& io, String host, int port, String path,
|
||||
String password, int db, const RedisConnection::Ptr& parent)
|
||||
: m_Host(std::move(host)), m_Port(port), m_Path(std::move(path)), m_Password(std::move(password)), m_DbIndex(db),
|
||||
m_Connecting(false), m_Connected(false), m_Started(false), m_Strand(io),
|
||||
m_QueuedWrites(io), m_QueuedReads(io), m_LogStatsTimer(io)
|
||||
m_QueuedWrites(io), m_QueuedReads(io), m_LogStatsTimer(io), m_Parent(parent)
|
||||
{
|
||||
}
|
||||
|
||||
@ -43,7 +45,10 @@ void RedisConnection::Start()
|
||||
|
||||
IoEngine::SpawnCoroutine(m_Strand, [this, keepAlive](asio::yield_context yc) { ReadLoop(yc); });
|
||||
IoEngine::SpawnCoroutine(m_Strand, [this, keepAlive](asio::yield_context yc) { WriteLoop(yc); });
|
||||
IoEngine::SpawnCoroutine(m_Strand, [this, keepAlive](asio::yield_context yc) { LogStats(yc); });
|
||||
|
||||
if (!m_Parent) {
|
||||
IoEngine::SpawnCoroutine(m_Strand, [this, keepAlive](asio::yield_context yc) { LogStats(yc); });
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_Connecting.exchange(true)) {
|
||||
@ -588,12 +593,28 @@ void RedisConnection::SetConnectedCallback(std::function<void(asio::yield_contex
|
||||
|
||||
void RedisConnection::IncreasePendingQueries(int count)
|
||||
{
|
||||
m_PendingQueries += count;
|
||||
m_InputQueries.InsertValue(Utility::GetTime(), count);
|
||||
if (m_Parent) {
|
||||
auto parent (m_Parent);
|
||||
|
||||
asio::post(parent->m_Strand, [parent, count]() {
|
||||
parent->IncreasePendingQueries(count);
|
||||
});
|
||||
} else {
|
||||
m_PendingQueries += count;
|
||||
m_InputQueries.InsertValue(Utility::GetTime(), count);
|
||||
}
|
||||
}
|
||||
|
||||
void RedisConnection::DecreasePendingQueries(int count)
|
||||
{
|
||||
m_PendingQueries -= count;
|
||||
m_OutputQueries.InsertValue(Utility::GetTime(), count);
|
||||
if (m_Parent) {
|
||||
auto parent (m_Parent);
|
||||
|
||||
asio::post(parent->m_Strand, [parent, count]() {
|
||||
parent->DecreasePendingQueries(count);
|
||||
});
|
||||
} else {
|
||||
m_PendingQueries -= count;
|
||||
m_OutputQueries.InsertValue(Utility::GetTime(), count);
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ namespace icinga
|
||||
};
|
||||
|
||||
RedisConnection(const String& host, const int port, const String& path,
|
||||
const String& password = "", const int db = 0);
|
||||
const String& password = "", const int db = 0, const Ptr& parent = nullptr);
|
||||
|
||||
void Start();
|
||||
|
||||
@ -143,7 +143,8 @@ namespace icinga
|
||||
template<class AsyncWriteStream>
|
||||
static void WriteRESP(AsyncWriteStream& stream, const Query& query, boost::asio::yield_context& yc);
|
||||
|
||||
RedisConnection(boost::asio::io_context& io, String host, int port, String path, String password, int db);
|
||||
RedisConnection(boost::asio::io_context& io, String host, int port, String path,
|
||||
String password, int db, const Ptr& parent);
|
||||
|
||||
void Connect(boost::asio::yield_context& yc);
|
||||
void ReadLoop(boost::asio::yield_context& yc);
|
||||
@ -197,6 +198,7 @@ namespace icinga
|
||||
RingBuffer m_OutputQueries{10};
|
||||
int m_PendingQueries{0};
|
||||
boost::asio::deadline_timer m_LogStatsTimer;
|
||||
Ptr m_Parent;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user