mirror of https://github.com/hyperledger/besu
Repaired Metrics name collision between Privacy and RocksDB (#187)
It was identified that when both KV_ROCKSDB metrics and Privacy were enabled, that Besu failed to start due to a naming collision in Metrics Collators - this was ultimately due to Besu having 2 keyvalue stores - one for public state, and another for private state - and _both_ using the same metrics. To overcome this issue, the metrics used in the private kv store are prefixed with the word "private". Signed-off-by: Trent Mohay <trent.mohay@consensys.net>pull/182/head
parent
3c1768eef7
commit
3d867532de
@ -0,0 +1,135 @@ |
|||||||
|
/* |
||||||
|
* Copyright ConsenSys AG. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||||
|
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||||
|
* specific language governing permissions and limitations under the License. |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: Apache-2.0 |
||||||
|
*/ |
||||||
|
package org.hyperledger.besu.plugin.services.storage.rocksdb; |
||||||
|
|
||||||
|
import org.hyperledger.besu.metrics.BesuMetricCategory; |
||||||
|
import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem; |
||||||
|
import org.hyperledger.besu.metrics.rocksdb.RocksDBStats; |
||||||
|
import org.hyperledger.besu.plugin.services.MetricsSystem; |
||||||
|
import org.hyperledger.besu.plugin.services.metrics.Counter; |
||||||
|
import org.hyperledger.besu.plugin.services.metrics.MetricCategory; |
||||||
|
import org.hyperledger.besu.plugin.services.metrics.OperationTimer; |
||||||
|
import org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBConfiguration; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
import org.rocksdb.RocksDBException; |
||||||
|
import org.rocksdb.Statistics; |
||||||
|
import org.rocksdb.TransactionDB; |
||||||
|
|
||||||
|
public class RocksDBMetricsFactory { |
||||||
|
|
||||||
|
public static final RocksDBMetricsFactory PUBLIC_ROCKS_DB_METRICS = |
||||||
|
new RocksDBMetricsFactory( |
||||||
|
BesuMetricCategory.KVSTORE_ROCKSDB, BesuMetricCategory.KVSTORE_ROCKSDB_STATS); |
||||||
|
|
||||||
|
public static final RocksDBMetricsFactory PRIVATE_ROCKS_DB_METRICS = |
||||||
|
new RocksDBMetricsFactory( |
||||||
|
BesuMetricCategory.KVSTORE_PRIVATE_ROCKSDB, |
||||||
|
BesuMetricCategory.KVSTORE_PRIVATE_ROCKSDB_STATS); |
||||||
|
|
||||||
|
private static final Logger LOG = LogManager.getLogger(); |
||||||
|
|
||||||
|
private final MetricCategory rocksDbMetricCategory; |
||||||
|
private final MetricCategory statsDbMetricCategory; |
||||||
|
|
||||||
|
public RocksDBMetricsFactory( |
||||||
|
final MetricCategory rocksDbMetricCategory, final MetricCategory statsDbMetricCategory) { |
||||||
|
this.rocksDbMetricCategory = rocksDbMetricCategory; |
||||||
|
this.statsDbMetricCategory = statsDbMetricCategory; |
||||||
|
} |
||||||
|
|
||||||
|
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); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue