Search in sources :

Example 6 with Observation

use of org.hyperledger.besu.metrics.Observation in project besu by hyperledger.

the class PrometheusMetricsSystemTest method shouldCreateObservationsFromTimer.

@Test
public void shouldCreateObservationsFromTimer() {
    final OperationTimer timer = metricsSystem.createTimer(RPC, "request", "Some help");
    final OperationTimer.TimingContext context = timer.startTimer();
    context.stopTimer();
    assertThat(metricsSystem.streamObservations()).usingElementComparator(IGNORE_VALUES).containsExactlyInAnyOrder(new Observation(RPC, "request", null, asList("quantile", "0.2")), new Observation(RPC, "request", null, asList("quantile", "0.5")), new Observation(RPC, "request", null, asList("quantile", "0.8")), new Observation(RPC, "request", null, asList("quantile", "0.95")), new Observation(RPC, "request", null, asList("quantile", "0.99")), new Observation(RPC, "request", null, asList("quantile", "1.0")), new Observation(RPC, "request", null, singletonList("sum")), new Observation(RPC, "request", null, singletonList("count")));
}
Also used : OperationTimer(org.hyperledger.besu.plugin.services.metrics.OperationTimer) Observation(org.hyperledger.besu.metrics.Observation) Test(org.junit.Test)

Example 7 with Observation

use of org.hyperledger.besu.metrics.Observation in project besu by hyperledger.

the class PrometheusMetricsSystemTest method shouldOnlyObserveEnabledMetrics.

@Test
public void shouldOnlyObserveEnabledMetrics() {
    final MetricsConfiguration metricsConfiguration = MetricsConfiguration.builder().metricCategories(ImmutableSet.of(BesuMetricCategory.RPC)).enabled(true).build();
    final ObservableMetricsSystem localMetricSystem = MetricsSystemFactory.create(metricsConfiguration);
    // do a category we are not watching
    final LabelledMetric<Counter> counterN = localMetricSystem.createLabelledCounter(NETWORK, "ABC", "Not that kind of network", "show");
    assertThat(counterN).isSameAs(NoOpMetricsSystem.NO_OP_LABELLED_1_COUNTER);
    counterN.labels("show").inc();
    assertThat(localMetricSystem.streamObservations()).isEmpty();
    // do a category we are watching
    final LabelledMetric<Counter> counterR = localMetricSystem.createLabelledCounter(RPC, "name", "Not useful", "method");
    assertThat(counterR).isNotSameAs(NoOpMetricsSystem.NO_OP_LABELLED_1_COUNTER);
    counterR.labels("op").inc();
    assertThat(localMetricSystem.streamObservations()).containsExactly(new Observation(RPC, "name", 1.0, singletonList("op")));
}
Also used : Counter(org.hyperledger.besu.plugin.services.metrics.Counter) ObservableMetricsSystem(org.hyperledger.besu.metrics.ObservableMetricsSystem) Observation(org.hyperledger.besu.metrics.Observation) Test(org.junit.Test)

Example 8 with Observation

use of org.hyperledger.besu.metrics.Observation in project besu by hyperledger.

the class PrometheusMetricsSystemTest method shouldCreateObservationsFromTimerWithLabels.

@Test
public void shouldCreateObservationsFromTimerWithLabels() {
    final LabelledMetric<OperationTimer> timer = metricsSystem.createLabelledTimer(RPC, "request", "Some help", "methodName");
    // noinspection EmptyTryBlock
    try (final OperationTimer.TimingContext ignored = timer.labels("method").startTimer()) {
    }
    assertThat(metricsSystem.streamObservations()).usingElementComparator(// We don't know how long it will actually take.
    IGNORE_VALUES).containsExactlyInAnyOrder(new Observation(RPC, "request", null, asList("method", "quantile", "0.2")), new Observation(RPC, "request", null, asList("method", "quantile", "0.5")), new Observation(RPC, "request", null, asList("method", "quantile", "0.8")), new Observation(RPC, "request", null, asList("method", "quantile", "0.95")), new Observation(RPC, "request", null, asList("method", "quantile", "0.99")), new Observation(RPC, "request", null, asList("method", "quantile", "1.0")), new Observation(RPC, "request", null, asList("method", "sum")), new Observation(RPC, "request", null, asList("method", "count")));
}
Also used : OperationTimer(org.hyperledger.besu.plugin.services.metrics.OperationTimer) Observation(org.hyperledger.besu.metrics.Observation) Test(org.junit.Test)

Example 9 with Observation

use of org.hyperledger.besu.metrics.Observation in project besu by hyperledger.

the class OpenTelemetrySystem method convertToObservations.

private Stream<Observation> convertToObservations(final MetricData metricData) {
    List<Observation> observations = new ArrayList<>();
    MetricCategory category = categoryNameToMetricCategory(metricData.getInstrumentationLibraryInfo().getName());
    Collection<?> points;
    switch(metricData.getType()) {
        case DOUBLE_GAUGE:
            points = metricData.getDoubleGaugeData().getPoints();
            break;
        case DOUBLE_SUM:
            points = metricData.getDoubleSumData().getPoints();
            break;
        case SUMMARY:
            points = metricData.getDoubleSummaryData().getPoints();
            break;
        case LONG_SUM:
            points = metricData.getLongSumData().getPoints();
            break;
        case HISTOGRAM:
            points = metricData.getDoubleHistogramData().getPoints();
            break;
        case LONG_GAUGE:
            points = metricData.getLongGaugeData().getPoints();
            break;
        default:
            throw new UnsupportedOperationException("Unsupported type " + metricData.getType().name());
    }
    for (Object ptObj : points) {
        PointData point = (PointData) ptObj;
        List<String> labels = new ArrayList<>();
        point.getAttributes().forEach((k, v) -> labels.add(v.toString()));
        observations.add(new Observation(category, metricData.getName(), extractValue(metricData.getType(), point), labels));
    }
    return observations.stream();
}
Also used : LongPointData(io.opentelemetry.sdk.metrics.data.LongPointData) DoubleHistogramPointData(io.opentelemetry.sdk.metrics.data.DoubleHistogramPointData) DoublePointData(io.opentelemetry.sdk.metrics.data.DoublePointData) DoubleSummaryPointData(io.opentelemetry.sdk.metrics.data.DoubleSummaryPointData) PointData(io.opentelemetry.sdk.metrics.data.PointData) Observation(org.hyperledger.besu.metrics.Observation) ArrayList(java.util.ArrayList) BesuMetricCategory(org.hyperledger.besu.metrics.BesuMetricCategory) StandardMetricCategory(org.hyperledger.besu.metrics.StandardMetricCategory) MetricCategory(org.hyperledger.besu.plugin.services.metrics.MetricCategory)

Example 10 with Observation

use of org.hyperledger.besu.metrics.Observation in project besu by hyperledger.

the class OpenTelemetryMetricsSystemTest method shouldCreateSeparateObservationsForEachCounterLabelValue.

@Test
public void shouldCreateSeparateObservationsForEachCounterLabelValue() {
    final LabelledMetric<Counter> counter = metricsSystem.createLabelledCounter(PEERS, "connected", "Some help string", "labelName");
    counter.labels("value1").inc();
    counter.labels("value2").inc();
    counter.labels("value1").inc();
    assertThat(metricsSystem.streamObservations()).containsExactlyInAnyOrder(new Observation(PEERS, "connected", 2L, singletonList("value1")), new Observation(PEERS, "connected", 1L, singletonList("value2")));
}
Also used : Counter(org.hyperledger.besu.plugin.services.metrics.Counter) Observation(org.hyperledger.besu.metrics.Observation) Test(org.junit.Test)

Aggregations

Observation (org.hyperledger.besu.metrics.Observation)20 Test (org.junit.Test)18 Counter (org.hyperledger.besu.plugin.services.metrics.Counter)10 ObservableMetricsSystem (org.hyperledger.besu.metrics.ObservableMetricsSystem)4 OperationTimer (org.hyperledger.besu.plugin.services.metrics.OperationTimer)4 MetricsConfiguration (org.hyperledger.besu.metrics.prometheus.MetricsConfiguration)2 LabelledGauge (org.hyperledger.besu.plugin.services.metrics.LabelledGauge)2 DoubleHistogramPointData (io.opentelemetry.sdk.metrics.data.DoubleHistogramPointData)1 DoublePointData (io.opentelemetry.sdk.metrics.data.DoublePointData)1 DoubleSummaryPointData (io.opentelemetry.sdk.metrics.data.DoubleSummaryPointData)1 LongPointData (io.opentelemetry.sdk.metrics.data.LongPointData)1 PointData (io.opentelemetry.sdk.metrics.data.PointData)1 ArrayList (java.util.ArrayList)1 BesuMetricCategory (org.hyperledger.besu.metrics.BesuMetricCategory)1 StandardMetricCategory (org.hyperledger.besu.metrics.StandardMetricCategory)1 PrometheusMetricsSystem (org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem)1 MetricCategory (org.hyperledger.besu.plugin.services.metrics.MetricCategory)1 Test (org.junit.jupiter.api.Test)1