From 2acaccd028eea620654343808ee69d0c953c0b96 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Mon, 13 Nov 2017 16:17:59 +0100 Subject: [PATCH 1/4] Fix that RingBuffer does not get updated if nothing is written refs #5750 --- lib/base/ringbuffer.cpp | 5 ++++- lib/base/ringbuffer.hpp | 2 +- lib/base/workqueue.cpp | 4 ++-- lib/base/workqueue.hpp | 2 +- lib/db_ido/dbconnection.cpp | 4 ++-- lib/db_ido/dbconnection.hpp | 2 +- lib/icinga/cib.cpp | 8 ++++---- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/base/ringbuffer.cpp b/lib/base/ringbuffer.cpp index 97c00745c..b8bcce93b 100644 --- a/lib/base/ringbuffer.cpp +++ b/lib/base/ringbuffer.cpp @@ -19,6 +19,7 @@ #include "base/ringbuffer.hpp" #include "base/objectlock.hpp" +#include "base/utility.hpp" using namespace icinga; @@ -58,8 +59,10 @@ void RingBuffer::InsertValue(RingBuffer::SizeType tv, int num) m_Slots[offsetTarget] += num; } -int RingBuffer::GetValues(RingBuffer::SizeType span) const +int RingBuffer::UpdateAndGetValues(RingBuffer::SizeType tv, RingBuffer::SizeType span) { + InsertValue(tv, 0); + ObjectLock olock(this); if (span > m_Slots.size()) diff --git a/lib/base/ringbuffer.hpp b/lib/base/ringbuffer.hpp index 11d9b0aea..94063c563 100644 --- a/lib/base/ringbuffer.hpp +++ b/lib/base/ringbuffer.hpp @@ -43,7 +43,7 @@ public: SizeType GetLength(void) const; void InsertValue(SizeType tv, int num); - int GetValues(SizeType span) const; + int UpdateAndGetValues(SizeType tv, SizeType span); private: std::vector m_Slots; diff --git a/lib/base/workqueue.cpp b/lib/base/workqueue.cpp index f3d2a6c32..ffc67802e 100644 --- a/lib/base/workqueue.cpp +++ b/lib/base/workqueue.cpp @@ -296,8 +296,8 @@ void WorkQueue::IncreaseTaskCount(void) m_TaskStats.InsertValue(now, 1); } -int WorkQueue::GetTaskCount(RingBuffer::SizeType span) const +int WorkQueue::GetTaskCount(RingBuffer::SizeType span) { boost::mutex::scoped_lock lock(m_StatsMutex); - return m_TaskStats.GetValues(span); + return m_TaskStats.UpdateAndGetValues(Utility::GetTime(), span); } diff --git a/lib/base/workqueue.hpp b/lib/base/workqueue.hpp index d9ec53bdd..1e8f7b0a1 100644 --- a/lib/base/workqueue.hpp +++ b/lib/base/workqueue.hpp @@ -94,7 +94,7 @@ public: bool IsWorkerThread(void) const; size_t GetLength(void) const; - int GetTaskCount(RingBuffer::SizeType span) const; + int GetTaskCount(RingBuffer::SizeType span); void SetExceptionCallback(const ExceptionCallback& callback); diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index 95b14486d..fac71a7e6 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -474,10 +474,10 @@ void DbConnection::IncreaseQueryCount(void) m_QueryStats.InsertValue(now, 1); } -int DbConnection::GetQueryCount(RingBuffer::SizeType span) const +int DbConnection::GetQueryCount(RingBuffer::SizeType span) { boost::mutex::scoped_lock lock(m_StatsMutex); - return m_QueryStats.GetValues(span); + return m_QueryStats.UpdateAndGetValues(Utility::GetTime(), span); } bool DbConnection::IsIDCacheValid(void) const diff --git a/lib/db_ido/dbconnection.hpp b/lib/db_ido/dbconnection.hpp index 2b1d77d6e..102be19d6 100644 --- a/lib/db_ido/dbconnection.hpp +++ b/lib/db_ido/dbconnection.hpp @@ -73,7 +73,7 @@ public: void SetStatusUpdate(const DbObject::Ptr& dbobj, bool hasupdate); bool GetStatusUpdate(const DbObject::Ptr& dbobj) const; - int GetQueryCount(RingBuffer::SizeType span) const; + int GetQueryCount(RingBuffer::SizeType span); virtual int GetPendingQueryCount(void) const = 0; virtual void ValidateFailoverTimeout(double value, const ValidationUtils& utils) override; diff --git a/lib/icinga/cib.cpp b/lib/icinga/cib.cpp index 293701937..07201a167 100644 --- a/lib/icinga/cib.cpp +++ b/lib/icinga/cib.cpp @@ -45,12 +45,12 @@ void CIB::UpdateActiveServiceChecksStatistics(long tv, int num) int CIB::GetActiveHostChecksStatistics(long timespan) { - return m_ActiveHostChecksStatistics.GetValues(timespan); + return m_ActiveHostChecksStatistics.UpdateAndGetValues(Utility::GetTime(), timespan); } int CIB::GetActiveServiceChecksStatistics(long timespan) { - return m_ActiveServiceChecksStatistics.GetValues(timespan); + return m_ActiveServiceChecksStatistics.UpdateAndGetValues(Utility::GetTime(), timespan); } void CIB::UpdatePassiveHostChecksStatistics(long tv, int num) @@ -65,12 +65,12 @@ void CIB::UpdatePassiveServiceChecksStatistics(long tv, int num) int CIB::GetPassiveHostChecksStatistics(long timespan) { - return m_PassiveHostChecksStatistics.GetValues(timespan); + return m_PassiveHostChecksStatistics.UpdateAndGetValues(Utility::GetTime(), timespan); } int CIB::GetPassiveServiceChecksStatistics(long timespan) { - return m_PassiveServiceChecksStatistics.GetValues(timespan); + return m_PassiveServiceChecksStatistics.UpdateAndGetValues(Utility::GetTime(), timespan); } CheckableCheckStatistics CIB::CalculateHostCheckStats(void) From 054faa54d56ed713ebb72abda5845be2a0edf3c6 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Mon, 13 Nov 2017 16:26:21 +0100 Subject: [PATCH 2/4] Return bytes sent/written in SendMessage() and WriteStringToStream() refs #5509 --- lib/base/netstring.cpp | 7 +++++-- lib/base/netstring.hpp | 2 +- lib/remote/jsonrpc.cpp | 8 +++++--- lib/remote/jsonrpc.hpp | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/base/netstring.cpp b/lib/base/netstring.cpp index 934097e2b..dce0208df 100644 --- a/lib/base/netstring.cpp +++ b/lib/base/netstring.cpp @@ -102,18 +102,21 @@ StreamReadStatus NetString::ReadStringFromStream(const Stream::Ptr& stream, Stri } /** - * Writes data into a stream using the netstring format. + * Writes data into a stream using the netstring format and returns bytes written. * * @param stream The stream. * @param str The String that is to be written. + * + * @return The amount of bytes written. */ -void NetString::WriteStringToStream(const Stream::Ptr& stream, const String& str) +size_t NetString::WriteStringToStream(const Stream::Ptr& stream, const String& str) { std::ostringstream msgbuf; WriteStringToStream(msgbuf, str); String msg = msgbuf.str(); stream->Write(msg.CStr(), msg.GetLength()); + return msg.GetLength(); } /** diff --git a/lib/base/netstring.hpp b/lib/base/netstring.hpp index c24cba028..e0d0f4082 100644 --- a/lib/base/netstring.hpp +++ b/lib/base/netstring.hpp @@ -39,7 +39,7 @@ class I2_BASE_API NetString { public: static StreamReadStatus ReadStringFromStream(const Stream::Ptr& stream, String *message, StreamReadContext& context, bool may_wait = false); - static void WriteStringToStream(const Stream::Ptr& stream, const String& message); + static size_t WriteStringToStream(const Stream::Ptr& stream, const String& message); static void WriteStringToStream(std::ostream& stream, const String& message); private: diff --git a/lib/remote/jsonrpc.cpp b/lib/remote/jsonrpc.cpp index 1d3efd5ca..c05a85c2b 100644 --- a/lib/remote/jsonrpc.cpp +++ b/lib/remote/jsonrpc.cpp @@ -54,11 +54,13 @@ static bool GetDebugJsonRpcCached(void) #endif /* I2_DEBUG */ /** - * Sends a message to the connected peer. + * Sends a message to the connected peer and returns the bytes sent. * * @param message The message. + * + * @return The amount of bytes sent. */ -void JsonRpc::SendMessage(const Stream::Ptr& stream, const Dictionary::Ptr& message) +size_t JsonRpc::SendMessage(const Stream::Ptr& stream, const Dictionary::Ptr& message) { String json = JsonEncode(message); @@ -67,7 +69,7 @@ void JsonRpc::SendMessage(const Stream::Ptr& stream, const Dictionary::Ptr& mess std::cerr << ConsoleColorTag(Console_ForegroundBlue) << ">> " << json << ConsoleColorTag(Console_Normal) << "\n"; #endif /* I2_DEBUG */ - NetString::WriteStringToStream(stream, json); + return NetString::WriteStringToStream(stream, json); } StreamReadStatus JsonRpc::ReadMessage(const Stream::Ptr& stream, String *message, StreamReadContext& src, bool may_wait) diff --git a/lib/remote/jsonrpc.hpp b/lib/remote/jsonrpc.hpp index 3589b365a..df19e2222 100644 --- a/lib/remote/jsonrpc.hpp +++ b/lib/remote/jsonrpc.hpp @@ -35,7 +35,7 @@ namespace icinga class I2_REMOTE_API JsonRpc { public: - static void SendMessage(const Stream::Ptr& stream, const Dictionary::Ptr& message); + static size_t SendMessage(const Stream::Ptr& stream, const Dictionary::Ptr& message); static StreamReadStatus ReadMessage(const Stream::Ptr& stream, String *message, StreamReadContext& src, bool may_wait = false); static Dictionary::Ptr DecodeMessage(const String& message); From c10f0a639b6aa63fa35e6f79b789538b613ed18c Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Tue, 14 Nov 2017 11:03:05 +0100 Subject: [PATCH 3/4] RingBuffer: Add CalculateRate() refs #5750 --- lib/base/ringbuffer.cpp | 18 ++++++++++++++++-- lib/base/ringbuffer.hpp | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/base/ringbuffer.cpp b/lib/base/ringbuffer.cpp index b8bcce93b..4e023e7ab 100644 --- a/lib/base/ringbuffer.cpp +++ b/lib/base/ringbuffer.cpp @@ -20,11 +20,12 @@ #include "base/ringbuffer.hpp" #include "base/objectlock.hpp" #include "base/utility.hpp" +#include using namespace icinga; RingBuffer::RingBuffer(RingBuffer::SizeType slots) - : Object(), m_Slots(slots, 0), m_TimeValue(0) + : Object(), m_Slots(slots, 0), m_TimeValue(0), m_InsertedValues(0) { } RingBuffer::SizeType RingBuffer::GetLength(void) const @@ -40,6 +41,9 @@ void RingBuffer::InsertValue(RingBuffer::SizeType tv, int num) RingBuffer::SizeType offsetTarget = tv % m_Slots.size(); + if (m_TimeValue == 0) + m_InsertedValues = 1; + if (tv > m_TimeValue) { RingBuffer::SizeType offset = m_TimeValue % m_Slots.size(); @@ -51,6 +55,9 @@ void RingBuffer::InsertValue(RingBuffer::SizeType tv, int num) offset = 0; m_Slots[offset] = 0; + + if (m_TimeValue != 0 && m_InsertedValues < m_Slots.size()) + m_InsertedValues++; } m_TimeValue = tv; @@ -68,7 +75,7 @@ int RingBuffer::UpdateAndGetValues(RingBuffer::SizeType tv, RingBuffer::SizeType if (span > m_Slots.size()) span = m_Slots.size(); - int off = m_TimeValue % m_Slots.size();; + int off = m_TimeValue % m_Slots.size(); int sum = 0; while (span > 0) { sum += m_Slots[off]; @@ -82,3 +89,10 @@ int RingBuffer::UpdateAndGetValues(RingBuffer::SizeType tv, RingBuffer::SizeType return sum; } + +double RingBuffer::CalculateRate(RingBuffer::SizeType tv, RingBuffer::SizeType span) +{ + ObjectLock olock(this); + int sum = UpdateAndGetValues(tv, span); + return sum / static_cast(std::min(span, m_InsertedValues)); +} diff --git a/lib/base/ringbuffer.hpp b/lib/base/ringbuffer.hpp index 94063c563..d81515858 100644 --- a/lib/base/ringbuffer.hpp +++ b/lib/base/ringbuffer.hpp @@ -44,10 +44,12 @@ public: SizeType GetLength(void) const; void InsertValue(SizeType tv, int num); int UpdateAndGetValues(SizeType tv, SizeType span); + double CalculateRate(SizeType tv, SizeType span); private: std::vector m_Slots; SizeType m_TimeValue; + SizeType m_InsertedValues; }; } From 5519626f84de0f762b410100cfee2b8da93c4bec Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Mon, 13 Nov 2017 16:30:29 +0100 Subject: [PATCH 4/4] Add metrics about communication between endpoints refs #5509 --- lib/base/ringbuffer.cpp | 4 +-- lib/methods/clusterzonechecktask.cpp | 24 +++++++++++++++++ lib/methods/icingachecktask.cpp | 30 +++++++++++++++++++++ lib/remote/apilistener.cpp | 6 +++-- lib/remote/endpoint.cpp | 40 ++++++++++++++++++++++++++++ lib/remote/endpoint.hpp | 17 ++++++++++++ lib/remote/endpoint.ti | 19 +++++++++++++ lib/remote/jsonrpcconnection.cpp | 5 +++- 8 files changed, 140 insertions(+), 5 deletions(-) diff --git a/lib/base/ringbuffer.cpp b/lib/base/ringbuffer.cpp index 4e023e7ab..660dc820b 100644 --- a/lib/base/ringbuffer.cpp +++ b/lib/base/ringbuffer.cpp @@ -68,10 +68,10 @@ void RingBuffer::InsertValue(RingBuffer::SizeType tv, int num) int RingBuffer::UpdateAndGetValues(RingBuffer::SizeType tv, RingBuffer::SizeType span) { - InsertValue(tv, 0); - ObjectLock olock(this); + InsertValue(tv, 0); + if (span > m_Slots.size()) span = m_Slots.size(); diff --git a/lib/methods/clusterzonechecktask.cpp b/lib/methods/clusterzonechecktask.cpp index 919e7fbed..b3bf66a5d 100644 --- a/lib/methods/clusterzonechecktask.cpp +++ b/lib/methods/clusterzonechecktask.cpp @@ -91,6 +91,13 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che bool connected = false; double zoneLag = 0; + double lastMessageSent = 0; + double lastMessageReceived = 0; + double messagesSentPerSecond = 0; + double messagesReceivedPerSecond = 0; + double bytesSentPerSecond = 0; + double bytesReceivedPerSecond = 0; + for (const Endpoint::Ptr& endpoint : zone->GetEndpoints()) { if (endpoint->GetConnected()) connected = true; @@ -99,6 +106,17 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che if (eplag > 0 && eplag > zoneLag) zoneLag = eplag; + + if (endpoint->GetLastMessageSent() > lastMessageSent) + lastMessageSent = endpoint->GetLastMessageSent(); + + if (endpoint->GetLastMessageReceived() > lastMessageReceived) + lastMessageReceived = endpoint->GetLastMessageReceived(); + + messagesSentPerSecond += endpoint->GetMessagesSentPerSecond(); + messagesReceivedPerSecond += endpoint->GetMessagesReceivedPerSecond(); + bytesSentPerSecond += endpoint->GetBytesSentPerSecond(); + bytesReceivedPerSecond += endpoint->GetBytesReceivedPerSecond(); } if (!connected) { @@ -122,6 +140,12 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che Array::Ptr perfdata = new Array(); perfdata->Add(new PerfdataValue("slave_lag", zoneLag, false, "s", lagWarning, lagCritical)); + perfdata->Add(new PerfdataValue("last_messages_sent", lastMessageSent)); + perfdata->Add(new PerfdataValue("last_messages_received", lastMessageReceived)); + 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)); + perfdata->Add(new PerfdataValue("sum_bytes_received_per_second", bytesReceivedPerSecond)); cr->SetPerformanceData(perfdata); checkable->ProcessCheckResult(cr); diff --git a/lib/methods/icingachecktask.cpp b/lib/methods/icingachecktask.cpp index 3a4b668a9..a51809828 100644 --- a/lib/methods/icingachecktask.cpp +++ b/lib/methods/icingachecktask.cpp @@ -100,6 +100,36 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResul perfdata->Add(new PerfdataValue("num_hosts_in_downtime", hs.hosts_in_downtime)); perfdata->Add(new PerfdataValue("num_hosts_acknowledged", hs.hosts_acknowledged)); + std::vector endpoints = ConfigType::GetObjectsByType(); + + double lastMessageSent = 0; + double lastMessageReceived = 0; + double messagesSentPerSecond = 0; + double messagesReceivedPerSecond = 0; + double bytesSentPerSecond = 0; + double bytesReceivedPerSecond = 0; + + for (Endpoint::Ptr endpoint : endpoints) + { + if (endpoint->GetLastMessageSent() > lastMessageSent) + lastMessageSent = endpoint->GetLastMessageSent(); + + if (endpoint->GetLastMessageReceived() > lastMessageReceived) + lastMessageReceived = endpoint->GetLastMessageReceived(); + + messagesSentPerSecond += endpoint->GetMessagesSentPerSecond(); + messagesReceivedPerSecond += endpoint->GetMessagesReceivedPerSecond(); + bytesSentPerSecond += endpoint->GetBytesSentPerSecond(); + bytesReceivedPerSecond += endpoint->GetBytesReceivedPerSecond(); + } + + perfdata->Add(new PerfdataValue("last_messages_sent", lastMessageSent)); + perfdata->Add(new PerfdataValue("last_messages_received", lastMessageReceived)); + 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)); + perfdata->Add(new PerfdataValue("sum_bytes_received_per_second", bytesReceivedPerSecond)); + cr->SetOutput("Icinga 2 has been running for " + Utility::FormatDuration(uptime) + ". Version: " + Application::GetAppVersion()); cr->SetPerformanceData(perfdata); diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 86cc79759..6743b6e70 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -1144,7 +1144,8 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client) } try { - NetString::WriteStringToStream(client->GetStream(), pmessage->Get("message")); + size_t bytesSent = NetString::WriteStringToStream(client->GetStream(), pmessage->Get("message")); + endpoint->AddMessageSent(bytesSent); count++; } catch (const std::exception& ex) { Log(LogWarning, "ApiListener") @@ -1169,7 +1170,8 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client) lmessage->Set("method", "log::SetLogPosition"); lmessage->Set("params", lparams); - JsonRpc::SendMessage(client->GetStream(), lmessage); + size_t bytesSent = JsonRpc::SendMessage(client->GetStream(), lmessage); + endpoint->AddMessageSent(bytesSent); } } diff --git a/lib/remote/endpoint.cpp b/lib/remote/endpoint.cpp index e922cd09c..b231be165 100644 --- a/lib/remote/endpoint.cpp +++ b/lib/remote/endpoint.cpp @@ -34,6 +34,10 @@ REGISTER_TYPE(Endpoint); boost::signals2::signal Endpoint::OnConnected; boost::signals2::signal Endpoint::OnDisconnected; +Endpoint::Endpoint(void) + : m_MessagesSent(60), m_BytesSent(60), m_MessagesReceived(60), m_BytesReceived(60) +{ } + void Endpoint::OnAllConfigLoaded(void) { ObjectImpl::OnAllConfigLoaded(); @@ -117,3 +121,39 @@ Endpoint::Ptr Endpoint::GetLocalEndpoint(void) return listener->GetLocalEndpoint(); } + +void Endpoint::AddMessageSent(int bytes) +{ + double time = Utility::GetTime(); + m_MessagesSent.InsertValue(time, 1); + m_BytesSent.InsertValue(time, bytes); + SetLastMessageSent(time); +} + +void Endpoint::AddMessageReceived(int bytes) +{ + double time = Utility::GetTime(); + m_MessagesReceived.InsertValue(time, 1); + m_BytesReceived.InsertValue(time, bytes); + SetLastMessageReceived(time); +} + +double Endpoint::GetMessagesSentPerSecond(void) const +{ + return m_MessagesSent.CalculateRate(Utility::GetTime(), 60); +} + +double Endpoint::GetMessagesReceivedPerSecond(void) const +{ + return m_MessagesReceived.CalculateRate(Utility::GetTime(), 60); +} + +double Endpoint::GetBytesSentPerSecond(void) const +{ + return m_BytesSent.CalculateRate(Utility::GetTime(), 60); +} + +double Endpoint::GetBytesReceivedPerSecond(void) const +{ + return m_BytesReceived.CalculateRate(Utility::GetTime(), 60); +} diff --git a/lib/remote/endpoint.hpp b/lib/remote/endpoint.hpp index 380c1e5c2..5570ea5b5 100644 --- a/lib/remote/endpoint.hpp +++ b/lib/remote/endpoint.hpp @@ -22,6 +22,7 @@ #include "remote/i2-remote.hpp" #include "remote/endpoint.thpp" +#include "base/ringbuffer.hpp" #include namespace icinga @@ -41,6 +42,8 @@ public: DECLARE_OBJECT(Endpoint); DECLARE_OBJECTNAME(Endpoint); + Endpoint(void); + static boost::signals2::signal&)> OnConnected; static boost::signals2::signal&)> OnDisconnected; @@ -56,6 +59,15 @@ public: void SetCachedZone(const intrusive_ptr& zone); + void AddMessageSent(int bytes); + void AddMessageReceived(int bytes); + + double GetMessagesSentPerSecond(void) const override; + double GetMessagesReceivedPerSecond(void) const override; + + double GetBytesSentPerSecond(void) const override; + double GetBytesReceivedPerSecond(void) const override; + protected: virtual void OnAllConfigLoaded(void) override; @@ -63,6 +75,11 @@ private: mutable boost::mutex m_ClientsLock; std::set > m_Clients; intrusive_ptr m_Zone; + + mutable RingBuffer m_MessagesSent; + mutable RingBuffer m_MessagesReceived; + mutable RingBuffer m_BytesSent; + mutable RingBuffer m_BytesReceived; }; } diff --git a/lib/remote/endpoint.ti b/lib/remote/endpoint.ti index edf9a58f0..e69642003 100644 --- a/lib/remote/endpoint.ti +++ b/lib/remote/endpoint.ti @@ -45,6 +45,25 @@ class Endpoint : ConfigObject [no_user_modify, no_storage] bool connected { get; }; + + Timestamp last_message_sent; + Timestamp last_message_received; + + [no_user_modify, no_storage] double messages_sent_per_second { + get; + }; + + [no_user_modify, no_storage] double messages_received_per_second { + get; + }; + + [no_user_modify, no_storage] double bytes_sent_per_second { + get; + }; + + [no_user_modify, no_storage] double bytes_received_per_second { + get; + }; }; } diff --git a/lib/remote/jsonrpcconnection.cpp b/lib/remote/jsonrpcconnection.cpp index 3d9cacaf0..23e9e27ac 100644 --- a/lib/remote/jsonrpcconnection.cpp +++ b/lib/remote/jsonrpcconnection.cpp @@ -111,7 +111,8 @@ void JsonRpcConnection::SendMessage(const Dictionary::Ptr& message) ObjectLock olock(m_Stream); if (m_Stream->IsEof()) return; - JsonRpc::SendMessage(m_Stream, message); + size_t bytesSent = JsonRpc::SendMessage(m_Stream, message); + m_Endpoint->AddMessageSent(bytesSent); } catch (const std::exception& ex) { std::ostringstream info; info << "Error while sending JSON-RPC message for identity '" << m_Identity << "'"; @@ -182,6 +183,8 @@ void JsonRpcConnection::MessageHandler(const String& jsonString) origin->FromZone = m_Endpoint->GetZone(); else origin->FromZone = Zone::GetByName(message->Get("originZone")); + + m_Endpoint->AddMessageReceived(jsonString.GetLength()); } Value vmethod;