use of io.micrometer.core.instrument.simple.SimpleMeterRegistry in project micrometer by micrometer-metrics.
the class TimerTest method recordThrowable.
@DisplayName("record throwables")
@Test
default void recordThrowable() {
MeterRegistry registry = new SimpleMeterRegistry();
Supplier<String> timed = () -> registry.timer("timer").record(() -> "");
timed.get();
}
use of io.micrometer.core.instrument.simple.SimpleMeterRegistry in project micrometer by micrometer-metrics.
the class MetricsTest method metricCanBeCreatedBeforeStaticRegistryIsConfigured.
@Test
void metricCanBeCreatedBeforeStaticRegistryIsConfigured() {
// doesn't blow up
Counter counter = Metrics.counter("counter");
counter.increment();
SimpleMeterRegistry simple = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
Metrics.addRegistry(simple);
counter.increment();
assertThat(Metrics.globalRegistry.get("counter").counter().count()).isEqualTo(1.0);
}
use of io.micrometer.core.instrument.simple.SimpleMeterRegistry in project micrometer by micrometer-metrics.
the class MicrometerMetricsPublisherCommandTest method testCumulativeCounters.
@Disabled("CI is failing often asserting that the count is 23")
@Test
void testCumulativeCounters() throws Exception {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("MicrometerCOMMAND-A");
HystrixCommandProperties properties = new HystrixPropertiesCommandDefault(key, propertiesSetter);
HystrixCommandMetrics metrics = HystrixCommandMetrics.getInstance(key, groupKey, properties);
HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(key, groupKey, properties, metrics);
SimpleMeterRegistry registry = new SimpleMeterRegistry();
MicrometerMetricsPublisherCommand metricsPublisherCommand = new MicrometerMetricsPublisherCommand(registry, key, groupKey, metrics, circuitBreaker, properties);
metricsPublisherCommand.initialize();
for (int i = 0; i < 3; i++) {
new SuccessCommand(key).execute();
new SuccessCommand(key).execute();
new SuccessCommand(key).execute();
Thread.sleep(10);
new TimeoutCommand(key).execute();
new SuccessCommand(key).execute();
new FailureCommand(key).execute();
new FailureCommand(key).execute();
new SuccessCommand(key).execute();
new SuccessCommand(key).execute();
new SuccessCommand(key).execute();
Thread.sleep(10);
new SuccessCommand(key).execute();
}
Iterable<Tag> tags = Tags.of("group", "MicrometerGROUP", "key", "MicrometerCOMMAND-A");
assertExecutionMetric(registry, "success", 24.0);
assertThat(registry.get("hystrix.execution").tags(tags).tags("event", "timeout").functionCounter().count()).isEqualTo(3.0);
assertThat(registry.get("hystrix.execution").tags(tags).tags("event", "failure").functionCounter().count()).isEqualTo(6.0);
assertThat(registry.get("hystrix.execution").tags(tags).tags("event", "short_circuited").functionCounter().count()).isEqualTo(0.0);
assertThat(registry.get("hystrix.circuit.breaker.open").tags(tags).gauge().value()).isEqualTo(0.0);
}
use of io.micrometer.core.instrument.simple.SimpleMeterRegistry in project micrometer by micrometer-metrics.
the class ProcessorMetricsTest method openJ9CpuMetrics.
@Test
void openJ9CpuMetrics() {
assumeTrue(classExists("com.ibm.lang.management.OperatingSystemMXBean"));
MeterRegistry registry = new SimpleMeterRegistry();
new ProcessorMetrics().bindTo(registry);
/*
* We can't assert on values because these methods are documented to return "-1"
* on the first call and a positive value - if supported - on subsequent calls.
* This holds true for "system.cpu.usage" but not for "process.cpu.usage". The latter
* needs some milliseconds of sleep before it actually returns a positive value
* on a supported system. Thread.sleep() is flaky, though.
*/
registry.get("system.cpu.usage").gauge();
registry.get("process.cpu.usage").gauge();
}
use of io.micrometer.core.instrument.simple.SimpleMeterRegistry in project micrometer by micrometer-metrics.
the class DistributionSummaryTest method histogramsInCumulativeMode.
@Test
void histogramsInCumulativeMode() {
MockClock clock = new MockClock();
MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock);
DistributionSummary summary = DistributionSummary.builder("my.summary").sla(1).register(registry);
summary.record(1);
// Histogram bucket counts DO roll over at the step interval, so decay.
assertThat(summary.takeSnapshot().histogramCounts()).containsExactly(new CountAtBucket(1, 1));
clock.add(SimpleConfig.DEFAULT.step());
assertThat(summary.takeSnapshot().histogramCounts()).containsExactly(new CountAtBucket(1, 0));
}
Aggregations