From 90f4d4830724ffda1813b17c334be39262848028 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sat, 17 Oct 2020 02:07:55 +0100 Subject: [PATCH] Add some metrics that match existing zebrad metrics The metric names match those used in zebrad, so the same visualisers can be used for both nodes. See https://github.com/ZcashFoundation/zebra/issues/1381 for discussion about potential naming changes. --- src/main.cpp | 6 ++++++ src/net.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index cfa7dbb57..9a21065de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,6 +46,7 @@ #include #include +#include using namespace std; @@ -3237,6 +3238,7 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) { "date", date.c_str(), "progress", progress.c_str(), "cache", cache.c_str()); + MetricsGauge("block.verified.block.height", pindexNew->nHeight); cvBlockChange.notify_all(); } @@ -3369,6 +3371,7 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams, int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1; LogPrint("bench", " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001); LogPrint("bench", "- Connect block: %.2fms [%.2fs]\n", (nTime6 - nTime1) * 0.001, nTimeTotal * 0.000001); + MetricsIncrementCounter("block.verified.block.count"); return true; } @@ -6226,6 +6229,7 @@ bool static ProcessMessage(const CChainParams& chainparams, CNode* pfrom, string CInv inv(MSG_BLOCK, block.GetHash()); LogPrint("net", "received block %s peer=%d\n", inv.hash.ToString(), pfrom->id); + MetricsIncrementCounter("sync.downloaded.block.count"); pfrom->AddInventoryKnown(inv); @@ -6244,6 +6248,8 @@ bool static ProcessMessage(const CChainParams& chainparams, CNode* pfrom, string LOCK(cs_main); Misbehaving(pfrom->GetId(), nDoS); } + } else if (state.IsValid()) { + MetricsIncrementCounter("sync.verified.block.count"); } } diff --git a/src/net.cpp b/src/net.cpp index 322219f54..c2a7b08bd 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -31,6 +31,8 @@ #include +#include + // Dump addresses to peers.dat and banlist.dat every 15 minutes (900s) #define DUMP_ADDRESSES_INTERVAL 900 @@ -702,6 +704,7 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes) if (msg.complete()) { msg.nTime = GetTimeMicros(); + MetricsIncrementCounter("peer.inbound.messages"); messageHandlerCondition.notify_one(); } } @@ -1104,6 +1107,7 @@ void ThreadSocketHandler() } if (vNodesSize != nPrevNodeCount) { nPrevNodeCount = vNodesSize; + MetricsGauge("pool.num_peers", nPrevNodeCount); uiInterface.NotifyNumConnectionsChanged(nPrevNodeCount); } @@ -2001,12 +2005,14 @@ void CNode::RecordBytesRecv(uint64_t bytes) { LOCK(cs_totalBytesRecv); nTotalBytesRecv += bytes; + MetricsCounter("bytes.read", bytes); } void CNode::RecordBytesSent(uint64_t bytes) { LOCK(cs_totalBytesSent); nTotalBytesSent += bytes; + MetricsCounter("bytes.written", bytes); uint64_t now = GetTime(); if (nMaxOutboundCycleStartTime + nMaxOutboundTimeframe < now) @@ -2280,6 +2286,7 @@ void CNode::AbortMessage() UNLOCK_FUNCTION(cs_vSend) void CNode::EndMessage() UNLOCK_FUNCTION(cs_vSend) { + MetricsIncrementCounter("peer.outbound.messages"); // The -*messagestest options are intentionally not documented in the help message, // since they are only used during development to debug the networking code and are // not intended for end-users.