added metric
This commit is contained in:
@@ -15,8 +15,14 @@
|
||||
*/
|
||||
package io.emeraldpay.dshackle.upstream
|
||||
|
||||
import io.emeraldpay.dshackle.Global
|
||||
import io.emeraldpay.dshackle.data.BlockContainer
|
||||
import io.emeraldpay.dshackle.upstream.forkchoice.ForkChoice
|
||||
import io.micrometer.core.instrument.Counter
|
||||
import io.micrometer.core.instrument.Gauge
|
||||
import io.micrometer.core.instrument.Meter
|
||||
import io.micrometer.core.instrument.Metrics
|
||||
import io.micrometer.core.instrument.Tag
|
||||
import org.slf4j.LoggerFactory
|
||||
import reactor.core.Disposable
|
||||
import reactor.core.publisher.Flux
|
||||
@@ -28,6 +34,7 @@ import reactor.core.scheduler.Schedulers
|
||||
import reactor.kotlin.core.publisher.toMono
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
|
||||
abstract class AbstractHead @JvmOverloads constructor(
|
||||
@@ -48,19 +55,23 @@ abstract class AbstractHead @JvmOverloads constructor(
|
||||
private var lastHeadUpdated = 0L
|
||||
private val lock = ReentrantLock()
|
||||
|
||||
|
||||
init {
|
||||
val state = AtomicBoolean(false)
|
||||
Gauge.builder("stuck_head", state) {
|
||||
if (it.get()) 1.0 else 0.0
|
||||
}
|
||||
.tag("upstream", upstreamId)
|
||||
.tag("class", this.javaClass.simpleName)
|
||||
.register(Metrics.globalRegistry)
|
||||
|
||||
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(
|
||||
{
|
||||
val delay = System.currentTimeMillis() - lastHeadUpdated
|
||||
if (delay > awaitHeadTimeoutMs) {
|
||||
log.warn("No head updates $upstreamId for $delay ms @ ${this.javaClass} - restart")
|
||||
if (lock.tryLock()) {
|
||||
try {
|
||||
start()
|
||||
} finally {
|
||||
lock.unlock()
|
||||
}
|
||||
}
|
||||
val delayed = delay > awaitHeadTimeoutMs
|
||||
state.set(delayed)
|
||||
if (delayed) {
|
||||
log.warn("No head updates $upstreamId for $delay ms @ ${this.javaClass}")
|
||||
}
|
||||
}, 300, 30, TimeUnit.SECONDS
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user