Search in sources :

Example 1 with PrometheusMetricsSystem

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

the class MetricsDataFactoryTest method shouldIncludeValidatorMetricsInPublish.

@ParameterizedTest(name = "Total_{0}_Active_{1}")
@MethodSource("getValidatorParams")
void shouldIncludeValidatorMetricsInPublish(final int validatorsTotal, final int validatorsActive, final boolean isValidatorActive, @TempDir final Path tempDir) {
    final MetricsDataFactory factory = new MetricsDataFactory(prometheusMetricsSystem, timeProvider, tempDir.toFile());
    MetricsPublisherSource source = StubMetricsPublisherSource.builder().validatorsActive(validatorsActive).validatorsTotal(validatorsTotal).build();
    final List<BaseMetricData> data = factory.getMetricData(source);
    assertThat(data.size()).isEqualTo(isValidatorActive ? 2 : 1);
    data.stream().filter(el -> el.getProcess().equals("validator")).forEach(element -> assertThat(element).isInstanceOf(ValidatorMetricData.class));
}
Also used : Test(org.junit.jupiter.api.Test) StubTimeProvider(tech.pegasys.teku.infrastructure.time.StubTimeProvider) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) StubMetricsPublisherSource(tech.pegasys.teku.test.data.publisher.StubMetricsPublisherSource) TempDir(org.junit.jupiter.api.io.TempDir) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Arguments(org.junit.jupiter.params.provider.Arguments) Path(java.nio.file.Path) Mockito.mock(org.mockito.Mockito.mock) PrometheusMetricsSystem(org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem) MethodSource(org.junit.jupiter.params.provider.MethodSource) StubMetricsPublisherSource(tech.pegasys.teku.test.data.publisher.StubMetricsPublisherSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with PrometheusMetricsSystem

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

the class MetricsDataFactoryTest method shouldIncludeBeaconMetricsInPublish.

@Test
void shouldIncludeBeaconMetricsInPublish(@TempDir final Path tempDir) {
    final MetricsDataFactory factory = new MetricsDataFactory(prometheusMetricsSystem, timeProvider, tempDir.toFile());
    MetricsPublisherSource source = StubMetricsPublisherSource.builder().isBeaconNodePresent(true).build();
    final List<BaseMetricData> data = factory.getMetricData(source);
    assertThat(data.size()).isEqualTo(2);
    data.stream().filter(el -> el.getProcess().equals("beaconnode")).forEach(element -> assertThat(element).isInstanceOf(BeaconNodeMetricData.class));
}
Also used : Test(org.junit.jupiter.api.Test) StubTimeProvider(tech.pegasys.teku.infrastructure.time.StubTimeProvider) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) StubMetricsPublisherSource(tech.pegasys.teku.test.data.publisher.StubMetricsPublisherSource) TempDir(org.junit.jupiter.api.io.TempDir) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Arguments(org.junit.jupiter.params.provider.Arguments) Path(java.nio.file.Path) Mockito.mock(org.mockito.Mockito.mock) PrometheusMetricsSystem(org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem) MethodSource(org.junit.jupiter.params.provider.MethodSource) StubMetricsPublisherSource(tech.pegasys.teku.test.data.publisher.StubMetricsPublisherSource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with PrometheusMetricsSystem

use of org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem 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 4 with PrometheusMetricsSystem

use of org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem in project besu by hyperledger.

the class MetricsSystemFactory method create.

/**
 * Creates and starts a new metric system to observe the behavior of the client
 *
 * @param metricsConfiguration the configuration of the metric system
 * @return a new metric system
 */
public static ObservableMetricsSystem create(final MetricsConfiguration metricsConfiguration) {
    LOG.trace("Creating a metric system with {}", metricsConfiguration.getProtocol());
    if (!metricsConfiguration.isEnabled() && !metricsConfiguration.isPushEnabled()) {
        return new NoOpMetricsSystem();
    }
    if (PROMETHEUS.equals(metricsConfiguration.getProtocol())) {
        final PrometheusMetricsSystem metricsSystem = new PrometheusMetricsSystem(metricsConfiguration.getMetricCategories(), metricsConfiguration.isTimersEnabled());
        metricsSystem.init();
        return metricsSystem;
    } else if (OPENTELEMETRY.equals(metricsConfiguration.getProtocol())) {
        final OpenTelemetrySystem metricsSystem = new OpenTelemetrySystem(metricsConfiguration.getMetricCategories(), metricsConfiguration.isTimersEnabled(), metricsConfiguration.getPrometheusJob());
        metricsSystem.initDefaults();
        return metricsSystem;
    } else {
        throw new IllegalArgumentException("Invalid metrics protocol " + metricsConfiguration.getProtocol());
    }
}
Also used : PrometheusMetricsSystem(org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem) OpenTelemetrySystem(org.hyperledger.besu.metrics.opentelemetry.OpenTelemetrySystem) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)

Example 5 with PrometheusMetricsSystem

use of org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem in project besu by hyperledger.

the class RocksDBMetricsFactory method create.

public RocksDBMetrics create(final MetricsSystem metricsSystem, final RocksDBConfiguration rocksDbConfiguration, final TransactionDB db, final Statistics stats) {
    final OperationTimer readLatency = metricsSystem.createLabelledTimer(rocksDbMetricCategory, "read_latency_seconds", "Latency for read from RocksDB.", "database").labels(rocksDbConfiguration.getLabel());
    final OperationTimer removeLatency = metricsSystem.createLabelledTimer(rocksDbMetricCategory, "remove_latency_seconds", "Latency of remove requests from RocksDB.", "database").labels(rocksDbConfiguration.getLabel());
    final OperationTimer writeLatency = metricsSystem.createLabelledTimer(rocksDbMetricCategory, "write_latency_seconds", "Latency for write to RocksDB.", "database").labels(rocksDbConfiguration.getLabel());
    final OperationTimer commitLatency = metricsSystem.createLabelledTimer(rocksDbMetricCategory, "commit_latency_seconds", "Latency for commits to RocksDB.", "database").labels(rocksDbConfiguration.getLabel());
    if (metricsSystem instanceof PrometheusMetricsSystem) {
        RocksDBStats.registerRocksDBMetrics(stats, (PrometheusMetricsSystem) metricsSystem, statsDbMetricCategory);
    }
    metricsSystem.createLongGauge(rocksDbMetricCategory, "rocks_db_table_readers_memory_bytes", "Estimated memory used for RocksDB index and filter blocks in bytes", () -> {
        try {
            return db.getLongProperty("rocksdb.estimate-table-readers-mem");
        } catch (final RocksDBException e) {
            LOG.debug("Failed to get RocksDB metric", e);
            return 0L;
        }
    });
    metricsSystem.createLongGauge(rocksDbMetricCategory, "rocks_db_files_size_bytes", "Estimated database size in bytes", () -> {
        try {
            return db.getLongProperty("rocksdb.live-sst-files-size");
        } catch (final RocksDBException e) {
            LOG.debug("Failed to get RocksDB metric", e);
            return 0L;
        }
    });
    final Counter rollbackCount = metricsSystem.createLabelledCounter(rocksDbMetricCategory, "rollback_count", "Number of RocksDB transactions rolled back.", "database").labels(rocksDbConfiguration.getLabel());
    return new RocksDBMetrics(readLatency, removeLatency, writeLatency, commitLatency, rollbackCount);
}
Also used : RocksDBException(org.rocksdb.RocksDBException) OperationTimer(org.hyperledger.besu.plugin.services.metrics.OperationTimer) PrometheusMetricsSystem(org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem) Counter(org.hyperledger.besu.plugin.services.metrics.Counter)

Aggregations

PrometheusMetricsSystem (org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem)7 Test (org.junit.jupiter.api.Test)3 Path (java.nio.file.Path)2 List (java.util.List)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Counter (org.hyperledger.besu.plugin.services.metrics.Counter)2 OperationTimer (org.hyperledger.besu.plugin.services.metrics.OperationTimer)2 TempDir (org.junit.jupiter.api.io.TempDir)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Arguments (org.junit.jupiter.params.provider.Arguments)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 Mockito.mock (org.mockito.Mockito.mock)2 RocksDBException (org.rocksdb.RocksDBException)2 StubTimeProvider (tech.pegasys.teku.infrastructure.time.StubTimeProvider)2 StubMetricsPublisherSource (tech.pegasys.teku.test.data.publisher.StubMetricsPublisherSource)2 ObservableMetricsSystem (org.hyperledger.besu.metrics.ObservableMetricsSystem)1 Observation (org.hyperledger.besu.metrics.Observation)1 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)1 OpenTelemetrySystem (org.hyperledger.besu.metrics.opentelemetry.OpenTelemetrySystem)1 HistogramType (org.rocksdb.HistogramType)1