-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathGaugeExample.java
More file actions
30 lines (24 loc) · 889 Bytes
/
Copy pathGaugeExample.java
File metadata and controls
30 lines (24 loc) · 889 Bytes
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
package io.github.biezhi.metrics;
import com.codahale.metrics.ConsoleReporter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.MetricRegistry;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.TimeUnit;
/**
* 衡量一个待处理队列中任务的个数
*/
public class GaugeExample {
public static Queue<String> q = new LinkedList<>();
public static void main(String[] args) throws InterruptedException {
MetricRegistry registry = new MetricRegistry();
ConsoleReporter reporter = ConsoleReporter.forRegistry(registry).build();
reporter.start(1, TimeUnit.SECONDS);
registry.register(MetricRegistry.name(GaugeExample.class, "queue", "size"),
(Gauge<Integer>) () -> q.size());
while (true) {
Thread.sleep(1000);
q.add("Job-xxx");
}
}
}