Skip to content

Commit

Permalink
Introduce Endpoint#pending_outgoing_messages for the API
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Dec 11, 2024
1 parent 8228f8c commit f722f8b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/methods/clusterzonechecktask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions lib/methods/icingachecktask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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));
Expand Down
12 changes: 12 additions & 0 deletions lib/remote/endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions lib/remote/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Endpoint final : public ObjectImpl<Endpoint>
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);
Expand Down
4 changes: 4 additions & 0 deletions lib/remote/endpoint.ti
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit f722f8b

Please sign in to comment.