Remove metric registry and fix examples. (#238)
This commit is contained in:
parent
3cc0af53af
commit
750e16c5e7
|
|
@ -23,50 +23,33 @@ import javax.annotation.concurrent.ThreadSafe;
|
|||
* Counter metric, to report instantaneous measurement of a double value. Cumulative values can go
|
||||
* up or stay the same, but can never go down. Cumulative values cannot be negative.
|
||||
*
|
||||
* <p>Example 1: Create a Cumulative with default labels.
|
||||
* <p>Example:
|
||||
*
|
||||
* <pre>{@code
|
||||
* class YourClass {
|
||||
*
|
||||
* private static final Meter meter = Metrics.getMeter();
|
||||
* private static final MetricRegistry metricRegistry = meter.metricRegistryBuilder().build();
|
||||
*
|
||||
* List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("Name", "desc"));
|
||||
*
|
||||
* CounterDouble cumulative = metricRegistry.addDoubleCumulative("processed_jobs",
|
||||
* "Processed jobs", "1", labelKeys);
|
||||
*
|
||||
* private static final CounterDouble counter =
|
||||
* meter.
|
||||
* .counterDoubleBuilder("processed_jobs")
|
||||
* .setDescription("Processed jobs")
|
||||
* .setUnit("1")
|
||||
* .setLabelKeys(Collections.singletonList(LabelKey.create("Name", "desc")))
|
||||
* .build();
|
||||
* // It is recommended to keep a reference of a TimeSeries.
|
||||
* CounterDouble.TimeSeries defaultTimeSeries = cumulative.getDefaultTimeSeries();
|
||||
* private static final CounterDouble.TimeSeries inboundTimeSeries =
|
||||
* counter.getOrCreateTimeSeries(Collections.singletonList(LabelValue.create("SomeWork")));
|
||||
* private static final CounterDouble.TimeSeries defaultTimeSeries =
|
||||
* counter.getDefaultTimeSeries();
|
||||
*
|
||||
* void doWork() {
|
||||
* void doDefaultWork() {
|
||||
* // Your code here.
|
||||
* defaultPoint.add(10);
|
||||
* defaultTimeSeries.add(10);
|
||||
* }
|
||||
*
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* <p>Example 2: You can also use labels (keys and values) to track different types of metric.
|
||||
*
|
||||
* <pre>{@code
|
||||
* class YourClass {
|
||||
*
|
||||
* private static final Meter meter = Metrics.getMeter();
|
||||
* private static final MetricRegistry metricRegistry = meter.metricRegistryBuilder().build();
|
||||
*
|
||||
* List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("Name", "desc"));
|
||||
* List<LabelValue> labelValues = Arrays.asList(LabelValue.create("Inbound"));
|
||||
*
|
||||
* CounterDouble cumulative = metricRegistry.addDoubleCumulative("processed_jobs",
|
||||
* "Processed jobs", "1", labelKeys);
|
||||
*
|
||||
* // It is recommended to keep a reference of a TimeSeries.
|
||||
* CounterDouble.TimeSeries inboundTimeSeries = cumulative.getOrCreateTimeSeries(labelValues);
|
||||
*
|
||||
* void doSomeWork() {
|
||||
* // Your code here.
|
||||
* inboundPoint.set(15);
|
||||
* inboundTimeSeries.set(15);
|
||||
* }
|
||||
*
|
||||
* }
|
||||
|
|
|
|||
|
|
@ -24,50 +24,32 @@ import javax.annotation.concurrent.ThreadSafe;
|
|||
* Counter metric, to report instantaneous measurement of a long value. Cumulative values can go up
|
||||
* or stay the same, but can never go down. Cumulative values cannot be negative.
|
||||
*
|
||||
* <p>Example 1: Create a Cumulative with default labels.
|
||||
* <p>Example:
|
||||
*
|
||||
* <pre>{@code
|
||||
* class YourClass {
|
||||
*
|
||||
* private static final Meter meter = Metrics.getMeter();
|
||||
* private static final MetricRegistry metricRegistry = meter.metricRegistryBuilder().build();
|
||||
*
|
||||
* List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("Name", "desc"));
|
||||
*
|
||||
* CounterLong cumulative = metricRegistry.addLongCumulative("processed_jobs",
|
||||
* "Processed jobs", "1", labelKeys);
|
||||
*
|
||||
* private static final CounterLong counter =
|
||||
* meter.
|
||||
* .counterLongBuilder("processed_jobs")
|
||||
* .setDescription("Processed jobs")
|
||||
* .setUnit("1")
|
||||
* .setLabelKeys(Collections.singletonList(LabelKey.create("Name", "desc")))
|
||||
* .build();
|
||||
* // It is recommended to keep a reference of a TimeSeries.
|
||||
* CounterLong.TimeSeries defaultTimeSeries = cumulative.getDefaultTimeSeries();
|
||||
* private static final CounterLong.TimeSeries inboundTimeSeries =
|
||||
* counter.getOrCreateTimeSeries(Collections.singletonList(LabelValue.create("SomeWork")));
|
||||
* private static final CounterLong.TimeSeries defaultTimeSeries = counter.getDefaultTimeSeries();
|
||||
*
|
||||
* void doWork() {
|
||||
* void doDefaultWork() {
|
||||
* // Your code here.
|
||||
* defaultPoint.add(10);
|
||||
* defaultTimeSeries.add(10);
|
||||
* }
|
||||
*
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* <p>Example 2: You can also use labels (keys and values) to track different types of metric.
|
||||
*
|
||||
* <pre>{@code
|
||||
* class YourClass {
|
||||
*
|
||||
* private static final Meter meter = Metrics.getMeter();
|
||||
* private static final MetricRegistry metricRegistry = meter.metricRegistryBuilder().build();
|
||||
*
|
||||
* List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("Name", "desc"));
|
||||
* List<LabelValue> labelValues = Arrays.asList(LabelValue.create("Inbound"));
|
||||
*
|
||||
* CounterLong cumulative = metricRegistry.addLongCumulative("processed_jobs",
|
||||
* "Processed jobs", "1", labelKeys);
|
||||
*
|
||||
* // It is recommended to keep a reference of a TimeSeries.
|
||||
* CounterLong.TimeSeries inboundTimeSeries = cumulative.getOrCreateTimeSeries(labelValues);
|
||||
*
|
||||
* void doSomeWork() {
|
||||
* // Your code here.
|
||||
* inboundPoint.set(15);
|
||||
* inboundTimeSeries.set(15);
|
||||
* }
|
||||
*
|
||||
* }
|
||||
|
|
|
|||
|
|
@ -24,50 +24,32 @@ import javax.annotation.concurrent.ThreadSafe;
|
|||
* Gauge metric, to report instantaneous measurement of a double value. Gauges can go both up and
|
||||
* down. The gauges values can be negative.
|
||||
*
|
||||
* <p>Example 1: Create a Gauge with default labels.
|
||||
* <p>Example:
|
||||
*
|
||||
* <pre>{@code
|
||||
* class YourClass {
|
||||
*
|
||||
* private static final Meter meter = Metrics.getMeter();
|
||||
* private static final MetricRegistry metricRegistry = meter.metricRegistryBuilder().build();
|
||||
*
|
||||
* List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("Name", "desc"));
|
||||
*
|
||||
* GaugeDouble gauge = metricRegistry.addDoubleGauge("queue_size",
|
||||
* "Pending jobs", "1", labelKeys);
|
||||
*
|
||||
* private static final GaugeDouble gauge =
|
||||
* meter
|
||||
* .gaugeDoubleBuilder("processed_jobs")
|
||||
* .setDescription("Processed jobs")
|
||||
* .setUnit("1")
|
||||
* .setLabelKeys(Collections.singletonList(LabelKey.create("Name", "desc")))
|
||||
* .build();
|
||||
* // It is recommended to keep a reference of a TimeSeries.
|
||||
* GaugeDouble.TimeSeries defaultTimeSeries = gauge.getDefaultTimeSeries();
|
||||
* private static final GaugeDouble.TimeSeries inboundTimeSeries =
|
||||
* gauge.getOrCreateTimeSeries(Collections.singletonList(LabelValue.create("SomeWork")));
|
||||
* private static final GaugeDouble.TimeSeries defaultTimeSeries = gauge.getDefaultTimeSeries();
|
||||
*
|
||||
* void doWork() {
|
||||
* void doDefault() {
|
||||
* // Your code here.
|
||||
* defaultPoint.add(10);
|
||||
* defaultTimeSeries.add(10);
|
||||
* }
|
||||
*
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* <p>Example 2: You can also use labels(keys and values) to track different types of metric.
|
||||
*
|
||||
* <pre>{@code
|
||||
* class YourClass {
|
||||
*
|
||||
* private static final Meter meter = Metrics.getMeter();
|
||||
* private static final MetricRegistry metricRegistry = meter.metricRegistryBuilder().build();
|
||||
*
|
||||
* List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("Name", "desc"));
|
||||
* List<LabelValue> labelValues = Arrays.asList(LabelValue.create("Inbound"));
|
||||
*
|
||||
* GaugeDouble gauge = metricRegistry.addDoubleGauge("queue_size",
|
||||
* "Pending jobs", "1", labelKeys);
|
||||
*
|
||||
* // It is recommended to keep a reference of a TimeSeries.
|
||||
* GaugeDouble.TimeSeries inboundTimeSeries = gauge.getOrCreateTimeSeries(labelValues);
|
||||
*
|
||||
* void doSomeWork() {
|
||||
* // Your code here.
|
||||
* inboundPoint.set(15);
|
||||
* inboundTimeSeries.set(15);
|
||||
* }
|
||||
*
|
||||
* }
|
||||
|
|
|
|||
|
|
@ -23,48 +23,32 @@ import javax.annotation.concurrent.ThreadSafe;
|
|||
* Gauge metric, to report instantaneous measurement of an long value. Gauges can go both up and
|
||||
* down. The gauges values can be negative.
|
||||
*
|
||||
* <p>Example 1: Create a Gauge with default labels.
|
||||
* <p>Example:
|
||||
*
|
||||
* <pre>{@code
|
||||
* class YourClass {
|
||||
*
|
||||
* private static final Meter meter = Metrics.getMeter();
|
||||
* private static final MetricRegistry metricRegistry = meter.metricRegistryBuilder().build();
|
||||
*
|
||||
* List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("Name", "desc"));
|
||||
*
|
||||
* GaugeLong gauge = metricRegistry.addLongGauge("queue_size", "Pending jobs", "1", labelKeys);
|
||||
*
|
||||
* private static final GaugeLong gauge =
|
||||
* meter
|
||||
* .gaugeLongBuilder("processed_jobs")
|
||||
* .setDescription("Processed jobs")
|
||||
* .setUnit("1")
|
||||
* .setLabelKeys(Collections.singletonList(LabelKey.create("Name", "desc")))
|
||||
* .build();
|
||||
* // It is recommended to keep a reference of a TimeSeries.
|
||||
* GaugeLong.TimeSeries defaultTimeSeries = gauge.getDefaultTimeSeries();
|
||||
* private static final GaugeLong.TimeSeries inboundTimeSeries =
|
||||
* gauge.getOrCreateTimeSeries(Collections.singletonList(LabelValue.create("SomeWork")));
|
||||
* private static final GaugeLong.TimeSeries defaultTimeSeries = gauge.getDefaultTimeSeries();
|
||||
*
|
||||
* void doWork() {
|
||||
* void doDefault() {
|
||||
* // Your code here.
|
||||
* defaultPoint.add(10);
|
||||
* defaultTimeSeries.add(10);
|
||||
* }
|
||||
*
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* <p>Example 2: You can also use labels(keys and values) to track different types of metric.
|
||||
*
|
||||
* <pre>{@code
|
||||
* class YourClass {
|
||||
*
|
||||
* private static final Meter meter = Metrics.getMeter();
|
||||
* private static final MetricRegistry metricRegistry = meter.metricRegistryBuilder().build();
|
||||
*
|
||||
* List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("Name", "desc"));
|
||||
* List<LabelValue> labelValues = Arrays.asList(LabelValue.create("Inbound"));
|
||||
*
|
||||
* GaugeLong gauge = metricRegistry.addLongGauge("queue_size", "Pending jobs", "1", labelKeys);
|
||||
*
|
||||
* // It is recommended to keep a reference of a TimeSeries.
|
||||
* GaugeLong.TimeSeries inboundTimeSeries = gauge.getOrCreateTimeSeries(labelValues);
|
||||
*
|
||||
* void doSomeWork() {
|
||||
* // Your code here.
|
||||
* inboundPoint.set(15);
|
||||
* inboundTimeSeries.set(15);
|
||||
* }
|
||||
*
|
||||
* }
|
||||
|
|
|
|||
|
|
@ -16,13 +16,50 @@
|
|||
|
||||
package io.opentelemetry.metrics;
|
||||
|
||||
/** Entry point fot metrics API, this object allows to create new {@link MetricRegistry}. */
|
||||
/** Entry point fot metrics API, this object allows to record measurements and {@link Metric}s. */
|
||||
public interface Meter {
|
||||
|
||||
/**
|
||||
* Returns a new builder for a {@code MetricRegistry}.
|
||||
* Returns a builder for a {@link GaugeLong} to be added to the registry.
|
||||
*
|
||||
* @return a new builder for a {@code MetricRegistry}.
|
||||
* @param name the name of the metric.
|
||||
* @return a {@code GaugeLong.Builder}.
|
||||
* @throws NullPointerException if {@code name} is null.
|
||||
* @throws IllegalArgumentException if different metric with the same name already registered.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
MetricRegistry.Builder metricRegistryBuilder();
|
||||
GaugeLong.Builder gaugeLongBuilder(String name);
|
||||
|
||||
/**
|
||||
* Returns a builder for a {@link GaugeDouble} to be added to the registry.
|
||||
*
|
||||
* @param name the name of the metric.
|
||||
* @return a {@code GaugeDouble.Builder}.
|
||||
* @throws NullPointerException if {@code name} is null.
|
||||
* @throws IllegalArgumentException if different metric with the same name already registered.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
GaugeDouble.Builder gaugeDoubleBuilder(String name);
|
||||
|
||||
/**
|
||||
* Returns a builder for a {@link CounterDouble} to be added to the registry.
|
||||
*
|
||||
* @param name the name of the metric.
|
||||
* @return a {@code CounterDouble.Builder}.
|
||||
* @throws NullPointerException if {@code name} is null.
|
||||
* @throws IllegalArgumentException if different metric with the same name already registered.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
CounterDouble.Builder counterDoubleBuilder(String name);
|
||||
|
||||
/**
|
||||
* Returns a builder for a {@link CounterLong} to be added to the registry.
|
||||
*
|
||||
* @param name the name of the metric.
|
||||
* @return a {@code CounterLong.Builder}.
|
||||
* @throws NullPointerException if {@code name} is null.
|
||||
* @throws IllegalArgumentException if different metric with the same name already registered.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
CounterLong.Builder counterLongBuilder(String name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.opentelemetry.metrics;
|
||||
|
||||
import io.opentelemetry.resource.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -79,7 +80,7 @@ public interface Metric<T> {
|
|||
|
||||
interface Builder<B extends Builder<B, V>, V> {
|
||||
/**
|
||||
* Sets the description of the Metric.
|
||||
* Sets the description of the {@code Metric}.
|
||||
*
|
||||
* <p>Default value is {@code ""}.
|
||||
*
|
||||
|
|
@ -89,7 +90,7 @@ public interface Metric<T> {
|
|||
B setDescription(String description);
|
||||
|
||||
/**
|
||||
* Sets the unit of the Metric.
|
||||
* Sets the unit of the {@code Metric}.
|
||||
*
|
||||
* <p>Default value is {@code "1"}.
|
||||
*
|
||||
|
|
@ -118,6 +119,32 @@ public interface Metric<T> {
|
|||
*/
|
||||
B setConstantLabels(Map<LabelKey, LabelValue> constantLabels);
|
||||
|
||||
/**
|
||||
* Sets the name of the component that reports this {@code Metric}.
|
||||
*
|
||||
* <p>The final name of the reported metric will be <code>component + "_" + name</code> if the
|
||||
* component is not empty.
|
||||
*
|
||||
* <p>It is recommended to always set a component name for all the metrics, because some
|
||||
* implementations may filter based on the component.
|
||||
*
|
||||
* @param component the name of the component that reports these metrics.
|
||||
* @return this.
|
||||
*/
|
||||
B setComponent(String component);
|
||||
|
||||
/**
|
||||
* Sets the {@code Resource} associated with this {@code Metric}.
|
||||
*
|
||||
* <p>This should be set only when reporting out-of-band metrics, otherwise the implementation
|
||||
* will set the {@code Resource} for in-process metrics (or user can do that when initialize the
|
||||
* {@code Meter}).
|
||||
*
|
||||
* @param resource the {@code Resource} associated with this {@code Metric}.
|
||||
* @return this.
|
||||
*/
|
||||
B setResource(Resource resource);
|
||||
|
||||
/**
|
||||
* Builds and returns a metric with the desired options.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,104 +0,0 @@
|
|||
/*
|
||||
* Copyright 2019, OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.metrics;
|
||||
|
||||
import io.opentelemetry.resource.Resource;
|
||||
|
||||
/**
|
||||
* Creates and manages a set of metrics for a library/application.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public interface MetricRegistry {
|
||||
|
||||
/**
|
||||
* Returns a builder for a {@link GaugeLong} to be added to the registry.
|
||||
*
|
||||
* @param name the name of the metric.
|
||||
* @return a {@code GaugeLong.Builder}.
|
||||
* @throws NullPointerException if {@code name} is null.
|
||||
* @throws IllegalArgumentException if different metric with the same name already registered.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
GaugeLong.Builder gaugeLongBuilder(String name);
|
||||
|
||||
/**
|
||||
* Returns a builder for a {@link GaugeDouble} to be added to the registry.
|
||||
*
|
||||
* @param name the name of the metric.
|
||||
* @return a {@code GaugeDouble.Builder}.
|
||||
* @throws NullPointerException if {@code name} is null.
|
||||
* @throws IllegalArgumentException if different metric with the same name already registered.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
GaugeDouble.Builder gaugeDoubleBuilder(String name);
|
||||
|
||||
/**
|
||||
* Returns a builder for a {@link CounterDouble} to be added to the registry.
|
||||
*
|
||||
* @param name the name of the metric.
|
||||
* @return a {@code CounterDouble.Builder}.
|
||||
* @throws NullPointerException if {@code name} is null.
|
||||
* @throws IllegalArgumentException if different metric with the same name already registered.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
CounterDouble.Builder counterDoubleBuilder(String name);
|
||||
|
||||
/**
|
||||
* Returns a builder for a {@link CounterLong} to be added to the registry.
|
||||
*
|
||||
* @param name the name of the metric.
|
||||
* @return a {@code CounterLong.Builder}.
|
||||
* @throws NullPointerException if {@code name} is null.
|
||||
* @throws IllegalArgumentException if different metric with the same name already registered.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
CounterLong.Builder counterLongBuilder(String name);
|
||||
|
||||
/** Builder class for the {@link MetricRegistry}. */
|
||||
interface Builder {
|
||||
|
||||
/**
|
||||
* Sets the name of the component that reports these metrics.
|
||||
*
|
||||
* <p>The final name of the reported metric will be <code>component + "_" + name</code> if the
|
||||
* component is not empty.
|
||||
*
|
||||
* @param component the name of the component that reports these metrics.
|
||||
* @return this.
|
||||
*/
|
||||
Builder setComponent(String component);
|
||||
|
||||
/**
|
||||
* Sets the {@code Resource} associated with the new {@code MetricRegistry}.
|
||||
*
|
||||
* <p>This should be set only when reporting out-of-band metrics, otherwise the implementation
|
||||
* will set the {@code Resource} for in-process metrics.
|
||||
*
|
||||
* @param resource the {@code Resource} associated with the new {@code MetricRegistry}.
|
||||
* @return this.
|
||||
*/
|
||||
Builder setResource(Resource resource);
|
||||
|
||||
/**
|
||||
* Builds and returns a {@link MetricRegistry} with the desired options.
|
||||
*
|
||||
* @return a {@link MetricRegistry} with the desired options.
|
||||
*/
|
||||
MetricRegistry build();
|
||||
}
|
||||
}
|
||||
|
|
@ -40,14 +40,6 @@ public final class NoopMetrics {
|
|||
}
|
||||
|
||||
private static final class NoopMeter implements Meter {
|
||||
|
||||
@Override
|
||||
public MetricRegistry.Builder metricRegistryBuilder() {
|
||||
return new NoopMetricCollection.Builder();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class NoopMetricCollection implements MetricRegistry {
|
||||
@Override
|
||||
public GaugeLong.Builder gaugeLongBuilder(String name) {
|
||||
Utils.checkNotNull(name, "name");
|
||||
|
|
@ -71,27 +63,6 @@ public final class NoopMetrics {
|
|||
Utils.checkNotNull(name, "name");
|
||||
return new NoopCounterLong.NoopBuilder();
|
||||
}
|
||||
|
||||
private static final class Builder implements MetricRegistry.Builder {
|
||||
private static final MetricRegistry METRIC_COLLECTION = new NoopMetricCollection();
|
||||
|
||||
@Override
|
||||
public MetricRegistry.Builder setComponent(String component) {
|
||||
Utils.checkNotNull(component, "component");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricRegistry.Builder setResource(Resource resource) {
|
||||
Utils.checkNotNull(resource, "resource");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricRegistry build() {
|
||||
return METRIC_COLLECTION;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** No-op implementations of GaugeLong class. */
|
||||
|
|
@ -169,6 +140,18 @@ public final class NoopMetrics {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setComponent(String component) {
|
||||
Utils.checkNotNull(component, "component");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setResource(Resource resource) {
|
||||
Utils.checkNotNull(resource, "resource");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GaugeLong build() {
|
||||
return new NoopGaugeLong(labelKeysSize);
|
||||
|
|
@ -251,6 +234,18 @@ public final class NoopMetrics {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setComponent(String component) {
|
||||
Utils.checkNotNull(component, "component");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setResource(Resource resource) {
|
||||
Utils.checkNotNull(resource, "resource");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GaugeDouble build() {
|
||||
return new NoopGaugeDouble(labelKeysSize);
|
||||
|
|
@ -335,6 +330,18 @@ public final class NoopMetrics {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setComponent(String component) {
|
||||
Utils.checkNotNull(component, "component");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setResource(Resource resource) {
|
||||
Utils.checkNotNull(resource, "resource");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CounterDouble build() {
|
||||
return new NoopCounterDouble(labelKeysSize);
|
||||
|
|
@ -419,6 +426,18 @@ public final class NoopMetrics {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setComponent(String component) {
|
||||
Utils.checkNotNull(component, "component");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setResource(Resource resource) {
|
||||
Utils.checkNotNull(resource, "resource");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CounterLong build() {
|
||||
return new NoopCounterLong(labelKeysSize);
|
||||
|
|
|
|||
|
|
@ -37,13 +37,12 @@ public class CounterDoubleTest {
|
|||
Collections.singletonList(LabelKey.create("key", "key description"));
|
||||
private static final List<LabelValue> EMPTY_LABEL_VALUES = new ArrayList<>();
|
||||
|
||||
private final MetricRegistry metricRegistry =
|
||||
NoopMetrics.newNoopMeter().metricRegistryBuilder().build();
|
||||
private final Meter meter = Metrics.getMeter();
|
||||
|
||||
@Test
|
||||
public void noopGetOrCreateTimeSeries_WithNullLabelValues() {
|
||||
CounterDouble counterDouble =
|
||||
metricRegistry
|
||||
meter
|
||||
.counterDoubleBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
@ -58,7 +57,7 @@ public class CounterDoubleTest {
|
|||
public void noopGetOrCreateTimeSeries_WithNullElement() {
|
||||
List<LabelValue> labelValues = Collections.singletonList(null);
|
||||
CounterDouble counterDouble =
|
||||
metricRegistry
|
||||
meter
|
||||
.counterDoubleBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
@ -72,7 +71,7 @@ public class CounterDoubleTest {
|
|||
@Test
|
||||
public void noopGetOrCreateTimeSeries_WithInvalidLabelSize() {
|
||||
CounterDouble counterDouble =
|
||||
metricRegistry
|
||||
meter
|
||||
.counterDoubleBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
@ -86,7 +85,7 @@ public class CounterDoubleTest {
|
|||
@Test
|
||||
public void noopRemoveTimeSeries_WithNullLabelValues() {
|
||||
CounterDouble counterDouble =
|
||||
metricRegistry
|
||||
meter
|
||||
.counterDoubleBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
|
|||
|
|
@ -37,13 +37,12 @@ public class CounterLongTest {
|
|||
Collections.singletonList(LabelKey.create("key", "key description"));
|
||||
private static final List<LabelValue> EMPTY_LABEL_VALUES = new ArrayList<>();
|
||||
|
||||
private final MetricRegistry metricRegistry =
|
||||
NoopMetrics.newNoopMeter().metricRegistryBuilder().build();
|
||||
private final Meter meter = Metrics.getMeter();
|
||||
|
||||
@Test
|
||||
public void noopGetOrCreateTimeSeries_WithNullLabelValues() {
|
||||
CounterLong counterLong =
|
||||
metricRegistry
|
||||
meter
|
||||
.counterLongBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
@ -58,7 +57,7 @@ public class CounterLongTest {
|
|||
public void noopGetOrCreateTimeSeries_WithNullElement() {
|
||||
List<LabelValue> labelValues = Collections.singletonList(null);
|
||||
CounterLong counterLong =
|
||||
metricRegistry
|
||||
meter
|
||||
.counterLongBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
@ -72,7 +71,7 @@ public class CounterLongTest {
|
|||
@Test
|
||||
public void noopGetOrCreateTimeSeries_WithInvalidLabelSize() {
|
||||
CounterLong counterLong =
|
||||
metricRegistry
|
||||
meter
|
||||
.counterLongBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
@ -86,7 +85,7 @@ public class CounterLongTest {
|
|||
@Test
|
||||
public void noopRemoveTimeSeries_WithNullLabelValues() {
|
||||
CounterLong counterLong =
|
||||
metricRegistry
|
||||
meter
|
||||
.counterLongBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
|
|||
|
|
@ -37,13 +37,12 @@ public class GaugeDoubleTest {
|
|||
Collections.singletonList(LabelKey.create("key", "key description"));
|
||||
private static final List<LabelValue> EMPTY_LABEL_VALUES = new ArrayList<>();
|
||||
|
||||
private final MetricRegistry metricRegistry =
|
||||
NoopMetrics.newNoopMeter().metricRegistryBuilder().build();
|
||||
private final Meter meter = Metrics.getMeter();
|
||||
|
||||
@Test
|
||||
public void noopGetOrCreateTimeSeries_WithNullLabelValues() {
|
||||
GaugeDouble gaugeDouble =
|
||||
metricRegistry
|
||||
meter
|
||||
.gaugeDoubleBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
@ -58,7 +57,7 @@ public class GaugeDoubleTest {
|
|||
public void noopGetOrCreateTimeSeries_WithNullElement() {
|
||||
List<LabelValue> labelValues = Collections.singletonList(null);
|
||||
GaugeDouble gaugeDouble =
|
||||
metricRegistry
|
||||
meter
|
||||
.gaugeDoubleBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
@ -72,7 +71,7 @@ public class GaugeDoubleTest {
|
|||
@Test
|
||||
public void noopGetOrCreateTimeSeries_WithInvalidLabelSize() {
|
||||
GaugeDouble gaugeDouble =
|
||||
metricRegistry
|
||||
meter
|
||||
.gaugeDoubleBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
@ -86,7 +85,7 @@ public class GaugeDoubleTest {
|
|||
@Test
|
||||
public void noopRemoveTimeSeries_WithNullLabelValues() {
|
||||
GaugeDouble gaugeDouble =
|
||||
metricRegistry
|
||||
meter
|
||||
.gaugeDoubleBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
|
|||
|
|
@ -37,13 +37,12 @@ public class GaugeLongTest {
|
|||
Collections.singletonList(LabelKey.create("key", "key description"));
|
||||
private static final List<LabelValue> EMPTY_LABEL_VALUES = new ArrayList<>();
|
||||
|
||||
private final MetricRegistry metricRegistry =
|
||||
NoopMetrics.newNoopMeter().metricRegistryBuilder().build();
|
||||
private final Meter meter = Metrics.getMeter();
|
||||
|
||||
@Test
|
||||
public void noopGetOrCreateTimeSeries_WithNullLabelValues() {
|
||||
GaugeLong gaugeLong =
|
||||
metricRegistry
|
||||
meter
|
||||
.gaugeLongBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
@ -58,7 +57,7 @@ public class GaugeLongTest {
|
|||
public void noopGetOrCreateTimeSeries_WithNullElement() {
|
||||
List<LabelValue> labelValues = Collections.singletonList(null);
|
||||
GaugeLong gaugeLong =
|
||||
metricRegistry
|
||||
meter
|
||||
.gaugeLongBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
@ -72,7 +71,7 @@ public class GaugeLongTest {
|
|||
@Test
|
||||
public void noopGetOrCreateTimeSeries_WithInvalidLabelSize() {
|
||||
GaugeLong gaugeLong =
|
||||
metricRegistry
|
||||
meter
|
||||
.gaugeLongBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
@ -86,7 +85,7 @@ public class GaugeLongTest {
|
|||
@Test
|
||||
public void noopRemoveTimeSeries_WithNullLabelValues() {
|
||||
GaugeLong gaugeLong =
|
||||
metricRegistry
|
||||
meter
|
||||
.gaugeLongBuilder(NAME)
|
||||
.setDescription(DESCRIPTION)
|
||||
.setLabelKeys(LABEL_KEY)
|
||||
|
|
|
|||
|
|
@ -22,39 +22,37 @@ import org.junit.rules.ExpectedException;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests for {@link MetricRegistry}. */
|
||||
/** Unit tests for {@link Meter}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class MetricRegistryTest {
|
||||
public class MeterTest {
|
||||
@Rule public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final MetricRegistry metricRegistry =
|
||||
NoopMetrics.newNoopMeter().metricRegistryBuilder().build();
|
||||
private final Meter meter = Metrics.getMeter();
|
||||
|
||||
@Test
|
||||
public void noopAddLongGauge_NullName() {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("name");
|
||||
metricRegistry.gaugeLongBuilder(null);
|
||||
meter.gaugeLongBuilder(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noopAddDoubleGauge_NullName() {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("name");
|
||||
metricRegistry.gaugeDoubleBuilder(null);
|
||||
meter.gaugeDoubleBuilder(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noopAddDoubleCumulative_NullName() {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("name");
|
||||
metricRegistry.counterDoubleBuilder(null);
|
||||
meter.counterDoubleBuilder(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noopAddLongCumulative_NullName() {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("name");
|
||||
metricRegistry.counterLongBuilder(null);
|
||||
meter.counterLongBuilder(null);
|
||||
}
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ package io.opentelemetry.contrib.metrics.runtime;
|
|||
import io.opentelemetry.metrics.CounterLong;
|
||||
import io.opentelemetry.metrics.LabelKey;
|
||||
import io.opentelemetry.metrics.LabelValue;
|
||||
import io.opentelemetry.metrics.MetricRegistry;
|
||||
import io.opentelemetry.metrics.Meter;
|
||||
import io.opentelemetry.metrics.Metrics;
|
||||
import java.lang.management.GarbageCollectorMXBean;
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
|
@ -45,12 +45,12 @@ public final class GarbageCollector {
|
|||
private static final LabelKey GC = LabelKey.create("gc", "");
|
||||
|
||||
private final List<GarbageCollectorMXBean> garbageCollectors;
|
||||
private final MetricRegistry metricRegistry;
|
||||
private final Meter meter;
|
||||
|
||||
/** Constructs a new module that is capable to export metrics about "jvm_gc". */
|
||||
public GarbageCollector() {
|
||||
this.garbageCollectors = ManagementFactory.getGarbageCollectorMXBeans();
|
||||
this.metricRegistry = Metrics.getMeter().metricRegistryBuilder().setComponent("jvm_gc").build();
|
||||
this.meter = Metrics.getMeter();
|
||||
}
|
||||
|
||||
/** Export all metrics generated by this module. */
|
||||
|
|
@ -58,11 +58,12 @@ public final class GarbageCollector {
|
|||
// TODO: This should probably be a cumulative Histogram without buckets (or Summary without
|
||||
// percentiles) to allow count/sum.
|
||||
final CounterLong collectionMetric =
|
||||
metricRegistry
|
||||
meter
|
||||
.counterLongBuilder("collection")
|
||||
.setDescription("Time spent in a given JVM garbage collector in milliseconds.")
|
||||
.setUnit("ms")
|
||||
.setLabelKeys(Collections.singletonList(GC))
|
||||
.setComponent("jvm_gc")
|
||||
.build();
|
||||
collectionMetric.setCallback(
|
||||
new Runnable() {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ package io.opentelemetry.contrib.metrics.runtime;
|
|||
import io.opentelemetry.metrics.GaugeLong;
|
||||
import io.opentelemetry.metrics.LabelKey;
|
||||
import io.opentelemetry.metrics.LabelValue;
|
||||
import io.opentelemetry.metrics.MetricRegistry;
|
||||
import io.opentelemetry.metrics.Meter;
|
||||
import io.opentelemetry.metrics.Metrics;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.MemoryMXBean;
|
||||
|
|
@ -57,14 +57,13 @@ public final class MemoryPools {
|
|||
|
||||
private final MemoryMXBean memoryBean;
|
||||
private final List<MemoryPoolMXBean> poolBeans;
|
||||
private final MetricRegistry metricRegistry;
|
||||
private final Meter meter;
|
||||
|
||||
/** Constructs a new module that is capable to export metrics about "jvm_memory". */
|
||||
public MemoryPools() {
|
||||
this.memoryBean = ManagementFactory.getMemoryMXBean();
|
||||
this.poolBeans = ManagementFactory.getMemoryPoolMXBeans();
|
||||
this.metricRegistry =
|
||||
Metrics.getMeter().metricRegistryBuilder().setComponent("jvm_memory").build();
|
||||
this.meter = Metrics.getMeter();
|
||||
}
|
||||
|
||||
/** Export only the "area" metric. */
|
||||
|
|
@ -74,11 +73,12 @@ public final class MemoryPools {
|
|||
// memory is committed (this can also be achieved by displaying the two metrics in the same
|
||||
// chart).
|
||||
final GaugeLong areaMetric =
|
||||
this.metricRegistry
|
||||
this.meter
|
||||
.gaugeLongBuilder("area")
|
||||
.setDescription("Bytes of a given JVM memory area.")
|
||||
.setUnit("By")
|
||||
.setLabelKeys(Arrays.asList(TYPE, AREA))
|
||||
.setComponent("jvm_memory")
|
||||
.build();
|
||||
final GaugeLong.TimeSeries usedHeap =
|
||||
areaMetric.getOrCreateTimeSeries(Arrays.asList(USED, HEAP));
|
||||
|
|
@ -111,11 +111,12 @@ public final class MemoryPools {
|
|||
/** Export only the "pool" metric. */
|
||||
public void exportMemoryPoolMetric() {
|
||||
final GaugeLong poolMetric =
|
||||
this.metricRegistry
|
||||
this.meter
|
||||
.gaugeLongBuilder("pool")
|
||||
.setDescription("Bytes of a given JVM memory pool.")
|
||||
.setUnit("By")
|
||||
.setLabelKeys(Arrays.asList(TYPE, POOL))
|
||||
.setComponent("jvm_memory")
|
||||
.build();
|
||||
poolMetric.setCallback(
|
||||
new Runnable() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue