Search in sources :

Example 1 with Counter

use of org.hyperledger.besu.plugin.services.metrics.Counter 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 2 with Counter

use of org.hyperledger.besu.plugin.services.metrics.Counter 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 3 with Counter

use of org.hyperledger.besu.plugin.services.metrics.Counter 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)

Example 4 with Counter

use of org.hyperledger.besu.plugin.services.metrics.Counter 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 5 with Counter

use of org.hyperledger.besu.plugin.services.metrics.Counter 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)

Aggregations

Counter (org.hyperledger.besu.plugin.services.metrics.Counter)12 Observation (org.hyperledger.besu.metrics.Observation)10 Test (org.junit.Test)10 ObservableMetricsSystem (org.hyperledger.besu.metrics.ObservableMetricsSystem)2 PrometheusMetricsSystem (org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem)2 OperationTimer (org.hyperledger.besu.plugin.services.metrics.OperationTimer)2 RocksDBException (org.rocksdb.RocksDBException)2 MetricsConfiguration (org.hyperledger.besu.metrics.prometheus.MetricsConfiguration)1