This repository was archived by the owner on Mar 3, 2026. It is now read-only.
forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetricsApp.java
More file actions
44 lines (37 loc) · 1.35 KB
/
MetricsApp.java
File metadata and controls
44 lines (37 loc) · 1.35 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
package demo;
import java.util.concurrent.TimeUnit;
import org.jooby.Jooby;
import org.jooby.json.Jackson;
import org.jooby.metrics.Metrics;
import com.codahale.metrics.ConsoleReporter;
import com.codahale.metrics.health.jvm.ThreadDeadlockHealthCheck;
import com.codahale.metrics.jvm.FileDescriptorRatioGauge;
import com.codahale.metrics.jvm.GarbageCollectorMetricSet;
import com.codahale.metrics.jvm.MemoryUsageGaugeSet;
import com.codahale.metrics.jvm.ThreadStatesGaugeSet;
public class MetricsApp extends Jooby {
{
use(new Jackson());
use(new Metrics()
.request()
.reporter(registry -> {
ConsoleReporter reporter = ConsoleReporter.forRegistry(registry)
.convertDurationsTo(TimeUnit.SECONDS)
.convertRatesTo(TimeUnit.SECONDS)
.build();
reporter.start(1, TimeUnit.MINUTES);
return reporter;
})
.metric("memory", new MemoryUsageGaugeSet())
.metric("threads", new ThreadStatesGaugeSet())
.metric("gc", new GarbageCollectorMetricSet())
.metric("fd", new FileDescriptorRatioGauge())
.healthCheck("deadlock", new ThreadDeadlockHealthCheck())
.ping()
.threadDump());
get("/", () -> "Hello metrics!");
}
public static void main(final String[] args) throws Throwable {
new MetricsApp().start(args);
}
}