use of io.micrometer.core.instrument.Tag in project micrometer by micrometer-metrics.
the class MicrometerMetricsPublisherCommandTest method testOpenCircuit.
@Disabled
@Test
void testOpenCircuit() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("MicrometerCOMMAND-B");
HystrixCommandProperties properties = new HystrixPropertiesCommandDefault(key, propertiesSetter.withCircuitBreakerForceOpen(true));
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();
new SuccessCommand(key).execute();
new SuccessCommand(key).execute();
new TimeoutCommand(key).execute();
new FailureCommand(key).execute();
new FailureCommand(key).execute();
new SuccessCommand(key).execute();
Iterable<Tag> tags = Tags.of("group", groupKey.name(), "key", key.name());
assertExecutionMetric(registry, "short_circuited", 6.0);
assertThat(registry.get("hystrix.execution").tags(tags).tags("event", "success").functionCounter().count()).isEqualTo(0.0);
assertThat(registry.get("hystrix.execution").tags(tags).tags("event", "timeout").functionCounter().count()).isEqualTo(0.0);
assertThat(registry.get("hystrix.execution").tags(tags).tags("event", "failure").functionCounter().count()).isEqualTo(0.0);
assertThat(registry.get("hystrix.fallback").tags(tags).tags("event", "fallback_success").functionCounter().count()).isEqualTo(6.0);
assertThat(registry.get("hystrix.circuit.breaker.open").tags(tags).gauge().value()).isEqualTo(1.0);
}
use of io.micrometer.core.instrument.Tag in project micrometer by micrometer-metrics.
the class TomcatMetricsTest method managerBasedMetrics.
@Test
void managerBasedMetrics() {
Context context = new StandardContext();
ManagerBase manager = new ManagerBase() {
@Override
public void load() {
}
@Override
public void unload() {
}
@Override
public Context getContext() {
return context;
}
};
manager.setMaxActiveSessions(3);
manager.createSession("first");
manager.createSession("second");
manager.createSession("third");
try {
manager.createSession("fourth");
fail("TooManyActiveSessionsException expected.");
} catch (TooManyActiveSessionsException exception) {
// ignore error, testing rejection
}
StandardSession expiredSession = new StandardSession(manager);
expiredSession.setId("third");
expiredSession.setCreationTime(System.currentTimeMillis() - 10_000);
manager.remove(expiredSession, true);
Iterable<Tag> tags = Tags.of("metricTag", "val1");
TomcatMetrics.monitor(registry, manager, tags);
assertThat(registry.get("tomcat.sessions.active.max").tags(tags).gauge().value()).isEqualTo(3.0);
assertThat(registry.get("tomcat.sessions.active.current").tags(tags).gauge().value()).isEqualTo(2.0);
assertThat(registry.get("tomcat.sessions.expired").tags(tags).functionCounter().count()).isEqualTo(1.0);
assertThat(registry.get("tomcat.sessions.rejected").tags(tags).functionCounter().count()).isEqualTo(1.0);
assertThat(registry.get("tomcat.sessions.created").tags(tags).functionCounter().count()).isEqualTo(3.0);
assertThat(registry.get("tomcat.sessions.alive.max").tags(tags).timeGauge().value()).isGreaterThan(1.0);
}
use of io.micrometer.core.instrument.Tag in project dolphin-platform by canoo.
the class MetricsModule method initialize.
@Override
public void initialize(final ServerCoreComponents coreComponents) {
final PlatformConfiguration configuration = coreComponents.getConfiguration();
final ServletContext servletContext = coreComponents.getInstance(ServletContext.class);
if (!configuration.getBooleanProperty(METRICS_NOOP_PROPERTY, true)) {
final PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
final List<Tag> tagList = TagUtil.convertTags(ContextManagerImpl.getInstance().getGlobalContexts());
new ClassLoaderMetrics(tagList).bindTo(prometheusRegistry);
new JvmMemoryMetrics(tagList).bindTo(prometheusRegistry);
new JvmGcMetrics(tagList).bindTo(prometheusRegistry);
new ProcessorMetrics(tagList).bindTo(prometheusRegistry);
new JvmThreadMetrics(tagList).bindTo(prometheusRegistry);
servletContext.addFilter(METRICS_SERVLET_FILTER_NAME, new RequestMetricsFilter()).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ALL_URL_MAPPING);
servletContext.addListener(new MetricsHttpSessionListener());
servletContext.addServlet(METRICS_SERVLET_NAME, new MetricsServlet(prometheusRegistry)).addMapping(configuration.getProperty(METRICS_ENDPOINT_PROPERTY));
MetricsImpl.getInstance().init(prometheusRegistry);
}
}
use of io.micrometer.core.instrument.Tag 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.Tag in project micrometer by micrometer-metrics.
the class JvmMemoryMetrics method bindTo.
@Override
public void bindTo(MeterRegistry registry) {
for (BufferPoolMXBean bufferPoolBean : ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class)) {
Iterable<Tag> tagsWithId = Tags.concat(tags, "id", bufferPoolBean.getName());
Gauge.builder("jvm.buffer.count", bufferPoolBean, BufferPoolMXBean::getCount).tags(tagsWithId).description("An estimate of the number of buffers in the pool").register(registry);
Gauge.builder("jvm.buffer.memory.used", bufferPoolBean, BufferPoolMXBean::getMemoryUsed).tags(tagsWithId).description("An estimate of the memory that the Java virtual machine is using for this buffer pool").baseUnit("bytes").register(registry);
Gauge.builder("jvm.buffer.total.capacity", bufferPoolBean, BufferPoolMXBean::getTotalCapacity).tags(tagsWithId).description("An estimate of the total capacity of the buffers in this pool").baseUnit("bytes").register(registry);
}
for (MemoryPoolMXBean memoryPoolBean : ManagementFactory.getPlatformMXBeans(MemoryPoolMXBean.class)) {
String area = MemoryType.HEAP.equals(memoryPoolBean.getType()) ? "heap" : "nonheap";
Iterable<Tag> tagsWithId = Tags.concat(tags, "id", memoryPoolBean.getName(), "area", area);
Gauge.builder("jvm.memory.used", memoryPoolBean, (mem) -> mem.getUsage().getUsed()).tags(tagsWithId).description("The amount of used memory").baseUnit("bytes").register(registry);
Gauge.builder("jvm.memory.committed", memoryPoolBean, (mem) -> mem.getUsage().getCommitted()).tags(tagsWithId).description("The amount of memory in bytes that is committed for the Java virtual machine to use").baseUnit("bytes").register(registry);
Gauge.builder("jvm.memory.max", memoryPoolBean, (mem) -> mem.getUsage().getMax()).tags(tagsWithId).description("The maximum amount of memory in bytes that can be used for memory management").baseUnit("bytes").register(registry);
}
}
Aggregations