Java Code Examples for org.eclipse.microprofile.metrics.MetricType#GAUGE

The following examples show how to use org.eclipse.microprofile.metrics.MetricType#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: MetricsRegistryImpl.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
private MetricType metricTypeFromClass(Class<?> in) {
    if (in.equals(Counter.class)) {
        return MetricType.COUNTER;
    } else if (in.equals(Gauge.class)) {
        return MetricType.GAUGE;
    } else if (in.equals(ConcurrentGauge.class)) {
        return MetricType.CONCURRENT_GAUGE;
    } else if (in.equals(Meter.class)) {
        return MetricType.METERED;
    } else if (in.equals(Timer.class)) {
        return MetricType.TIMER;
    } else if (in.equals(SimpleTimer.class)) {
        return MetricType.SIMPLE_TIMER;
    } else if (in.equals(Histogram.class)) {
        return MetricType.HISTOGRAM;
    }
    return null;
}
 
Example 2
Source File: OpenMetricsExporterTest.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void testUptimeGaugeUnitConversion() {
    OpenMetricsExporter exporter = new OpenMetricsExporter();
    MetricRegistry baseRegistry = MetricRegistries.get(MetricRegistry.Type.BASE);

    Gauge gauge = new MGaugeImpl(JmxWorker.instance(), "java.lang:type=Runtime/Uptime");
    Metadata metadata = new ExtendedMetadata("jvm.uptime", "display name", "description", MetricType.GAUGE, "milliseconds");
    baseRegistry.register(metadata, gauge);

    long actualUptime /* in ms */ = ManagementFactory.getRuntimeMXBean().getUptime();
    double actualUptimeInSeconds = actualUptime / 1000.0;

    StringBuilder out = exporter.exportOneMetric(MetricRegistry.Type.BASE, new MetricID("jvm.uptime"));
    assertNotNull(out);

    double valueFromOpenMetrics = -1;
    for (String line : out.toString().split(System.getProperty("line.separator"))) {
        if (line.startsWith("base_jvm_uptime_seconds")) {
            valueFromOpenMetrics /* in seconds */ = Double
                    .valueOf(line.substring("base:jvm_uptime_seconds".length()).trim());
        }
    }
    assertTrue("Value should not be -1", valueFromOpenMetrics != -1);
    assertTrue(valueFromOpenMetrics >= actualUptimeInSeconds);
}
 
Example 3
Source File: OpenMetricsExporterTest.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void testNameOverride() {
    OpenMetricsExporter exporter = new OpenMetricsExporter();
    MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION);

    Metadata metadata = new ExtendedMetadata("voltage1",
            "Voltage",
            "Measures your electric potential",
            MetricType.GAUGE,
            "volts",
            null,
            false,
            Optional.of(true),
            false,
            "baz");
    Tag tag = new Tag("a", "b");
    registry.register(metadata, (Gauge<Long>) () -> 3L, tag);

    String result = exporter.exportOneScope(MetricRegistry.Type.APPLICATION).toString();
    System.out.println(result);
    assertHasHelpLineExactlyOnce(result, "application_baz", "Measures your electric potential");
    assertHasTypeLineExactlyOnce(result, "application_baz", "gauge");
    assertHasValueLineExactlyOnce(result, "application_baz", "3.0", tag);
}
 
Example 4
Source File: SmallRyeMetricsProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Obtains the MetricType from a bean that is a producer method or field,
 * or null if no MetricType can be detected.
 */
private MetricType getMetricType(ClassInfo clazz) {
    DotName name = clazz.name();
    if (name.equals(GAUGE_INTERFACE)) {
        return MetricType.GAUGE;
    }
    if (name.equals(COUNTER_INTERFACE)) {
        return MetricType.COUNTER;
    }
    if (name.equals(CONCURRENT_GAUGE_INTERFACE)) {
        return MetricType.CONCURRENT_GAUGE;
    }
    if (name.equals(HISTOGRAM_INTERFACE)) {
        return MetricType.HISTOGRAM;
    }
    if (name.equals(SIMPLE_TIMER_INTERFACE)) {
        return MetricType.SIMPLE_TIMER;
    }
    if (name.equals(TIMER_INTERFACE)) {
        return MetricType.TIMER;
    }
    if (name.equals(METER_INTERFACE)) {
        return MetricType.METERED;
    }
    return null;
}
 
Example 5
Source File: MetricBuildItem.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Create a metric build item from the specified metadata and tags.
 * Such metric will be picked up by the Metrics extension and registered in the VENDOR registry.
 * This constructor is applicable to all metric types except gauges.
 *
 * @param metadata The metadata that should be applied to the registered metric
 * @param enabled Whether this metric is enabled
 * @param tags The tags that will be applied to this metric
 * @param configRootName the name of the root configuration of the extension as defined by the <code>@ConfigRoot</code>
 *        annotation.
 */
public MetricBuildItem(Metadata metadata, boolean enabled, String configRootName, Tag... tags) {
    if (metadata.getTypeRaw() == MetricType.GAUGE) {
        throw new IllegalArgumentException("Gauges require a non-null implementation object");
    }
    this.metadata = metadata;
    this.tags = tags;
    this.implementor = null;
    this.enabled = enabled;
    this.configRootName = configRootName;
    this.registryType = MetricRegistry.Type.VENDOR;
}
 
Example 6
Source File: MetricBuildItem.java    From quarkus with Apache License 2.0 3 votes vote down vote up
/**
 * Create a metric build item from the specified metadata, tags, and a callable.
 * Such metric will be picked up by the Metrics extension and registered in the VENDOR registry.
 *
 * @param metadata The metadata that should be applied to the registered metric
 * @param implementor The object that implements the metric. It must be an instance of the appropriate
 *        metric class (from the {@link org.eclipse.microprofile.metrics} package).
 *        This is required for gauges and optional for all other metric types.
 * @param enabled Whether this metric is enabled
 * @param tags The tags that will be applied to this metric
 * @param configRootName the name of the root configuration of the extension as defined by the <code>@ConfigRoot</code>
 *        annotation.
 *
 */
public MetricBuildItem(Metadata metadata, Object implementor, boolean enabled, String configRootName, Tag... tags) {
    if (implementor == null && metadata.getTypeRaw() == MetricType.GAUGE) {
        throw new IllegalArgumentException("Gauges require a non-null implementation object");
    }
    this.metadata = metadata;
    this.tags = tags;
    this.implementor = implementor;
    this.enabled = enabled;
    this.configRootName = configRootName;
    this.registryType = MetricRegistry.Type.VENDOR;
}
 
Example 7
Source File: MetricBuildItem.java    From quarkus with Apache License 2.0 3 votes vote down vote up
/**
 * Create a metric build item from the specified metadata, tags, a callable, and scope.
 * Such metric will be picked up by the Metrics extension and registered in the registry for the desired scope.
 *
 * @param metadata The metadata that should be applied to the registered metric
 * @param implementor The object that implements the metric. It must be an instance of the appropriate
 *        metric class (from the {@link org.eclipse.microprofile.metrics} package).
 *        This is required for gauges and optional for all other metric types.
 * @param enabled Whether this metric is enabled
 * @param tags The tags that will be applied to this metric
 * @param configRootName the name of the root configuration of the extension as defined by the <code>@ConfigRoot</code>
 *        annotation.
 * @param registryType Registry where the metric should be placed
 *
 */
public MetricBuildItem(Metadata metadata, Object implementor, boolean enabled, String configRootName,
        MetricRegistry.Type registryType, Tag... tags) {
    if (implementor == null && metadata.getTypeRaw() == MetricType.GAUGE) {
        throw new IllegalArgumentException("Gauges require a non-null implementation object");
    }
    this.metadata = metadata;
    this.tags = tags;
    this.implementor = implementor;
    this.enabled = enabled;
    this.configRootName = configRootName;
    this.registryType = registryType;
}