Skip to content

Commit

Permalink
Adding JSON output
Browse files Browse the repository at this point in the history
  • Loading branch information
djw8605 committed May 27, 2020
1 parent 55c2088 commit 1e43902
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ if(NOT EXISTS "${PROJECT_SOURCE_DIR}/vendor/picojson/picojson.h")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()

if(NOT EXISTS "${PROJECT_SOURCE_DIR}/vendor/gtest/CMakeLists.txt")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()

macro(use_cxx11)
if (CMAKE_VERSION VERSION_LESS "3.1")
Expand All @@ -56,9 +59,23 @@ target_link_libraries(XrdTCPStats-${XROOTD_PLUGIN_VERSION} -ldl -lpthread ${XROO
#set_target_properties(XrdTCPStats-${XROOTD_PLUGIN_VERSION} PROPERTIES OUTPUT_NAME XrdTCPStats-${XROOTD_PLUGIN_VERSION} SUFFIX ".so" LINK_FLAGS "-Wl,--version-script=${CMAKE_SOURCE_DIR}/configs/export-lib-symbols")
set_target_properties(XrdTCPStats-${XROOTD_PLUGIN_VERSION} PROPERTIES OUTPUT_NAME XrdTCPStats-${XROOTD_PLUGIN_VERSION} SUFFIX ".so")

if( BUILD_UNITTESTS )

include(ExternalProject)
ExternalProject_Add(gtest
PREFIX external/gtest
URL file://${PROJECT_SOURCE_DIR}/vendor/gtest
INSTALL_COMMAND :
CMAKE_ARGS
-DCMAKE_CXX_FLAGS=-std=gnu++11
)
enable_testing()
add_subdirectory(test)
endif()


SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Install path for libraries")

install(
TARGETS XrdTCPStats-${XROOTD_PLUGIN_VERSION}
LIBRARY DESTINATION ${LIB_INSTALL_DIR})
LIBRARY DESTINATION ${LIB_INSTALL_DIR})
18 changes: 16 additions & 2 deletions src/tcpstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ void TCPStats::Monitor(int fd, XrdNetAddrInfo &netInfo, const char *tident)
socklen_t tcp_info_length = sizeof(tcp_info);
int sockopt_rc = getsockopt( fd, SOL_TCP, TCP_INFO, (void *)&tcp_info, &tcp_info_length );
if ( sockopt_rc == 0 ) {
auto returnedJSON = TCPStats::GenerateJSON(tcp_info, netInfo);
}
// Create the json object
/*
int sprintf_rc = sprintf(statistics,
Expand All @@ -50,15 +52,27 @@ void TCPStats::Monitor(int fd, XrdNetAddrInfo &netInfo, const char *tident)
tcp_info.tcpi_reordering
);
*/
}

}

std::string GenerateJSON(tcp_info& tcp_info, XrdNetAddrInfo& netInfo)
std::string TCPStats::GenerateJSON(tcp_info& tcp_info, XrdNetAddrInfo& netInfo)
{
picojson::object wrapper;
wrapper["type"] = picojson::value("tcpstats");

// Remote Address String
char addr_str[512];
netInfo.Format(addr_str, 512);
wrapper["remote"] = picojson::value(addr_str);

// TCP Statistics
wrapper["rtt"] = picojson::value(static_cast<double>(tcp_info.tcpi_rtt));
wrapper["unacked"] = picojson::value(static_cast<double>(tcp_info.tcpi_unacked));
wrapper["sacked"] = picojson::value(static_cast<double>(tcp_info.tcpi_sacked));
wrapper["lost"] = picojson::value(static_cast<double>(tcp_info.tcpi_lost));
wrapper["retrans"] = picojson::value(static_cast<double>(tcp_info.tcpi_retrans));
wrapper["reordering"] = picojson::value(static_cast<double>(tcp_info.tcpi_reordering));

return picojson::value(wrapper).serialize();
}

Expand Down
3 changes: 2 additions & 1 deletion src/tcpstats.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ class TCPStats: public XrdTcpMonPin {

public:
void Monitor(int fd, XrdNetAddrInfo &netInfo, const char *tident);
static std::string GenerateJSON(tcp_info& tcp_info, XrdNetAddrInfo& netInfo);

TCPStats(XrdXrootdGStream* gs);
virtual ~TCPStats() {};

private:
XrdXrootdGStream* stream;
std::string GenerateJSON(tcp_info& tcp_info, XrdNetAddrInfo& netInfo);

};


Expand Down

0 comments on commit 1e43902

Please sign in to comment.