Search in sources :

Example 1 with Observation

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

the class RocksDbStatsTest method shouldNotCrashIfMetricsRequestedAfterClose.

@Test
void shouldNotCrashIfMetricsRequestedAfterClose() throws Exception {
    final ObservableMetricsSystem metricsSystem = new PrometheusMetricsSystem(Set.of(TekuMetricCategory.STORAGE_HOT_DB), true);
    try (RocksDbStats stats = new RocksDbStats(metricsSystem, TekuMetricCategory.STORAGE_HOT_DB)) {
        stats.registerMetrics(database);
    }
    when(database.getLongProperty(any())).thenThrow(new IllegalStateException("Database shutdown"));
    final List<Observation> metrics = metricsSystem.streamObservations().collect(Collectors.toList());
    assertThat(metrics).isNotEmpty();
}
Also used : PrometheusMetricsSystem(org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem) ObservableMetricsSystem(org.hyperledger.besu.metrics.ObservableMetricsSystem) Observation(org.hyperledger.besu.metrics.Observation) Test(org.junit.jupiter.api.Test)

Example 2 with Observation

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

the class OpenTelemetryMetricsSystemTest method shouldCreateObservationFromCounter.

@Test
public void shouldCreateObservationFromCounter() {
    final Counter counter = metricsSystem.createCounter(PEERS, "connected", "Some help string");
    counter.inc();
    assertThat(metricsSystem.streamObservations()).containsExactly(new Observation(PEERS, "connected", 1L, emptyList()));
    counter.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 3 with Observation

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

the class OpenTelemetryMetricsSystemTest 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()) {
    }
    // noinspection EmptyTryBlock
    try (final OperationTimer.TimingContext ignored = timer.labels("method").startTimer()) {
    }
    // noinspection EmptyTryBlock
    try (final OperationTimer.TimingContext ignored = timer.labels("method").startTimer()) {
    }
    // 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, singletonList("method")));
}
Also used : OperationTimer(org.hyperledger.besu.plugin.services.metrics.OperationTimer) Observation(org.hyperledger.besu.metrics.Observation) Test(org.junit.Test)

Example 4 with Observation

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

the class OpenTelemetryMetricsSystemTest method shouldCreateObservationFromGauge.

@Test
public void shouldCreateObservationFromGauge() {
    final MetricsConfiguration metricsConfiguration = MetricsConfiguration.builder().metricCategories(ImmutableSet.of(BesuMetricCategory.RPC)).enabled(true).protocol(OPENTELEMETRY).build();
    final ObservableMetricsSystem localMetricSystem = MetricsSystemFactory.create(metricsConfiguration);
    localMetricSystem.createGauge(RPC, "myValue", "Help", () -> 7.0);
    assertThat(localMetricSystem.streamObservations()).containsExactlyInAnyOrder(new Observation(RPC, "myValue", 7.0, emptyList()));
}
Also used : MetricsConfiguration(org.hyperledger.besu.metrics.prometheus.MetricsConfiguration) ObservableMetricsSystem(org.hyperledger.besu.metrics.ObservableMetricsSystem) Observation(org.hyperledger.besu.metrics.Observation) Test(org.junit.Test)

Example 5 with Observation

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

the class OpenTelemetryMetricsSystemTest 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, Collections.emptyList()));
}
Also used : OperationTimer(org.hyperledger.besu.plugin.services.metrics.OperationTimer) 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