Search in sources :

Example 21 with Metadata

use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.

the class AnnotationReaderGetOrRegisterTest method gaugeFromMetdadata.

@Test
@Gauge(tags = { "a=b", "c=d" }, unit = MetricUnits.HOURS, description = "description")
public void gaugeFromMetdadata() {
    Metadata annoated = AnnotationReader.GAUGE.metadata(getClass(), TestUtils.getTestMethod());
    String name = getClass().getCanonicalName() + ".gaugeFromMetdadata";
    Metadata expected = Metadata.builder(annoated).withName(name).build();
    org.eclipse.microprofile.metrics.Gauge<Long> gauge = () -> 1L;
    registry.register(expected, gauge, new Tag("a", "b"), new Tag("c", "d"));
    InjectionPoint point = testMethodAsInjectionPoint();
    org.eclipse.microprofile.metrics.Gauge<?> gauge2 = AnnotationReader.GAUGE.getOrRegister(point, org.eclipse.microprofile.metrics.Gauge.class, registry);
    assertNotNull(gauge2);
    assertSame(gauge, gauge2);
}
Also used : InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) Metadata(org.eclipse.microprofile.metrics.Metadata) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test) Gauge(org.eclipse.microprofile.metrics.annotation.Gauge) ConcurrentGauge(org.eclipse.microprofile.metrics.annotation.ConcurrentGauge)

Example 22 with Metadata

use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.

the class JsonExporterOptionsTest method singleMetricOption.

@Test
public void singleMetricOption() {
    Gauge<Long> fooVal = () -> 1L;
    MetricID fooValID = new MetricID("fooVal", new Tag("store", "webshop"));
    Metadata fooValMeta = Metadata.builder().withName("fooVal").withDescription("The size of foo after each request").withUnit(MetricUnits.MILLISECONDS).withDisplayName("Size of foo").withType(MetricType.GAUGE).build();
    export(fooValID, fooVal, fooValMeta);
    assertOutputEqualsFile("Options1.json");
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Metadata(org.eclipse.microprofile.metrics.Metadata) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 23 with Metadata

use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.

the class JsonExporterOptionsTest method gaugesWithNonNumberValuesDoExportMetadata.

@Test
public void gaugesWithNonNumberValuesDoExportMetadata() {
    Gauge<String> gauge = () -> "hello world";
    MetricID metricID = new MetricID("test3");
    Metadata metadata = Metadata.builder().withName(metricID.getName()).withType(MetricType.GAUGE).build();
    assertOutputEquals("\n" + "{\n" + "    \"test3\": {\n" + "        \"unit\": \"none\",\n" + "        \"type\": \"gauge\"\n" + "    }\n" + "}", metricID, gauge, metadata);
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Metadata(org.eclipse.microprofile.metrics.Metadata) Test(org.junit.Test)

Example 24 with Metadata

use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.

the class MetricRegistryImpl method findMetricOrCreate.

private <T extends Metric> T findMetricOrCreate(String name, MetricType metricType, T metric, Tag... tags) {
    checkNameIsNotNullOrEmpty(name);
    Metadata metadata = Metadata.builder().withName(name).withType(metricType).withDisplayName("").build();
    return findMetricOrCreate(metadata, true, metric, tags);
}
Also used : Metadata(org.eclipse.microprofile.metrics.Metadata)

Example 25 with Metadata

use of org.eclipse.microprofile.metrics.Metadata in project wildfly-swarm by wildfly-swarm.

the class MetricsInterceptor method metrics.

@AroundConstruct
private Object metrics(InvocationContext context) throws Exception {
    Class<?> bean = context.getConstructor().getDeclaringClass();
    LOGGER.infof("MetricsInterceptor, bean=%s\n", bean);
    // Registers the bean constructor metrics
    registerMetrics(bean, context.getConstructor());
    // Registers the methods metrics over the bean type hierarchy
    Class<?> type = bean;
    do {
        // TODO: discover annotations declared on implemented interfaces
        for (Method method : type.getDeclaredMethods()) {
            if (!method.isSynthetic() && !Modifier.isPrivate(method.getModifiers())) {
                registerMetrics(bean, method);
            }
        }
        type = type.getSuperclass();
    } while (!Object.class.equals(type));
    Object target = context.proceed();
    // Registers the gauges over the bean type hierarchy after the target is constructed as it is required for the gauge invocations
    type = bean;
    do {
        // TODO: discover annotations declared on implemented interfaces
        for (Method method : type.getDeclaredMethods()) {
            MetricResolver.Of<Gauge> gauge = resolver.gauge(bean, method);
            if (gauge.isPresent()) {
                Gauge g = gauge.metricAnnotation();
                Metadata metadata = getMetadata(gauge.metricName(), g.unit(), g.description(), g.displayName(), MetricType.GAUGE, g.tags());
                registry.register(metadata, new ForwardingGauge(method, context.getTarget()));
            }
        }
        type = type.getSuperclass();
    } while (!Object.class.equals(type));
    return target;
}
Also used : Metadata(org.eclipse.microprofile.metrics.Metadata) Method(java.lang.reflect.Method) Gauge(org.eclipse.microprofile.metrics.annotation.Gauge) AroundConstruct(javax.interceptor.AroundConstruct)

Aggregations

Metadata (org.eclipse.microprofile.metrics.Metadata)65 MetricID (org.eclipse.microprofile.metrics.MetricID)31 Test (org.junit.Test)30 Tag (org.eclipse.microprofile.metrics.Tag)12 Counter (org.eclipse.microprofile.metrics.Counter)9 Metric (org.eclipse.microprofile.metrics.Metric)9 MetricRegistry (org.eclipse.microprofile.metrics.MetricRegistry)8 HashMap (java.util.HashMap)6 Map (java.util.Map)4 Histogram (org.eclipse.microprofile.metrics.Histogram)4 ArrayList (java.util.ArrayList)3 Meter (org.eclipse.microprofile.metrics.Meter)3 Gauge (org.eclipse.microprofile.metrics.annotation.Gauge)3 ObjectName (javax.management.ObjectName)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Gauge (org.eclipse.microprofile.metrics.Gauge)2 MetricType (org.eclipse.microprofile.metrics.MetricType)2 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)2 Snapshot (org.eclipse.microprofile.metrics.Snapshot)2