use of io.micrometer.core.lang.Nullable in project micrometer by micrometer-metrics.
the class ExecutorServiceMetrics method unwrapThreadPoolExecutor.
/**
* Every ScheduledThreadPoolExecutor created by {@link Executors} is wrapped. Also,
* {@link Executors#newSingleThreadExecutor()} wrap a regular {@link ThreadPoolExecutor}.
*/
@Nullable
private ThreadPoolExecutor unwrapThreadPoolExecutor(ExecutorService executor, Class<?> wrapper) {
try {
Field e = wrapper.getDeclaredField("e");
e.setAccessible(true);
return (ThreadPoolExecutor) e.get(executorService);
} catch (NoSuchFieldException | IllegalAccessException e) {
// Do nothing. We simply can't get to the underlying ThreadPoolExecutor.
}
return null;
}
use of io.micrometer.core.lang.Nullable in project micrometer by micrometer-metrics.
the class WavefrontMeterRegistry method writeMetricDirect.
private String writeMetricDirect(Meter.Id id, @Nullable String suffix, double value) {
Meter.Id fullId = id;
if (suffix != null)
fullId = idWithSuffix(id, suffix);
List<Tag> conventionTags = getConventionTags(fullId);
String tags = conventionTags.stream().map(t -> "\"" + t.getKey() + "\": \"" + t.getValue() + "\"").collect(joining(","));
UUID uuid = UUID.randomUUID();
String uniqueNameSuffix = ((Long) uuid.getMostSignificantBits()).toString() + uuid.getLeastSignificantBits();
// it as part of the name. Wavefront strips a $<NUMERIC> suffix from the name at parsing time.
return "\"" + getConventionName(fullId) + "$" + uniqueNameSuffix + "\"" + ": {" + "\"value\": " + DoubleFormat.decimalOrNan(value) + "," + "\"tags\": {" + tags + "}" + "}";
}
use of io.micrometer.core.lang.Nullable in project micrometer by micrometer-metrics.
the class GraphiteMeterRegistryTest method metricPrefixes.
@Test
void metricPrefixes() {
final CountDownLatch bindLatch = new CountDownLatch(1);
final CountDownLatch receiveLatch = new CountDownLatch(1);
final CountDownLatch terminateLatch = new CountDownLatch(1);
final GraphiteMeterRegistry registry = new GraphiteMeterRegistry(new GraphiteConfig() {
@Override
@Nullable
public String get(String key) {
return null;
}
@Override
public Duration step() {
return Duration.ofSeconds(1);
}
@Override
public GraphiteProtocol protocol() {
return GraphiteProtocol.UDP;
}
@Override
public int port() {
return 8127;
}
@Override
public String[] tagsAsPrefix() {
return new String[] { "application" };
}
}, mockClock);
final Disposable.Swap server = Disposables.swap();
Consumer<ClientOptions.Builder<?>> opts = builder -> builder.option(ChannelOption.SO_REUSEADDR, true).connectAddress(() -> new InetSocketAddress(PORT));
UdpServer.create(opts).newHandler((in, out) -> {
in.receive().asString().log().subscribe(line -> {
assertThat(line).startsWith("APPNAME.myTimer");
receiveLatch.countDown();
});
return Flux.never();
}).doOnSuccess(v -> bindLatch.countDown()).doOnTerminate(terminateLatch::countDown).subscribe(server::replace);
try {
assertTrue(bindLatch.await(10, TimeUnit.SECONDS));
registry.timer("my.timer", "application", "APPNAME");
assertTrue(receiveLatch.await(10, TimeUnit.SECONDS));
} catch (InterruptedException e) {
fail("Failed to wait for line", e);
} finally {
server.dispose();
registry.stop();
try {
terminateLatch.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
fail("Failed to terminate UDP server listening for Graphite metrics", e);
}
}
}
use of io.micrometer.core.lang.Nullable in project micrometer by micrometer-metrics.
the class SampleRegistries method prometheus.
/**
* To use pushgateway instead:
* new PushGateway("localhost:9091").pushAdd(registry.getPrometheusRegistry(), "samples");
*
* @return A prometheus registry.
*/
public static PrometheusMeterRegistry prometheus() {
PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(new PrometheusConfig() {
@Override
public Duration step() {
return Duration.ofSeconds(10);
}
@Override
@Nullable
public String get(String k) {
return null;
}
});
try {
HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
server.createContext("/prometheus", httpExchange -> {
String response = prometheusRegistry.scrape();
httpExchange.sendResponseHeaders(200, response.length());
OutputStream os = httpExchange.getResponseBody();
os.write(response.getBytes());
os.close();
});
new Thread(server::start).run();
} catch (IOException e) {
throw new RuntimeException(e);
}
return prometheusRegistry;
}
Aggregations