Skip to content

Commit

Permalink
adding new block, transaction, and peer metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Jameson Lopp committed Jun 13, 2015
1 parent b6bbd0e commit e1d6699
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ bool AddOrphanTx(const CTransaction& tx, NodeId peer)

LogPrint("mempool", "stored orphan tx %s (mapsz %u prevsz %u)\n", hash.ToString(),
mapOrphanTransactions.size(), mapOrphanTransactionsByPrev.size());
statsClient.gauge("transactions.orphans", mapOrphanTransactions.size());
statsClient.inc("transactions.orphans.add", 1.0f);
return true;
}

Expand All @@ -568,6 +570,7 @@ void static EraseOrphanTx(uint256 hash)
mapOrphanTransactionsByPrev.erase(itPrev);
}
mapOrphanTransactions.erase(it);
statsClient.inc("transactions.orphans.remove", 1.0f);
}

void EraseOrphansFor(NodeId peer)
Expand All @@ -584,6 +587,7 @@ void EraseOrphansFor(NodeId peer)
}
}
if (nErased > 0) LogPrint("mempool", "Erased %d orphan tx from peer %d\n", nErased, peer);
statsClient.gauge("transactions.orphans", mapOrphanTransactions.size());
}


Expand All @@ -600,6 +604,7 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
EraseOrphanTx(it->first);
++nEvicted;
}
statsClient.gauge("transactions.orphans", mapOrphanTransactions.size());
return nEvicted;
}

Expand Down Expand Up @@ -919,8 +924,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa

// is it already in the memory pool?
uint256 hash = tx.GetHash();
if (pool.exists(hash))
if (pool.exists(hash)) {
statsClient.inc("transactions.duplicate", 1.0f);
return false;
}

// Check for conflicts with in-memory transactions
{
Expand Down Expand Up @@ -1065,6 +1072,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
pool.addUnchecked(hash, entry, !IsInitialBlockDownload());
statsClient.count("transactions.sizeBytes", nSize, 1.0f);
statsClient.count("transactions.fees", nFees, 1.0f);
statsClient.count("transactions.inputValue", nValueIn, 1.0f);
statsClient.count("transactions.outputValue", nValueOut, 1.0f);
statsClient.count("transactions.sigOps", nSigOps, 1.0f);
statsClient.count("transactions.priority", dPriority, 1.0f);
}

SyncWithWallets(tx, NULL);
Expand Down Expand Up @@ -1333,7 +1344,7 @@ void Misbehaving(NodeId pnode, int howmuch)
{
LogPrintf("%s: %s (%d -> %d) BAN THRESHOLD EXCEEDED\n", __func__, state->name, state->nMisbehavior-howmuch, state->nMisbehavior);
state->fShouldBan = true;
statsClient.inc("misbehavior.banned", 1.0);
statsClient.inc("misbehavior.banned", 1.0f);
} else {
LogPrintf("%s: %s (%d -> %d)\n", __func__, state->name, state->nMisbehavior-howmuch, state->nMisbehavior);
statsClient.count("misbehavior.amount", howmuch, 1.0);
Expand Down Expand Up @@ -2744,6 +2755,9 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
boost::posix_time::ptime finish = boost::posix_time::microsec_clock::local_time();
boost::posix_time::time_duration diff = finish - start;
statsClient.timing("CheckBlock_us", diff.total_microseconds(), 1.0f);
statsClient.gauge("blocks.currentSizeBytes", ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION));
statsClient.gauge("blocks.currentNumTransactions", block.vtx.size());
statsClient.gauge("blocks.currentSigOps", nSigOps);

return true;
}
Expand Down
12 changes: 12 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,9 @@ void ThreadSocketHandler()
int spvNodes = 0;
int inboundNodes = 0;
int outboundNodes = 0;
int ipv4Nodes = 0;
int ipv6Nodes = 0;
int torNodes = 0;
BOOST_FOREACH(CNode* pnode, vNodes)
{
if(pnode->fClient)
Expand All @@ -751,11 +754,20 @@ void ThreadSocketHandler()
inboundNodes++;
else
outboundNodes++;
if(pnode->addr.IsIPv4())
ipv4Nodes++;
if(pnode->addr.IsIPv6())
ipv6Nodes++;
if(pnode->addr.IsTor())
torNodes++;
}
statsClient.gauge("peers.spvNodeConnections", spvNodes, 1.0f);
statsClient.gauge("peers.fullNodeConnections", fullNodes, 1.0f);
statsClient.gauge("peers.inboundConnections", inboundNodes, 1.0f);
statsClient.gauge("peers.outboundConnections", outboundNodes, 1.0f);
statsClient.gauge("peers.ipv4Connections", ipv4Nodes, 1.0f);
statsClient.gauge("peers.ipv6Connections", ipv6Nodes, 1.0f);
statsClient.gauge("peers.torConnections", torNodes, 1.0f);
}

//
Expand Down

0 comments on commit e1d6699

Please sign in to comment.