Skip to content

Commit

Permalink
Add latest block timestamp metric
Browse files Browse the repository at this point in the history
  • Loading branch information
Ktl-XV committed Jan 31, 2024
1 parent 1922288 commit 19c574c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/scripts/pull_and_save_block_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import { Block, Transaction, TransactionReceipt } from '../entities';
import { eventScrperProps, EventScraperProps } from '../events';
import { parseBlock, parseTransaction, parseTransactionReceipt } from '../parsers/web3/parse_web3_objects';
import { chunk, logger } from '../utils';
import { LATEST_SCRAPED_BLOCK, CURRENT_BLOCK, SCRIPT_RUN_DURATION, SAVED_RESULTS } from '../utils/metrics';
import {
CURRENT_BLOCK,
LATEST_SCRAPED_BLOCK,
LATEST_SCRAPED_BLOCK_TIMESTAMP,
SAVED_RESULTS,
SCRIPT_RUN_DURATION,
} from '../utils/metrics';
import { contractTopicFilter } from './utils/block_utils';
import { getParseSaveTokensAsync } from './utils/web3_utils';
import { web3Factory } from '@0x/dev-utils';
Expand Down Expand Up @@ -450,6 +456,9 @@ export class BlockEventsScraper {
const scriptDurationSeconds = (endTime - startTime) / 1000;
SCRIPT_RUN_DURATION.set({ script: 'events-by-block' }, scriptDurationSeconds);
LATEST_SCRAPED_BLOCK.labels({ chain: CHAIN_NAME }).set(blockRangeEnd);
LATEST_SCRAPED_BLOCK_TIMESTAMP.labels({ chain: CHAIN_NAME }).set(
newBlocks[newBlocks.length - 1].timestamp,
);

logger.info(`Finished pulling events block by in ${scriptDurationSeconds}`);
}
Expand Down
6 changes: 6 additions & 0 deletions src/utils/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export const LATEST_SCRAPED_BLOCK = new Gauge({
labelNames: ['chain'],
});

export const LATEST_SCRAPED_BLOCK_TIMESTAMP = new Gauge({
name: 'event_scraper_latest_scraped_block_timestamp',
help: 'The timestamp of the latest scraped block',
labelNames: ['chain'],
});

export const SCRIPT_RUN_DURATION = new Gauge({
name: 'event_scraper_script_run_duration',
help: 'The time a script took to run',
Expand Down

0 comments on commit 19c574c

Please sign in to comment.