|
| 1 | +package io.iohk.ethereum.blockchain.sync |
| 2 | + |
| 3 | +import akka.util.ByteString |
| 4 | +import com.google.common.util.concurrent.AtomicDouble |
| 5 | +import io.iohk.ethereum.domain.Block |
| 6 | +import io.iohk.ethereum.metrics.MetricsContainer |
| 7 | + |
| 8 | +case object BlockMetrics extends MetricsContainer { |
| 9 | + |
| 10 | + private[this] final val BlockNumberGauge = |
| 11 | + metrics.registry.gauge("sync.block.number.gauge", new AtomicDouble(0d)) |
| 12 | + private[this] final val BlockGasLimitGauge = |
| 13 | + metrics.registry.gauge("sync.block.gasLimit.gauge", new AtomicDouble(0d)) |
| 14 | + private[this] final val BlockGasUsedGauge = |
| 15 | + metrics.registry.gauge("sync.block.gasUsed.gauge", new AtomicDouble(0d)) |
| 16 | + private[this] final val BlockDifficultyGauge = |
| 17 | + metrics.registry.gauge("sync.block.difficulty.gauge", new AtomicDouble(0d)) |
| 18 | + private[this] final val BlockTransactionsGauge = |
| 19 | + metrics.registry.gauge("sync.block.transactions.gauge", new AtomicDouble(0d)) |
| 20 | + private[this] final val BlockUnclesGauge = |
| 21 | + metrics.registry.gauge("sync.block.uncles.gauge", new AtomicDouble(0d)) |
| 22 | + private[this] final val TimeBetweenParentGauge = |
| 23 | + metrics.registry.gauge("sync.block.timeBetweenParent.seconds.gauge", new AtomicDouble(0d)) |
| 24 | + |
| 25 | + def measure(block: Block, getBlockByHashFn: ByteString => Option[Block]): Unit = { |
| 26 | + BlockNumberGauge.set(block.number.toDouble) |
| 27 | + BlockGasLimitGauge.set(block.header.gasLimit.toDouble) |
| 28 | + BlockGasUsedGauge.set(block.header.gasUsed.toDouble) |
| 29 | + BlockDifficultyGauge.set(block.header.difficulty.toDouble) |
| 30 | + BlockTransactionsGauge.set(block.body.numberOfTxs) |
| 31 | + BlockUnclesGauge.set(block.body.numberOfUncles) |
| 32 | + |
| 33 | + getBlockByHashFn(block.header.parentHash) match { |
| 34 | + case Some(parentBlock) => |
| 35 | + val timeBetweenBlocksInSeconds: Long = |
| 36 | + block.header.unixTimestamp - parentBlock.header.unixTimestamp |
| 37 | + TimeBetweenParentGauge.set(timeBetweenBlocksInSeconds) |
| 38 | + case None => () |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | +} |
0 commit comments