Skip to content

Commit

Permalink
Merge pull request #27 from jlopp/bandwidthByMsgType
Browse files Browse the repository at this point in the history
gauge bandwidth usage by message type
  • Loading branch information
jlopp committed Mar 20, 2016
2 parents 18452e5 + a311782 commit 884a84f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
24 changes: 22 additions & 2 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes)
i = mapRecvBytesPerMsgCmd.find(NET_MESSAGE_COMMAND_OTHER);
assert(i != mapRecvBytesPerMsgCmd.end());
i->second += msg.hdr.nMessageSize + CMessageHeader::HEADER_SIZE;
statsClient.count("bandwidth.message." + std::string(msg.hdr.pchCommand) + ".bytesReceived", msg.hdr.nMessageSize + CMessageHeader::HEADER_SIZE, 1.0f);

msg.nTime = GetTimeMicros();
messageHandlerCondition.notify_one();
Expand Down Expand Up @@ -1102,8 +1103,6 @@ void ThreadSocketHandler()
nPrevNodeCount = vNodes.size();
uiInterface.NotifyNumConnectionsChanged(nPrevNodeCount);

statsClient.gauge("peers.totalConnections", nPrevNodeCount, 1.0f);

// count various node attributes
int fullNodes = 0;
int spvNodes = 0;
Expand All @@ -1112,8 +1111,21 @@ void ThreadSocketHandler()
int ipv4Nodes = 0;
int ipv6Nodes = 0;
int torNodes = 0;
mapMsgCmdSize mapRecvBytesMsgStats;
mapMsgCmdSize mapSentBytesMsgStats;
BOOST_FOREACH(const std::string &msg, getAllNetMessageTypes())
{
mapRecvBytesMsgStats[msg] = 0;
mapSentBytesMsgStats[msg] = 0;
}
mapRecvBytesMsgStats[NET_MESSAGE_COMMAND_OTHER] = 0;
mapSentBytesMsgStats[NET_MESSAGE_COMMAND_OTHER] = 0;
BOOST_FOREACH(CNode* pnode, vNodes)
{
BOOST_FOREACH(const mapMsgCmdSize::value_type &i, pnode->mapRecvBytesPerMsgCmd)
mapRecvBytesMsgStats[i.first] += i.second;
BOOST_FOREACH(const mapMsgCmdSize::value_type &i, pnode->mapSendBytesPerMsgCmd)
mapSentBytesMsgStats[i.first] += i.second;
if(pnode->fClient)
spvNodes++;
else
Expand All @@ -1128,7 +1140,14 @@ void ThreadSocketHandler()
ipv6Nodes++;
if(pnode->addr.IsTor())
torNodes++;
statsClient.timing("peers.ping_us", pnode->nPingUsecTime, 1.0f);
}
BOOST_FOREACH(const std::string &msg, getAllNetMessageTypes())
{
statsClient.gauge("bandwidth.message." + msg + ".totalBytesReceived", mapRecvBytesMsgStats[msg], 1.0f);
statsClient.gauge("bandwidth.message." + msg + ".totalBytesSent", mapSentBytesMsgStats[msg], 1.0f);
}
statsClient.gauge("peers.totalConnections", nPrevNodeCount, 1.0f);
statsClient.gauge("peers.spvNodeConnections", spvNodes, 1.0f);
statsClient.gauge("peers.fullNodeConnections", fullNodes, 1.0f);
statsClient.gauge("peers.inboundConnections", inboundNodes, 1.0f);
Expand Down Expand Up @@ -2542,6 +2561,7 @@ void CNode::EndMessage(const char* pszCommand) UNLOCK_FUNCTION(cs_vSend)

//log total amount of bytes per command
mapSendBytesPerMsgCmd[std::string(pszCommand)] += nSize + CMessageHeader::HEADER_SIZE;
statsClient.count("bandwidth.message." + std::string(pszCommand) + ".bytesSent", nSize + CMessageHeader::HEADER_SIZE, 1.0f);

// Set the checksum
uint256 hash = Hash(ssSend.begin() + CMessageHeader::HEADER_SIZE, ssSend.end());
Expand Down
6 changes: 3 additions & 3 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,13 @@ class CNode
static std::vector<CSubNet> vWhitelistedRange;
static CCriticalSection cs_vWhitelistedRange;

mapMsgCmdSize mapSendBytesPerMsgCmd;
mapMsgCmdSize mapRecvBytesPerMsgCmd;

// Basic fuzz-testing
void Fuzz(int nChance); // modifies ssSend

public:
mapMsgCmdSize mapSendBytesPerMsgCmd;
mapMsgCmdSize mapRecvBytesPerMsgCmd;

uint256 hashContinue;
int nStartingHeight;

Expand Down

0 comments on commit 884a84f

Please sign in to comment.