-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathMetricsHistogram.java
More file actions
112 lines (97 loc) · 3.78 KB
/
MetricsHistogram.java
File metadata and controls
112 lines (97 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package org.tron.common.prometheus;
import io.prometheus.client.Histogram;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import lombok.extern.slf4j.Slf4j;
@Slf4j(topic = "metrics")
public class MetricsHistogram {
private static final Map<String, Histogram> container = new ConcurrentHashMap<>();
static {
init(MetricKeys.Histogram.INTERNAL_SERVICE_LATENCY, "Internal Service latency.",
"class", "method");
init(MetricKeys.Histogram.HTTP_SERVICE_LATENCY, "Http Service latency.",
"url");
init(MetricKeys.Histogram.GRPC_SERVICE_LATENCY, "Grpc Service latency.",
"endpoint");
init(MetricKeys.Histogram.JSONRPC_SERVICE_LATENCY, "JsonRpc Service latency.",
"method");
init(MetricKeys.Histogram.MINER_LATENCY, "miner latency.",
MetricLabels.Histogram.MINER);
init(MetricKeys.Histogram.PING_PONG_LATENCY, "node ping pong latency.");
init(MetricKeys.Histogram.VERIFY_SIGN_LATENCY, "verify sign latency for trx , block.",
"type");
init(MetricKeys.Histogram.LOCK_ACQUIRE_LATENCY, "lock acquire latency.",
"type");
init(MetricKeys.Histogram.BLOCK_PROCESS_LATENCY,
"process block latency for TronNetDelegate.",
"sync");
init(MetricKeys.Histogram.BLOCK_PUSH_LATENCY, "push block latency for Manager.");
init(MetricKeys.Histogram.BLOCK_GENERATE_LATENCY, "generate block latency.",
"address");
init(MetricKeys.Histogram.PROCESS_TRANSACTION_LATENCY, "process transaction latency.",
"type", "contract");
init(MetricKeys.Histogram.MINER_DELAY, "miner delay time, actualTime - planTime.",
MetricLabels.Histogram.MINER);
init(MetricKeys.Histogram.UDP_BYTES, "udp_bytes traffic.",
"type");
init(MetricKeys.Histogram.TCP_BYTES, "tcp_bytes traffic.",
"type");
init(MetricKeys.Histogram.HTTP_BYTES, "http_bytes traffic.",
"url", "status");
init(MetricKeys.Histogram.MESSAGE_PROCESS_LATENCY, "process message latency.",
"type");
init(MetricKeys.Histogram.BLOCK_FETCH_LATENCY, "fetch block latency.");
init(MetricKeys.Histogram.BLOCK_RECEIVE_DELAY,
"receive block delay time, receiveTime - blockTime.");
init(MetricKeys.Histogram.BLOCK_TRANSACTION_COUNT,
"Distribution of transaction counts per block.",
new double[]{0, 10, 50, 100, 200, 500, 1000, 2000, 5000, 10000},
MetricLabels.Histogram.MINER);
}
private MetricsHistogram() {
throw new IllegalStateException("MetricsHistogram");
}
private static void init(String name, String help, String... labels) {
container.put(name, Histogram.build()
.name(name)
.help(help)
.labelNames(labels)
.register());
}
private static void init(String name, String help, double[] buckets, String... labels) {
Histogram.Builder builder = Histogram.build()
.name(name)
.help(help)
.labelNames(labels);
if (buckets != null && buckets.length > 0) {
builder.buckets(buckets);
}
container.put(name, builder.register());
}
static Histogram.Timer startTimer(String key, String... labels) {
if (Metrics.enabled()) {
Histogram histogram = container.get(key);
if (histogram == null) {
logger.info("{} not exist", key);
return null;
}
return histogram.labels(labels).startTimer();
}
return null;
}
static void observeDuration(Histogram.Timer startTimer) {
if (startTimer != null) {
startTimer.observeDuration();
}
}
static void observe(String key, double amt, String... labels) {
if (Metrics.enabled()) {
Histogram histogram = container.get(key);
if (histogram == null) {
logger.info("{} not exist", key);
return;
}
histogram.labels(labels).observe(amt);
}
}
}