Search in sources :

Example 1 with MetricID

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

the class TestUtils method parseMetricID.

/**
 * Parses text form of a {@link MetricID} back to object.
 *
 * This supports both the result of calling {@link MetricID#toString()} as well as a simplified more user friendly form illustrated in the examples below:
 *
 * <pre>
 * my-metric-name
 * my-metric-name[tag=value,tag=value]
 * </pre>
 *
 * @param metric text form of a {@link MetricID}
 * @return
 */
public static MetricID parseMetricID(String metric) {
    int startOfTags = metric.indexOf('[');
    if (startOfTags < 0) {
        // no tags, must be simple format
        return new MetricID(metric);
    }
    int endOfTags = metric.indexOf(']');
    String[] tagNameValues = metric.substring(startOfTags + 1, endOfTags).split(",");
    Tag[] tags = new Tag[tagNameValues.length];
    for (int i = 0; i < tagNameValues.length; i++) {
        String tag = tagNameValues[i];
        int endOfName = tag.indexOf('=');
        String value = tag.substring(endOfName + 1);
        if (value.startsWith("\"") && value.endsWith("\"")) {
            value = value.substring(1, value.length() - 1);
        }
        tags[i] = new Tag(tag.substring(0, endOfName), value);
    }
    if (metric.startsWith("MetricID{")) {
        int startOfName = metric.indexOf('\'');
        return new MetricID(metric.substring(startOfName + 1, metric.indexOf('\'', startOfName + 1)), tags);
    }
    return new MetricID(metric.substring(0, startOfTags), tags);
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Tag(org.eclipse.microprofile.metrics.Tag)

Example 2 with MetricID

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

the class MethodFaultToleranceMetrics method withMethodTag.

private MetricID withMethodTag(String metric, Tag[] tags) {
    Tag method = new Tag("method", canonicalMethodName);
    if (tags.length == 0) {
        return new MetricID(metric, method);
    }
    Tag[] newTags = new Tag[tags.length + 1];
    newTags[0] = method;
    arraycopy(tags, 0, newTags, 1, tags.length);
    return new MetricID(metric, newTags);
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Tag(org.eclipse.microprofile.metrics.Tag)

Example 3 with MetricID

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

the class BulkheadMetricTckTest method bulkheadMetricHistogramTest.

/**
 * Scenario is equivalent to the TCK test of same name but not 100% identical
 */
@Test(timeout = 3000)
public void bulkheadMetricHistogramTest() {
    callMethodWithNewThreadAndWaitFor(commonWaiter);
    callMethodWithNewThreadAndWaitFor(commonWaiter);
    waitUntilPermitsAquired(2, 0);
    assertFurtherThreadThrowsBulkheadException(1);
    waitSome(100);
    commonWaiter.complete(null);
    waitUntilPermitsAquired(0, 0);
    Histogram executionTimes = registry.getHistogram(new MetricID("ft.bulkhead.runningDuration", new Tag("method", "fish.payara.microprofile.faulttolerance.policy.BulkheadMetricTckTest.bulkheadMetricHistogramTest_Method")));
    Snapshot snap = executionTimes.getSnapshot();
    assertNotNull(executionTimes);
    assertEquals(2, executionTimes.getCount());
    assertApproxMillis(100, Math.round(snap.getMedian()));
    assertApproxMillis(100, Math.round(snap.getMean()));
    // Now let's put some quick results through the bulkhead
    callMethodDirectly(null);
    callMethodDirectly(null);
    assertEquals(4, executionTimes.getCount());
    snap = executionTimes.getSnapshot();
    assertApproxMillis(50, Math.round(snap.getMean()));
}
Also used : Snapshot(org.eclipse.microprofile.metrics.Snapshot) Histogram(org.eclipse.microprofile.metrics.Histogram) MetricID(org.eclipse.microprofile.metrics.MetricID) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 4 with MetricID

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

the class AbstractInterceptor method apply.

protected static <E extends Member & AnnotatedElement, M extends Metric> M apply(E element, Class<?> bean, AnnotationReader<?> reader, Class<M> metricType, BiFunction<MetricID, Class<M>, M> loader) {
    MetricID metricID = reader.metricID(bean, element);
    M metric = loader.apply(metricID, metricType);
    if (metric == null) {
        throw new IllegalStateException("No " + metricType.getSimpleName() + " with ID [" + metricID + "] found in application registry");
    }
    return metric;
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID)

Example 5 with MetricID

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

the class MetricsServiceImpl method processMetadataToAnnotations.

private static void processMetadataToAnnotations(MetricsContextImpl context, MonitoringDataCollector collector) {
    RegisteredMetric metric = context.pollNewlyRegistered();
    while (metric != null) {
        MetricID metricID = metric.id;
        Type scope = metric.scope;
        MetricRegistry registry = context.getRegistry(scope);
        MonitoringDataCollector metricCollector = tagCollector(context.getName(), metricID, collector);
        Metadata metadata = registry.getMetadata(metricID.getName());
        String suffix = "Count";
        String property = "Count";
        boolean isGauge = metadata.getTypeRaw() == MetricType.GAUGE;
        if (isGauge) {
            suffix = getMetricUnitSuffix(metadata.unit());
            property = "Value";
        }
        // Note that by convention an annotation with value 0 done before the series collected any value is considered permanent
        metricCollector.annotate(toName(metricID, suffix), 0, false, metadataToAnnotations(context.getName(), scope, metadata, property));
        metric = context.pollNewlyRegistered();
    }
}
Also used : MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) MetricID(org.eclipse.microprofile.metrics.MetricID) MetricType(org.eclipse.microprofile.metrics.MetricType) Type(org.eclipse.microprofile.metrics.MetricRegistry.Type) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) Metadata(org.eclipse.microprofile.metrics.Metadata) MBeanMetadata(fish.payara.microprofile.metrics.jmx.MBeanMetadata)

Aggregations

MetricID (org.eclipse.microprofile.metrics.MetricID)53 Test (org.junit.Test)41 Metadata (org.eclipse.microprofile.metrics.Metadata)31 Tag (org.eclipse.microprofile.metrics.Tag)25 Counter (org.eclipse.microprofile.metrics.Counter)10 Metric (org.eclipse.microprofile.metrics.Metric)6 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)6 Snapshot (org.eclipse.microprofile.metrics.Snapshot)6 Histogram (org.eclipse.microprofile.metrics.Histogram)5 ConcurrentGauge (org.eclipse.microprofile.metrics.ConcurrentGauge)4 Timer (org.eclipse.microprofile.metrics.Timer)4 Gauge (org.eclipse.microprofile.metrics.Gauge)3 MonitoringDataCollector (fish.payara.monitoring.collect.MonitoringDataCollector)2 ArrayList (java.util.ArrayList)2 Meter (org.eclipse.microprofile.metrics.Meter)2 NoSuchRegistryException (fish.payara.microprofile.metrics.exception.NoSuchRegistryException)1 TimerImpl (fish.payara.microprofile.metrics.impl.TimerImpl)1 MBeanMetadata (fish.payara.microprofile.metrics.jmx.MBeanMetadata)1 FileNotFoundException (java.io.FileNotFoundException)1 Collections.emptyMap (java.util.Collections.emptyMap)1