Skip to content

Commit f67bec2

Browse files
authored
Merge pull request #4626 from chengtx01/add_net_metrics
feat(net): add 3 prometheus metrics for network module
2 parents 42e6a22 + a5c7f15 commit f67bec2

5 files changed

Lines changed: 23 additions & 3 deletions

File tree

common/src/main/java/org/tron/common/prometheus/MetricKeys.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public static class Histogram {
5858
public static final String TCP_BYTES = "tron:tcp_bytes";
5959
public static final String HTTP_BYTES = "tron:http_bytes";
6060
public static final String INTERNAL_SERVICE_LATENCY = "tron:internal_service_latency_seconds";
61+
public static final String MESSAGE_PROCESS_LATENCY = "tron:message_process_latency_seconds";
62+
public static final String BLOCK_FETCH_LATENCY = "tron:block_fetch_latency_seconds";
63+
public static final String BLOCK_RECEIVE_DELAY = "tron:block_receive_delay_seconds";
6164

6265
private Histogram() {
6366
throw new IllegalStateException("Histogram");

common/src/main/java/org/tron/common/prometheus/MetricsHistogram.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public class MetricsHistogram {
4141
"type");
4242
init(MetricKeys.Histogram.HTTP_BYTES, "http_bytes traffic.",
4343
"url", "status");
44+
init(MetricKeys.Histogram.MESSAGE_PROCESS_LATENCY, "process message latency.",
45+
"type");
46+
init(MetricKeys.Histogram.BLOCK_FETCH_LATENCY, "fetch block latency.");
47+
init(MetricKeys.Histogram.BLOCK_RECEIVE_DELAY,
48+
"receive block delay time, receiveTime - blockTime.");
4449
}
4550

4651
private MetricsHistogram() {

framework/src/main/java/org/tron/core/db/Manager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
14101410
String address = StringUtil.encode58Check(miner.getWitnessAddress().toByteArray());
14111411
final Histogram.Timer timer = Metrics.histogramStartTimer(
14121412
MetricKeys.Histogram.BLOCK_GENERATE_LATENCY, address);
1413-
Metrics.histogramObserve(MetricKeys.Histogram.MINER_LATENCY,
1413+
Metrics.histogramObserve(MetricKeys.Histogram.MINER_DELAY,
14141414
(System.currentTimeMillis() - blockTime) / Metrics.MILLISECONDS_PER_SECOND, address);
14151415
long postponedTrxCount = 0;
14161416
logger.info("Generate block {} begin.", chainBaseManager.getHeadBlockNum() + 1);

framework/src/main/java/org/tron/core/net/TronNetService.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.springframework.stereotype.Component;
66
import org.tron.common.overlay.message.Message;
77
import org.tron.common.overlay.server.ChannelManager;
8+
import org.tron.common.prometheus.MetricKeys;
9+
import org.tron.common.prometheus.Metrics;
810
import org.tron.core.exception.P2pException;
911
import org.tron.core.exception.P2pException.TypeEnum;
1012
import org.tron.core.net.message.BlockMessage;
@@ -129,8 +131,12 @@ protected void onMessage(PeerConnection peer, TronMessage msg) {
129131
processException(peer, msg, e);
130132
} finally {
131133
long costs = System.currentTimeMillis() - startTime;
132-
logger.info("Message processing costs {} ms, peer: {}, type: {}, time tag: {}",
133-
costs, peer.getInetAddress(), msg.getType(), getTimeTag(costs));
134+
if (costs > DURATION_STEP) {
135+
logger.info("Message processing costs {} ms, peer: {}, type: {}, time tag: {}",
136+
costs, peer.getInetAddress(), msg.getType(), getTimeTag(costs));
137+
Metrics.histogramObserve(MetricKeys.Histogram.MESSAGE_PROCESS_LATENCY,
138+
costs / Metrics.MILLISECONDS_PER_SECOND, msg.getType().name());
139+
}
134140
}
135141
}
136142

framework/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.bouncycastle.util.encoders.Hex;
88
import org.springframework.beans.factory.annotation.Autowired;
99
import org.springframework.stereotype.Component;
10+
import org.tron.common.prometheus.MetricKeys;
11+
import org.tron.common.prometheus.Metrics;
1012
import org.tron.core.Constant;
1113
import org.tron.core.capsule.BlockCapsule;
1214
import org.tron.core.capsule.BlockCapsule.BlockId;
@@ -76,7 +78,11 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep
7678
if (null != time) {
7779
MetricsUtil.histogramUpdateUnCheck(MetricsKey.NET_LATENCY_FETCH_BLOCK
7880
+ peer.getNode().getHost(), now - time);
81+
Metrics.histogramObserve(MetricKeys.Histogram.BLOCK_FETCH_LATENCY,
82+
(now - time) / Metrics.MILLISECONDS_PER_SECOND);
7983
}
84+
Metrics.histogramObserve(MetricKeys.Histogram.BLOCK_RECEIVE_DELAY,
85+
(now - blockMessage.getBlockCapsule().getTimeStamp()) / Metrics.MILLISECONDS_PER_SECOND);
8086
fetchBlockService.blockFetchSuccess(blockId);
8187
long interval = blockId.getNum() - tronNetDelegate.getHeadBlockId().getNum();
8288
processBlock(peer, blockMessage.getBlockCapsule());

0 commit comments

Comments
 (0)