diff --git a/src/dinosaurwet/dinosaurwet.controller.ts b/src/dinosaurwet/dinosaurwet.controller.ts index 178cd08..b92d853 100644 --- a/src/dinosaurwet/dinosaurwet.controller.ts +++ b/src/dinosaurwet/dinosaurwet.controller.ts @@ -3,7 +3,7 @@ import { Response } from 'express'; import { identity, prop } from 'ramda'; import * as xml from 'xml'; import { InjectMetric } from '@willsoto/nestjs-prometheus'; -import { Gauge } from 'prom-client'; +import { Gauge, Histogram } from 'prom-client'; import { ApiTags } from '@nestjs/swagger'; const episodeFiles: [number, string][] = [ @@ -147,10 +147,12 @@ export class DinosaurwetController { constructor( @InjectMetric('weekly_count') public weeklyCount: Gauge, @InjectMetric('daily_count') public dailyCount: Gauge, + @InjectMetric('rss_query_count') public queryCount: Gauge, ) {} @Get('') getAllAtOnce(@Res() response: Response) { + this.queryCount.inc(); response.header('Content-Type', 'application/xml'); const feed = buildFeeds('Dinosaur Wet - All At Once', episodes); return response.send(feed); @@ -158,6 +160,7 @@ export class DinosaurwetController { @Get('daily') getDaily(@Res() response: Response) { + this.queryCount.inc(); response.header('Content-Type', 'application/xml'); const feed = buildFeeds( 'Dinosaur Wet - Daily', @@ -171,6 +174,7 @@ export class DinosaurwetController { @Get('weekly') getWeekly(@Res() response: Response) { + this.queryCount.inc(); response.header('Content-Type', 'application/xml'); const feed = buildFeeds( 'Dinosaur Wet - Weekly', diff --git a/src/dinosaurwet/dinosaurwet.module.ts b/src/dinosaurwet/dinosaurwet.module.ts index e2bacd0..e1d07aa 100644 --- a/src/dinosaurwet/dinosaurwet.module.ts +++ b/src/dinosaurwet/dinosaurwet.module.ts @@ -24,6 +24,10 @@ import { name: 'weekly_count', help: 'The current weekly Dinosaur Wet episode count', }), + makeGaugeProvider({ + name: 'rss_query_count', + help: 'Total RSS endpoint queries', + }), ], }) export class DinosaurwetModule {} diff --git a/src/ogscraper/ogscraper.controller.ts b/src/ogscraper/ogscraper.controller.ts index 0e26786..90eac21 100644 --- a/src/ogscraper/ogscraper.controller.ts +++ b/src/ogscraper/ogscraper.controller.ts @@ -3,6 +3,8 @@ import { ApiProperty, ApiTags } from '@nestjs/swagger'; const ogs = require('open-graph-scraper'); import { SuccessResult } from 'open-graph-scraper'; import { OgScraperService } from './ogscraper.service'; +import { InjectMetric } from '@willsoto/nestjs-prometheus'; +import { Histogram } from 'prom-client'; class ScrapeOgDto { @ApiProperty({ @@ -16,10 +18,17 @@ class ScrapeOgDto { @Controller('ogscraper') @ApiTags('open-graph-scraper') export class OgScraperController { - constructor(private readonly ogScraperService: OgScraperService) {} + constructor( + private readonly ogScraperService: OgScraperService, + @InjectMetric('generation_time') + public generationTime: Histogram, + ) {} @Post('') async scrapeOg(@Body() body: ScrapeOgDto): Promise { - return this.ogScraperService.getOg(body.url); + const end = this.generationTime.startTimer(); + const response = await this.ogScraperService.getOg(body.url); + end(); + return response; } } diff --git a/src/ogscraper/ogscraper.module.ts b/src/ogscraper/ogscraper.module.ts index 2dbb21f..226d65a 100644 --- a/src/ogscraper/ogscraper.module.ts +++ b/src/ogscraper/ogscraper.module.ts @@ -1,10 +1,28 @@ import { Module } from '@nestjs/common'; import { OgScraperController } from './ogscraper.controller'; import { OgScraperService } from './ogscraper.service'; +import { + PrometheusModule, + makeHistogramProvider, +} from '@willsoto/nestjs-prometheus'; @Module({ + imports: [ + PrometheusModule.register({ + customMetricPrefix: 'ogscraper', + defaultMetrics: { + enabled: false, + }, + }), + ], controllers: [OgScraperController], - providers: [OgScraperService], + providers: [ + OgScraperService, + makeHistogramProvider({ + name: 'generation_time', + help: 'Open Graph Scraping response times', + }), + ], exports: [OgScraperService], }) export class OgScraperModule {}