Java Code Examples for org.eclipse.microprofile.metrics.annotation.Gauge

The following examples show how to use org.eclipse.microprofile.metrics.annotation.Gauge. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: smallrye-metrics   Source File: CDIAnnotationInfo.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String name() {
    if (annotation instanceof Counted) {
        return ((Counted) annotation).name();
    } else if (annotation instanceof ConcurrentGauge) {
        return ((ConcurrentGauge) annotation).name();
    } else if (annotation instanceof Gauge) {
        return ((Gauge) annotation).name();
    } else if (annotation instanceof Metered) {
        return ((Metered) annotation).name();
    } else if (annotation instanceof Timed) {
        return ((Timed) annotation).name();
    } else if (annotation instanceof SimplyTimed) {
        return ((SimplyTimed) annotation).name();
    } else {
        throw new IllegalArgumentException("Unknown metric annotation type " + annotation.annotationType());
    }
}
 
Example 2
Source Project: smallrye-metrics   Source File: CDIAnnotationInfo.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean absolute() {
    if (annotation instanceof Counted) {
        return ((Counted) annotation).absolute();
    } else if (annotation instanceof ConcurrentGauge) {
        return ((ConcurrentGauge) annotation).absolute();
    } else if (annotation instanceof Gauge) {
        return ((Gauge) annotation).absolute();
    } else if (annotation instanceof Metered) {
        return ((Metered) annotation).absolute();
    } else if (annotation instanceof Timed) {
        return ((Timed) annotation).absolute();
    } else if (annotation instanceof SimplyTimed) {
        return ((SimplyTimed) annotation).absolute();
    } else {
        throw SmallRyeMetricsMessages.msg.unknownMetricAnnotationType(annotation.annotationType());
    }
}
 
Example 3
Source Project: smallrye-metrics   Source File: CDIAnnotationInfo.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String[] tags() {
    if (annotation instanceof Counted) {
        return ((Counted) annotation).tags();
    } else if (annotation instanceof ConcurrentGauge) {
        return ((ConcurrentGauge) annotation).tags();
    } else if (annotation instanceof Gauge) {
        return ((Gauge) annotation).tags();
    } else if (annotation instanceof Metered) {
        return ((Metered) annotation).tags();
    } else if (annotation instanceof Timed) {
        return ((Timed) annotation).tags();
    } else if (annotation instanceof SimplyTimed) {
        return ((SimplyTimed) annotation).tags();
    } else {
        throw SmallRyeMetricsMessages.msg.unknownMetricAnnotationType(annotation.annotationType());
    }
}
 
Example 4
Source Project: smallrye-metrics   Source File: CDIAnnotationInfo.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String unit() {
    if (annotation instanceof Counted) {
        return ((Counted) annotation).unit();
    } else if (annotation instanceof ConcurrentGauge) {
        return ((ConcurrentGauge) annotation).unit();
    } else if (annotation instanceof Gauge) {
        return ((Gauge) annotation).unit();
    } else if (annotation instanceof Metered) {
        return ((Metered) annotation).unit();
    } else if (annotation instanceof Timed) {
        return ((Timed) annotation).unit();
    } else if (annotation instanceof SimplyTimed) {
        return ((SimplyTimed) annotation).unit();
    } else {
        throw SmallRyeMetricsMessages.msg.unknownMetricAnnotationType(annotation.annotationType());
    }
}
 
Example 5
Source Project: smallrye-metrics   Source File: CDIAnnotationInfo.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String description() {
    if (annotation instanceof Counted) {
        return ((Counted) annotation).description();
    } else if (annotation instanceof ConcurrentGauge) {
        return ((ConcurrentGauge) annotation).description();
    } else if (annotation instanceof Gauge) {
        return ((Gauge) annotation).description();
    } else if (annotation instanceof Metered) {
        return ((Metered) annotation).description();
    } else if (annotation instanceof Timed) {
        return ((Timed) annotation).description();
    } else if (annotation instanceof SimplyTimed) {
        return ((SimplyTimed) annotation).description();
    } else {
        throw SmallRyeMetricsMessages.msg.unknownMetricAnnotationType(annotation.annotationType());
    }
}
 
Example 6
Source Project: smallrye-metrics   Source File: CDIAnnotationInfo.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String displayName() {
    if (annotation instanceof Counted) {
        return ((Counted) annotation).displayName();
    } else if (annotation instanceof ConcurrentGauge) {
        return ((ConcurrentGauge) annotation).displayName();
    } else if (annotation instanceof Gauge) {
        return ((Gauge) annotation).displayName();
    } else if (annotation instanceof Metered) {
        return ((Metered) annotation).displayName();
    } else if (annotation instanceof Timed) {
        return ((Timed) annotation).displayName();
    } else if (annotation instanceof SimplyTimed) {
        return ((SimplyTimed) annotation).displayName();
    } else {
        throw SmallRyeMetricsMessages.msg.unknownMetricAnnotationType(annotation.annotationType());
    }
}
 
Example 7
private <X> void findAnnotatedInterfaces(@Observes @WithAnnotations({ Counted.class, Gauge.class, Metered.class,
        SimplyTimed.class, Timed.class, ConcurrentGauge.class }) ProcessAnnotatedType<X> pat) {
    Class<X> clazz = pat.getAnnotatedType().getJavaClass();
    Package pack = clazz.getPackage();
    if (pack != null && pack.getName().equals(GaugeRegistrationInterceptor.class.getPackage().getName())) {
        return;
    }
    if (clazz.isInterface()) {
        // All declared metrics of an annotated interface are registered during AfterDeploymentValidation
        metricsInterfaces.add(clazz);
    }
}
 
Example 8
private <X> void applyMetricsBinding(@Observes @WithAnnotations({ Gauge.class }) ProcessAnnotatedType<X> pat) {
    Class<X> clazz = pat.getAnnotatedType().getJavaClass();
    Package pack = clazz.getPackage();
    if (pack == null || !pack.getName().equals(GaugeRegistrationInterceptor.class.getPackage().getName())) {
        if (!clazz.isInterface()) {
            AnnotatedTypeDecorator newPAT = new AnnotatedTypeDecorator<>(pat.getAnnotatedType(), METRICS_BINDING);
            pat.setAnnotatedType(newPAT);
        }
    }

}
 
Example 9
@AroundConstruct
Object metrics(InvocationContext context) throws Exception {
    Class<?> type = context.getConstructor().getDeclaringClass();

    Object target = context.proceed();

    BeanInfoAdapter<Class<?>> beanInfoAdapter = new CDIBeanInfoAdapter();
    MemberInfoAdapter<Member> memberInfoAdapter = new CDIMemberInfoAdapter();
    // Registers the gauges over the bean type hierarchy after the target is constructed as it is required for the gauge invocations
    do {
        // TODO: discover annotations declared on implemented interfaces
        for (Method method : type.getDeclaredMethods()) {
            MetricResolver.Of<Gauge> gauge = resolver.gauge(beanInfoAdapter.convert(type),
                    memberInfoAdapter.convert(method));
            if (gauge.isPresent()) {
                AnnotationInfo g = gauge.metricAnnotation();
                Metadata metadata = MetricsMetadata.getMetadata(g, gauge.metricName(), g.unit(), g.description(),
                        g.displayName(), MetricType.GAUGE);
                registry.register(metadata, new ForwardingGauge(method, context.getTarget()),
                        TagsUtils.parseTagsAsArray(g.tags()));
            }
        }
        type = type.getSuperclass();
    } while (!Object.class.equals(type));

    return target;
}
 
Example 10
@Counted(name = "counter")
@Gauge(name = "gauge", unit = MetricUnits.NONE)
@Metered(name = "meter")
@Timed(name = "timer")
public Long metricsMethod() {
    return 1234L;
}
 
Example 11
Source Project: trader   Source File: Summary.java    License: Apache License 2.0 5 votes vote down vote up
void setPortfolioMetric(String owner, double total) {
	totals.put(owner, total);
	if (gauges.get(owner)==null) try { //gauge not yet registered for this portfolio
		org.eclipse.microprofile.metrics.Gauge<Double> gauge = () -> { return totals.get(owner); };

		Metadata metadata = Metadata.builder().withName("portfolio_value").withType(MetricType.GAUGE).withUnit(DOLLARS).build();

		metricRegistry.register(metadata, gauge, new Tag("owner", owner)); //registry injected via CDI

		gauges.put(owner, gauge);
	} catch (Throwable t) {
		logger.warning(t.getMessage());
	}
}
 
Example 12
Source Project: tomee   Source File: WeatherService.java    License: Apache License 2.0 5 votes vote down vote up
@Path("/day/temperature")
@Gauge(name = "weather_day_temperature", absolute = true, unit = "celsius",
        displayName = "Weather Day Temperature",
        description = "This metric shows the day temperature.",
        tags = {"weather=temperature"})
@GET
@Produces(MediaType.TEXT_PLAIN)
public Integer dayTemperature() {
    return 30;
}
 
Example 13
@Gauge(name = "peakOfOrders", unit = MetricUnits.NONE, description = "Highest number of orders")
public Long highestNumberOfOrders() {
    return orderRepository.countAll();
}
 
Example 14
@Gauge(name = "counter_gauge", unit = MetricUnits.NONE)
private long getCustomerCount() {
    return counter.getCount();
}
 
Example 15
@SuppressWarnings("unused")
@Gauge(name = "aGauge", unit = MetricUnits.NONE)
int myGauge() {
  return 42;
}
 
Example 16
Source Project: quarkus-deep-dive   Source File: TodoResource.java    License: Apache License 2.0 4 votes vote down vote up
@Gauge(name = "numberOfItems", unit = MetricUnits.NONE,
        description = "Number of todo list items.")
public long count() {
    return Todo.findCompleted().size();
}
 
Example 17
Source Project: boost   Source File: InventoryManager.java    License: Eclipse Public License 1.0 4 votes vote down vote up
@Gauge(unit = MetricUnits.NONE, name = "inventorySizeGuage", absolute = true, description = "Number of systems in the inventory")
public int getTotal() {
    return systems.size();
}
 
Example 18
Source Project: boost   Source File: InventoryManager.java    License: Eclipse Public License 1.0 4 votes vote down vote up
@Gauge(unit = MetricUnits.NONE, name = "inventorySizeGuage", absolute = true, description = "Number of systems in the inventory")
public int getTotal() {
    return systems.size();
}
 
Example 19
Source Project: quarkus-quickstarts   Source File: PrimeNumberChecker.java    License: Apache License 2.0 4 votes vote down vote up
@Gauge(name = "highestPrimeNumberSoFar", unit = MetricUnits.NONE, description = "Highest prime number so far.")
public Long highestPrimeNumberSoFar() {
    return highestPrimeNumberSoFar;
}
 
Example 20
@Gauge(name = "gaugeApp", absolute = true, unit = MetricUnits.NONE)
public Long gauge() {
    return ++i;
}
 
Example 21
@Gauge(name = "gauge", absolute = true, unit = MetricUnits.DAYS)
public Long gaugedMethod() {
    return 42L;
}
 
Example 22
Source Project: smallrye-metrics   Source File: MetricResolver.java    License: Apache License 2.0 4 votes vote down vote up
public Of<Gauge> gauge(BeanInfo topClass, MemberInfo method) {
    return resolverOf(topClass, method, Gauge.class);
}
 
Example 23
Source Project: quarkus   Source File: DummyGaugeNoReflectionAnnotation.java    License: Apache License 2.0 4 votes vote down vote up
@Gauge(name = "dummyGauge", unit = MetricUnits.NONE)
public Long dummyGauge() {
    return 1234l;
}
 
Example 24
Source Project: quarkus   Source File: DummyGauge.java    License: Apache License 2.0 4 votes vote down vote up
@Gauge(name = "dummyGauge", unit = MetricUnits.NONE)
public Long dummyGauge() {
    return 42l;
}
 
Example 25
Source Project: quarkus   Source File: MetricsResource.java    License: Apache License 2.0 4 votes vote down vote up
@GET
@Path("/gauge")
@Gauge(name = "gauge", unit = MetricUnits.NONE)
public Long gauge() {
    return 42L;
}
 
Example 26
@Gauge(name = "childGaugeMethod", unit = MetricUnits.NONE)
public long getChildGauge() {
    return childGauge;
}
 
Example 27
@Gauge(name = "inheritedParentGaugeMethod", unit=MetricUnits.NONE)
public long getGauge() {
    return gauge;
}
 
Example 28
@Gauge(name = "inheritedChildGaugeMethod", unit = MetricUnits.NONE)
public long getChildGauge() {
    return childGauge;
}
 
Example 29
Source Project: microprofile-metrics   Source File: GaugeMethodBean.java    License: Apache License 2.0 4 votes vote down vote up
@Gauge(name = "gaugeMethod", unit=MetricUnits.NONE)
public long getGauge() {
    return gauge;
}
 
Example 30
Source Project: microprofile-metrics   Source File: GaugeTagMethodBean.java    License: Apache License 2.0 4 votes vote down vote up
@Gauge(name = "gaugeMethod", unit=MetricUnits.NONE, tags = {"number=one"})
public long getGaugeOne() {
    return gaugeOne;
}