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

The following examples show how to use org.eclipse.microprofile.metrics.annotation.Gauge. 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 File: CDIAnnotationInfo.java    From smallrye-metrics with 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 #2
Source File: CDIAnnotationInfo.java    From smallrye-metrics with 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 #3
Source File: CDIAnnotationInfo.java    From smallrye-metrics with 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 #4
Source File: CDIAnnotationInfo.java    From smallrye-metrics with 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 #5
Source File: CDIAnnotationInfo.java    From smallrye-metrics with 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 #6
Source File: CDIAnnotationInfo.java    From smallrye-metrics with 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 #7
Source File: MultipleMetricsMethodBean.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Counted(name = "counter")
@Gauge(name = "gauge", unit = MetricUnits.NONE)
@Metered(name = "meter")
@Timed(name = "timer")
public Long metricsMethod() {
    return 1234L;
}
 
Example #8
Source File: Summary.java    From trader with 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 #9
Source File: GaugeRegistrationInterceptor.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
@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
Source File: MetricCdiInjectionExtension.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
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 #11
Source File: MetricCdiInjectionExtension.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
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 #12
Source File: WeatherService.java    From tomee with 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
Source File: Summary.java    From trader with Apache License 2.0 4 votes vote down vote up
@Gauge(name="portfolio_loyalty", tags="level=basic", displayName="Basic", unit=MetricUnits.NONE)
public int getBasic() {
	return basic;
}
 
Example #14
Source File: Summary.java    From trader with Apache License 2.0 4 votes vote down vote up
@Gauge(name="portfolio_loyalty", tags="level=bronze", displayName="Bronze", unit=MetricUnits.NONE)
public int getBronze() {
	return bronze;
}
 
Example #15
Source File: Summary.java    From trader with Apache License 2.0 4 votes vote down vote up
@Gauge(name="portfolio_loyalty", tags="level=silver", displayName="Silver", unit=MetricUnits.NONE)
public int getSilver() {
	return silver;
}
 
Example #16
Source File: Summary.java    From trader with Apache License 2.0 4 votes vote down vote up
@Gauge(name="portfolio_loyalty", tags="level=gold", displayName="Gold", unit=MetricUnits.NONE)
public int getGold() {
	return gold;
}
 
Example #17
Source File: Summary.java    From trader with Apache License 2.0 4 votes vote down vote up
@Gauge(name="portfolio_loyalty", tags="level=platinum", displayName="Platinum", unit=MetricUnits.NONE)
public int getPlatinum() {
	return platinum;
}
 
Example #18
Source File: Summary.java    From trader with Apache License 2.0 4 votes vote down vote up
@Gauge(name="portfolio_loyalty", tags="level=unknown", displayName="Unknown", unit=MetricUnits.NONE)
public int getUnknown() {
	return unknown;
}
 
Example #19
Source File: MetricController.java    From ci.maven with Apache License 2.0 4 votes vote down vote up
@Gauge(name = "counter_gauge", unit = MetricUnits.NONE)
private long getCustomerCount() {
    return counter.getCount();
}
 
Example #20
Source File: GaugeInjectionBean.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Gauge(name = "gaugeInjection", unit=MetricUnits.NONE)
public long getGauge() {
    return gauge;
}
 
Example #21
Source File: GaugeTagMethodBean.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Gauge(name = "gaugeMethod", unit=MetricUnits.NONE, tags = {"number=two"})
public long getGaugeTwo() {
    return gaugeTwo;
}
 
Example #22
Source File: GaugeTagMethodBean.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Gauge(name = "gaugeMethod", unit=MetricUnits.NONE, tags = {"number=one"})
public long getGaugeOne() {
    return gaugeOne;
}
 
Example #23
Source File: GaugeMethodBean.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Gauge(name = "gaugeMethod", unit=MetricUnits.NONE)
public long getGauge() {
    return gauge;
}
 
Example #24
Source File: DummyGaugeNoReflectionAnnotation.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Gauge(name = "dummyGauge", unit = MetricUnits.NONE)
public Long dummyGauge() {
    return 1234l;
}
 
Example #25
Source File: InheritedChildGaugeMethodBean.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Gauge(name = "inheritedChildGaugeMethod", unit = MetricUnits.NONE)
public long getChildGauge() {
    return childGauge;
}
 
Example #26
Source File: InheritedParentGaugeMethodBean.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Gauge(name = "inheritedParentGaugeMethod", unit=MetricUnits.NONE)
public long getGauge() {
    return gauge;
}
 
Example #27
Source File: InheritedGaugeMethodBean.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Gauge(name = "childGaugeMethod", unit = MetricUnits.NONE)
public long getChildGauge() {
    return childGauge;
}
 
Example #28
Source File: MetricsResource.java    From quarkus with 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 #29
Source File: DummyGauge.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Gauge(name = "dummyGauge", unit = MetricUnits.NONE)
public Long dummyGauge() {
    return 42l;
}
 
Example #30
Source File: OrderEndpoint.java    From Hands-On-Cloud-Native-Applications-with-Java-and-Quarkus with MIT License 4 votes vote down vote up
@Gauge(name = "peakOfOrders", unit = MetricUnits.NONE, description = "Highest number of orders")
public Long highestNumberOfOrders() {
    return orderRepository.countAll();
}