Search in sources :

Example 11 with Observation

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

the class OpenTelemetryMetricsSystemTest method shouldCreateLabelledGauge.

@Test
public void shouldCreateLabelledGauge() {
    LabelledGauge labelledGauge = metricsSystem.createLabelledGauge(RPC, "gaugeName", "help", "a", "b");
    labelledGauge.labels(() -> 1.0, "a1", "b1");
    labelledGauge.labels(() -> 11.0, "a2", "b2");
    labelledGauge.labels(() -> 21.0, "a3", "b3");
    assertThat(metricsSystem.streamObservations()).containsExactlyInAnyOrder(new Observation(RPC, "gaugeName", 1.0, List.of("a1", "b1")), new Observation(RPC, "gaugeName", 11.0, List.of("a2", "b2")), new Observation(RPC, "gaugeName", 21.0, List.of("a3", "b3")));
}
Also used : Observation(org.hyperledger.besu.metrics.Observation) LabelledGauge(org.hyperledger.besu.plugin.services.metrics.LabelledGauge) Test(org.junit.Test)

Example 12 with Observation

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

the class OpenTelemetryMetricsSystemTest method shouldIncrementCounterBySpecifiedAmount.

@Test
public void shouldIncrementCounterBySpecifiedAmount() {
    final Counter counter = metricsSystem.createCounter(PEERS, "connected", "Some help string");
    counter.inc(5);
    assertThat(metricsSystem.streamObservations()).containsExactly(new Observation(PEERS, "connected", 5L, emptyList()));
    counter.inc(6);
    assertThat(metricsSystem.streamObservations()).containsExactly(new Observation(PEERS, "connected", 11L, emptyList()));
}
Also used : Counter(org.hyperledger.besu.plugin.services.metrics.Counter) Observation(org.hyperledger.besu.metrics.Observation) Test(org.junit.Test)

Example 13 with Observation

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

the class OpenTelemetryMetricsSystemTest method shouldOnlyObserveEnabledMetrics.

@Test
public void shouldOnlyObserveEnabledMetrics() {
    final MetricsConfiguration metricsConfiguration = MetricsConfiguration.builder().metricCategories(ImmutableSet.of(BesuMetricCategory.RPC)).enabled(true).protocol(OPENTELEMETRY).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", (long) 1, singletonList("op")));
}
Also used : Counter(org.hyperledger.besu.plugin.services.metrics.Counter) MetricsConfiguration(org.hyperledger.besu.metrics.prometheus.MetricsConfiguration) ObservableMetricsSystem(org.hyperledger.besu.metrics.ObservableMetricsSystem) Observation(org.hyperledger.besu.metrics.Observation) Test(org.junit.Test)

Example 14 with Observation

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

the class OpenTelemetryMetricsSystemTest method shouldHandleDuplicateCounterCreation.

@Test
public void shouldHandleDuplicateCounterCreation() {
    final LabelledMetric<Counter> counter1 = metricsSystem.createLabelledCounter(PEERS, "connected", "Some help string");
    final LabelledMetric<Counter> counter2 = metricsSystem.createLabelledCounter(PEERS, "connected", "Some help string");
    assertThat(counter1).isEqualTo(counter2);
    counter1.labels().inc();
    assertThat(metricsSystem.streamObservations()).containsExactly(new Observation(PEERS, "connected", 1L, emptyList()));
    counter2.labels().inc();
    assertThat(metricsSystem.streamObservations()).containsExactly(new Observation(PEERS, "connected", 2L, emptyList()));
}
Also used : Counter(org.hyperledger.besu.plugin.services.metrics.Counter) Observation(org.hyperledger.besu.metrics.Observation) Test(org.junit.Test)

Example 15 with Observation

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

the class PrometheusMetricsSystemTest method shouldCreateObservationFromGauge.

@Test
public void shouldCreateObservationFromGauge() {
    metricsSystem.createGauge(JVM, "myValue", "Help", () -> 7.0);
    assertThat(metricsSystem.streamObservations()).containsExactlyInAnyOrder(new Observation(JVM, "myValue", 7.0, emptyList()));
}
Also used : 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