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()));
}
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")));
}
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")));
}
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()));
}
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")));
}
Aggregations