From 84920baeaf493ffcaf23a17795acd504bf5cef1b Mon Sep 17 00:00:00 2001 From: Derek Weitzel Date: Fri, 29 May 2020 08:34:57 -0500 Subject: [PATCH] Update monitor function signature XRootD change the function signature in xrootd/xrootd@314852ea0d40e14e59aab9f299b10417dd83d1ca --- src/tcpstats.cpp | 13 ++++++++----- src/tcpstats.h | 12 ++++++------ test/main.cpp | 10 ++++++++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/tcpstats.cpp b/src/tcpstats.cpp index 4cbecb0..4941bd9 100644 --- a/src/tcpstats.cpp +++ b/src/tcpstats.cpp @@ -8,7 +8,7 @@ XrdVERSIONINFO(TcpMonPin,XRootDTCP); -XrdTcpMonPin* TcpMonPin::getInstance(const char *parms, +XrdTcpMonPin* myPinObject::getInstance(const char *parms, XrdOucEnv &envR, XrdSysLogger &logR, XrdTcpMonPin *prevP) @@ -26,14 +26,15 @@ TCPStats::TCPStats(XrdXrootdGStream* gs) this->stream = gs; } -void TCPStats::Monitor(int fd, XrdNetAddrInfo &netInfo, const char *tident) +void TCPStats::Monitor(XrdNetAddrInfo &netInfo, XrdTcpMonPin::LinkInfo &lnkInfo, int liLen) { + tcp_info tcp_info; socklen_t tcp_info_length = sizeof(tcp_info); - int sockopt_rc = getsockopt( fd, SOL_TCP, TCP_INFO, (void *)&tcp_info, &tcp_info_length ); + int sockopt_rc = getsockopt( lnkInfo.fd, SOL_TCP, TCP_INFO, (void *)&tcp_info, &tcp_info_length ); if ( sockopt_rc == 0 ) { - std::string returnedJSON = TCPStats::GenerateJSON(tcp_info, netInfo); + std::string returnedJSON = TCPStats::GenerateJSON(tcp_info, netInfo, lnkInfo.bytesIn, lnkInfo.bytesOut); // Insert the JSON into the gstream // Include the null terminated character in the count @@ -43,7 +44,7 @@ void TCPStats::Monitor(int fd, XrdNetAddrInfo &netInfo, const char *tident) } -std::string TCPStats::GenerateJSON(tcp_info& tcp_info, XrdNetAddrInfo& netInfo) +std::string TCPStats::GenerateJSON(tcp_info& tcp_info, XrdNetAddrInfo& netInfo, long long bytesIn, long long bytesOut) { picojson::object wrapper; wrapper["type"] = picojson::value("tcpstats"); @@ -60,6 +61,8 @@ std::string TCPStats::GenerateJSON(tcp_info& tcp_info, XrdNetAddrInfo& netInfo) wrapper["lost"] = picojson::value(static_cast(tcp_info.tcpi_lost)); wrapper["retrans"] = picojson::value(static_cast(tcp_info.tcpi_retrans)); wrapper["reordering"] = picojson::value(static_cast(tcp_info.tcpi_reordering)); + wrapper["bytes_in"] = picojson::value(static_cast(bytesIn)); + wrapper["bytes_out"] = picojson::value(static_cast(bytesOut)); return picojson::value(wrapper).serialize(); } diff --git a/src/tcpstats.h b/src/tcpstats.h index 0e302d0..97e9965 100644 --- a/src/tcpstats.h +++ b/src/tcpstats.h @@ -12,8 +12,8 @@ class TCPStats: public XrdTcpMonPin { public: - void Monitor(int fd, XrdNetAddrInfo &netInfo, const char *tident); - static std::string GenerateJSON(tcp_info& tcp_info, XrdNetAddrInfo& netInfo); + void Monitor(XrdNetAddrInfo &netInfo, XrdTcpMonPin::LinkInfo &lnkInfo, int liLen); + static std::string GenerateJSON(tcp_info& tcp_info, XrdNetAddrInfo& netInfo, long long bytesIn, long long bytesOut); TCPStats(XrdXrootdGStream* gs); virtual ~TCPStats() {}; @@ -24,13 +24,13 @@ class TCPStats: public XrdTcpMonPin { }; -class TcpMonPin : public XrdOucPinObject +class myPinObject : public XrdOucPinObject { public: - TcpMonPin() {}; - virtual ~TcpMonPin() {}; + myPinObject() {}; + virtual ~myPinObject() {}; XrdTcpMonPin *getInstance(const char *parms, XrdOucEnv &envR, XrdSysLogger &logR, XrdTcpMonPin *prevP); -}; \ No newline at end of file +} TcpMonPin; \ No newline at end of file diff --git a/test/main.cpp b/test/main.cpp index 2eabd0c..82f37d2 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -38,7 +38,7 @@ class TCPTest : public ::testing::Test { m_logger = std::unique_ptr(new XrdSysLogger()); - auto new_instance = std::unique_ptr(new TcpMonPin()); + auto new_instance = std::unique_ptr(new myPinObject()); ASSERT_TRUE(new_instance != nullptr); XrdTcpMonPin *prevP = nullptr; @@ -79,7 +79,10 @@ TEST_F(TCPTest, GenerateJSON) { name.sin_addr = *(struct in_addr *) hostinfo->h_addr; XrdNetAddr xrdnetaddr(&name); - std::string returned_json = TCPStats::GenerateJSON(tcp_info, xrdnetaddr); + long long bytesIn = 10; + long long bytesOut = 11; + + std::string returned_json = TCPStats::GenerateJSON(tcp_info, xrdnetaddr, bytesIn, bytesOut); // Parse the returned JSON picojson::value v; @@ -94,6 +97,9 @@ TEST_F(TCPTest, GenerateJSON) { ASSERT_EQ(v.get()["lost"].get(), 5); ASSERT_EQ(v.get()["retrans"].get(), 6); ASSERT_EQ(v.get()["reordering"].get(), 7); + ASSERT_EQ(v.get()["bytes_in"].get(), 10); + ASSERT_EQ(v.get()["bytes_out"].get(), 11); + //std::cout << returned_json;