diff --git a/substrate/substrate-dump/src/dumper.ts b/substrate/substrate-dump/src/dumper.ts index cbd5a7ea6..04eac4cf2 100644 --- a/substrate/substrate-dump/src/dumper.ts +++ b/substrate/substrate-dump/src/dumper.ts @@ -99,10 +99,11 @@ export class Dumper { : this.options.withTrace ? '' : undefined } - return this.src().getFinalizedBlocks([{ + const blocks = this.src().getFinalizedBlocks([{ range, request }]) + return blocks; } private async *process(from?: number, prevHash?: string): AsyncIterable { @@ -140,6 +141,9 @@ export class Dumper { ) } } + const metrics = this.rpc().getMetrics(); + this.prometheus().setSuccesfulRequestCount(metrics.requestsServed); + this.prometheus().setFailedRequestCount(metrics.connectionErrors); yield batch.blocks @@ -205,7 +209,7 @@ export class Dumper { const prometheus = this.prometheus(); if (this.options.metricsPort) { await prometheus.serve(); - this.log().info(`prometheus metrics are available on port {port}`) + this.log().info(`prometheus metrics are available on port ${this.options.metricsPort}`) } await archive.appendRawBlocks({ blocks: (nextBlock, prevHash) => this.saveMetadata(this.process(nextBlock, prevHash)), diff --git a/substrate/substrate-dump/src/prometheus.ts b/substrate/substrate-dump/src/prometheus.ts index c2a9c94ae..4316781c4 100644 --- a/substrate/substrate-dump/src/prometheus.ts +++ b/substrate/substrate-dump/src/prometheus.ts @@ -7,6 +7,7 @@ export class PrometheusServer { private port?: number | string private chainHeightGauge: Gauge; private lastWrittenBlockGauge: Gauge; + private rpcRequestsGauge: Gauge; constructor(port: number) { this.port = port; @@ -22,6 +23,13 @@ export class PrometheusServer { registers: [this.registry] }); + this.rpcRequestsGauge = new Gauge({ + name: 'sqd_rpc_requests_count', + help: 'Number of rpc requests of different kinds', + labelNames: ['kind'], + registers: [this.registry] + }); + collectDefaultMetrics({register: this.registry}) } @@ -33,6 +41,17 @@ export class PrometheusServer { this.lastWrittenBlockGauge.set(block); } + setSuccesfulRequestCount(requests: number) { + this.rpcRequestsGauge.set({ + 'kind': 'successful' + }, requests) + } + + setFailedRequestCount(requests: number) { + this.rpcRequestsGauge.set({ + 'kind': 'failed' + }, requests) + } serve(): Promise { return createPrometheusServer(this.registry, this.port)