import { OnEvent } from '@nestjs/event-emitter' ; import { InjectMetric } from '@willsoto/nestjs-prometheus' ; import { Gauge } from 'prom-client' ; import { BestBlockPayload , EventPayload , IndexerEvent , ProcessBlockPayload , TargetBlockPayload , } from '../indexer/events' ; export class MetricEventListener { private skipDictionaryCount = 0 ; constructor ( @ InjectMetric ( 'subql_indexer_api_connected' ) private apiConnectedMetric , @ InjectMetric ( 'subql_indexer_injected_api_connected' ) private injectedApiConnectedMetric , @ InjectMetric ( 'subql_indexer_block_queue_size' ) private blockQueueSizeMetric , @ InjectMetric ( 'subql_indexer_blocknumber_queue_size' ) private blocknumberQueueSizeMetric , @ InjectMetric ( 'subql_indexer_processing_block_height' ) private processingBlockHeight , @ InjectMetric ( 'subql_indexer_processed_block_height' ) private processedBlockHeight , @ InjectMetric ( 'subql_indexer_target_block_height' ) private targetHeightMetric , @ InjectMetric ( 'subql_indexer_best_block_height' ) private bestHeightMetric , @ InjectMetric ( 'subql_indexer_using_dictionary' ) private usingDictionaryMetric , @ InjectMetric ( 'subql_indexer_skip_dictionary_count' ) private skipDictionaryCountMetric ) { } @ OnEvent ( IndexerEvent . ApiConnected ) handleApiConnected ( { value } ) { this . apiConnectedMetric . set ( value ) ; } @ OnEvent ( IndexerEvent . InjectedApiConnected ) handleInjectedApiConnected ( { value } ) { this . injectedApiConnectedMetric . set ( value ) ; } @ OnEvent ( IndexerEvent . BlockQueueSize ) handleBlockQueueSizeMetric ( { value } ) { this . blockQueueSizeMetric . set ( value ) ; } @ OnEvent ( IndexerEvent . BlocknumberQueueSize ) handleBlocknumberQueueSizeMetric ( { value } ) { this . blocknumberQueueSizeMetric . set ( value ) ; } @ OnEvent ( IndexerEvent . BlockProcessing ) handleProcessingBlock ( blockPayload ) { this . processingBlockHeight . set ( blockPayload . height ) ; } @ OnEvent ( IndexerEvent . BlockTarget ) handleTargetBlock ( blockPayload ) { this . targetHeightMetric . set ( blockPayload . height ) ; } @ OnEvent ( IndexerEvent . BlockBest ) handleBestBlock ( blockPayload ) { this . bestHeightMetric . set ( blockPayload . height ) ; } @ OnEvent ( IndexerEvent . UsingDictionary ) handleUsingDictionary ( { value } ) { this . usingDictionaryMetric . set ( value ) ; } @ OnEvent ( IndexerEvent . SkipDictionary ) handleSkipDictionary ( ) { this . skipDictionaryCount += 1 ; this . skipDictionaryCountMetric . set ( this . skipDictionaryCount ) ; } }