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