-
Notifications
You must be signed in to change notification settings - Fork 9
/
TestRunner.java
52 lines (41 loc) · 1.61 KB
/
TestRunner.java
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
package com.izeye.sample;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.util.concurrent.ScheduledThreadPoolExecutor;
/**
* {@link ApplicationRunner} for testing.
*
* @author Johnny Lim
*/
@Component
public class TestRunner implements ApplicationRunner {
private final MeterRegistry meterRegistry;
public TestRunner(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
}
@Override
public void run(ApplicationArguments args) {
createExecutor("another.executor.service", Tags.of("key1", "value1"));
for (int i = 0; i < 10; i++) {
String executorServiceName = "my.executor.service." + i;
Tags tags = Tags.empty();
createExecutor(executorServiceName, tags);
}
for (Meter meter : this.meterRegistry.getMeters()) {
Meter.Id id = meter.getId();
if (id.getName().startsWith("executor.")) {
System.out.println(id);
}
}
}
private void createExecutor(String executorServiceName, Tags tags) {
ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(10);
new ExecutorServiceMetrics(scheduledThreadPoolExecutor, executorServiceName, tags)
.bindTo(this.meterRegistry);
}
}