Skip to content

Commit

Permalink
Convert latest timestamp metric to delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Ktl-XV committed Jan 31, 2024
1 parent 19c574c commit fcf32b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/scripts/pull_and_save_block_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { chunk, logger } from '../utils';
import {
CURRENT_BLOCK,
LATEST_SCRAPED_BLOCK,
LATEST_SCRAPED_BLOCK_TIMESTAMP,
LATEST_SCRAPED_BLOCK_DELAY,
SAVED_RESULTS,
SCRIPT_RUN_DURATION,
} from '../utils/metrics';
Expand Down Expand Up @@ -454,11 +454,10 @@ export class BlockEventsScraper {
if (success) {
const endTime = new Date().getTime();
const scriptDurationSeconds = (endTime - startTime) / 1000;
const latestScrapedBlockDelay = Date.now() / 1000 - newBlocks[newBlocks.length - 1].timestamp;
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,
);
LATEST_SCRAPED_BLOCK_DELAY.labels({ chain: CHAIN_NAME }).set(latestScrapedBlockDelay);

logger.info(`Finished pulling events block by in ${scriptDurationSeconds}`);
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ 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',
export const LATEST_SCRAPED_BLOCK_DELAY = new Gauge({
name: 'event_scraper_latest_scraped_block_delay',
help: "The difference of the latest scraped block's timestamp and the current timestamp",
labelNames: ['chain'],
});

Expand Down

0 comments on commit fcf32b8

Please sign in to comment.