Introduce Endpoint#pending_outgoing_messages for the API

This commit is contained in:
Alexander A. Klimov 2024-12-11 17:21:08 +01:00
parent 1a723a477a
commit 37c50c1fee
5 changed files with 23 additions and 0 deletions

View File

@ -133,6 +133,7 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
double lastMessageSent = 0;
double lastMessageReceived = 0;
uint_fast64_t pendingOutgoingMessages = 0;
double messagesSentPerSecond = 0;
double messagesReceivedPerSecond = 0;
double bytesSentPerSecond = 0;
@ -156,6 +157,7 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
if (endpoint->GetLastMessageReceived() > lastMessageReceived)
lastMessageReceived = endpoint->GetLastMessageReceived();
pendingOutgoingMessages += endpoint->GetPendingOutgoingMessages();
messagesSentPerSecond += endpoint->GetMessagesSentPerSecond();
messagesReceivedPerSecond += endpoint->GetMessagesReceivedPerSecond();
bytesSentPerSecond += endpoint->GetBytesSentPerSecond();
@ -207,6 +209,7 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
new PerfdataValue("slave_lag", zoneLag, false, "s", lagWarning, lagCritical),
new PerfdataValue("last_messages_sent", lastMessageSent),
new PerfdataValue("last_messages_received", lastMessageReceived),
new PerfdataValue("sum_pending_outgoing_messages", pendingOutgoingMessages),
new PerfdataValue("sum_messages_sent_per_second", messagesSentPerSecond),
new PerfdataValue("sum_messages_received_per_second", messagesReceivedPerSecond),
new PerfdataValue("sum_bytes_sent_per_second", bytesSentPerSecond),

View File

@ -123,6 +123,7 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
double lastMessageSent = 0;
double lastMessageReceived = 0;
uint_fast64_t pendingOutgoingMessages = 0;
double messagesSentPerSecond = 0;
double messagesReceivedPerSecond = 0;
double bytesSentPerSecond = 0;
@ -136,6 +137,7 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
if (endpoint->GetLastMessageReceived() > lastMessageReceived)
lastMessageReceived = endpoint->GetLastMessageReceived();
pendingOutgoingMessages += endpoint->GetPendingOutgoingMessages();
messagesSentPerSecond += endpoint->GetMessagesSentPerSecond();
messagesReceivedPerSecond += endpoint->GetMessagesReceivedPerSecond();
bytesSentPerSecond += endpoint->GetBytesSentPerSecond();
@ -144,6 +146,7 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
perfdata->Add(new PerfdataValue("last_messages_sent", lastMessageSent));
perfdata->Add(new PerfdataValue("last_messages_received", lastMessageReceived));
perfdata->Add(new PerfdataValue("sum_pending_outgoing_messages", pendingOutgoingMessages));
perfdata->Add(new PerfdataValue("sum_messages_sent_per_second", messagesSentPerSecond));
perfdata->Add(new PerfdataValue("sum_messages_received_per_second", messagesReceivedPerSecond));
perfdata->Add(new PerfdataValue("sum_bytes_sent_per_second", bytesSentPerSecond));

View File

@ -101,6 +101,18 @@ Endpoint::Ptr Endpoint::GetLocalEndpoint()
return listener->GetLocalEndpoint();
}
uint_fast64_t Endpoint::GetPendingOutgoingMessages() const
{
uint_fast64_t pending = 0;
std::unique_lock lock (m_ClientsLock);
for (auto& client : m_Clients) {
pending += client->GetPendingOutgoingMessages();
}
return pending;
}
void Endpoint::AddMessageSent(int bytes)
{
double time = Utility::GetTime();

View File

@ -39,6 +39,7 @@ public:
static Endpoint::Ptr GetLocalEndpoint();
void SetCachedZone(const intrusive_ptr<Zone>& zone);
uint_fast64_t GetPendingOutgoingMessages() const override;
void AddMessageSent(int bytes);
void AddMessageReceived(int bytes);

View File

@ -39,6 +39,10 @@ class Endpoint : ConfigObject
Timestamp last_message_sent;
Timestamp last_message_received;
[no_user_modify, no_storage] uint_fast64_t pending_outgoing_messages {
get;
};
[no_user_modify, no_storage] double messages_sent_per_second {
get;
};