Additional metrics

This commit is contained in:
2023-10-16 20:23:16 -06:00
parent 295b217539
commit 84b6b9f385
4 changed files with 39 additions and 4 deletions

View File

@@ -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<string>,
@InjectMetric('daily_count') public dailyCount: Gauge<string>,
@InjectMetric('rss_query_count') public queryCount: Gauge<string>,
) {}
@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',

View File

@@ -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 {}

View File

@@ -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<string>,
) {}
@Post('')
async scrapeOg(@Body() body: ScrapeOgDto): Promise<SuccessResult> {
return this.ogScraperService.getOg(body.url);
const end = this.generationTime.startTimer();
const response = await this.ogScraperService.getOg(body.url);
end();
return response;
}
}

View File

@@ -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 {}