Search in sources :

Example 1 with Tag

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);
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Tag(io.micrometer.core.instrument.Tag) HystrixPropertiesCommandDefault(com.netflix.hystrix.strategy.properties.HystrixPropertiesCommandDefault) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with Tag

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);
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) TooManyActiveSessionsException(org.apache.catalina.session.TooManyActiveSessionsException) ManagerBase(org.apache.catalina.session.ManagerBase) StandardSession(org.apache.catalina.session.StandardSession) StandardContext(org.apache.catalina.core.StandardContext) Tag(io.micrometer.core.instrument.Tag) Test(org.junit.jupiter.api.Test)

Example 3 with Tag

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);
    }
}
Also used : PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) PlatformConfiguration(com.canoo.platform.core.PlatformConfiguration) ProcessorMetrics(io.micrometer.core.instrument.binder.system.ProcessorMetrics) RequestMetricsFilter(com.canoo.dp.impl.platform.server.metrics.servlet.RequestMetricsFilter) JvmMemoryMetrics(io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics) JvmGcMetrics(io.micrometer.core.instrument.binder.jvm.JvmGcMetrics) ClassLoaderMetrics(io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics) JvmThreadMetrics(io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics) MetricsHttpSessionListener(com.canoo.dp.impl.platform.server.metrics.servlet.MetricsHttpSessionListener) MetricsServlet(com.canoo.dp.impl.platform.server.metrics.servlet.MetricsServlet) ServletContext(javax.servlet.ServletContext) Tag(io.micrometer.core.instrument.Tag) DispatcherType(javax.servlet.DispatcherType)

Example 4 with Tag

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);
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Tag(io.micrometer.core.instrument.Tag) HystrixPropertiesCommandDefault(com.netflix.hystrix.strategy.properties.HystrixPropertiesCommandDefault) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 5 with Tag

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);
    }
}
Also used : BufferPoolMXBean(java.lang.management.BufferPoolMXBean) Tag(io.micrometer.core.instrument.Tag) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Aggregations

Tag (io.micrometer.core.instrument.Tag)6 Test (org.junit.jupiter.api.Test)3 HystrixPropertiesCommandDefault (com.netflix.hystrix.strategy.properties.HystrixPropertiesCommandDefault)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 Disabled (org.junit.jupiter.api.Disabled)2 MetricsHttpSessionListener (com.canoo.dp.impl.platform.server.metrics.servlet.MetricsHttpSessionListener)1 MetricsServlet (com.canoo.dp.impl.platform.server.metrics.servlet.MetricsServlet)1 RequestMetricsFilter (com.canoo.dp.impl.platform.server.metrics.servlet.RequestMetricsFilter)1 PlatformConfiguration (com.canoo.platform.core.PlatformConfiguration)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ClassLoaderMetrics (io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics)1 JvmGcMetrics (io.micrometer.core.instrument.binder.jvm.JvmGcMetrics)1 JvmMemoryMetrics (io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics)1 JvmThreadMetrics (io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics)1 ProcessorMetrics (io.micrometer.core.instrument.binder.system.ProcessorMetrics)1 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)1 SeldonAPIException (io.seldon.apife.exception.SeldonAPIException)1 Feedback (io.seldon.protos.PredictionProtos.Feedback)1 BufferPoolMXBean (java.lang.management.BufferPoolMXBean)1 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)1