Browse Source

Task/add monitor id check for uptime statistics gathering (#6873)

Add monitor id check
pull/6881/head
Thomas Kaul 1 week ago
committed by GitHub
parent
commit
3a95d8e7dc
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 21
      apps/api/src/services/queues/statistics-gathering/statistics-gathering.processor.ts

21
apps/api/src/services/queues/statistics-gathering/statistics-gathering.processor.ts

@ -93,12 +93,25 @@ export class StatisticsGatheringProcessor {
@Process(GATHER_STATISTICS_UPTIME_PROCESS_JOB_NAME) @Process(GATHER_STATISTICS_UPTIME_PROCESS_JOB_NAME)
public async gatherUptimeStatistics() { public async gatherUptimeStatistics() {
const monitorId = await this.propertyService.getByKey<string>(
PROPERTY_BETTER_UPTIME_MONITOR_ID
);
if (!monitorId) {
Logger.log(
`Uptime statistics gathering has been skipped as no ${PROPERTY_BETTER_UPTIME_MONITOR_ID} is configured`,
'StatisticsGatheringProcessor'
);
return;
}
Logger.log( Logger.log(
'Uptime statistics gathering has been started', 'Uptime statistics gathering has been started',
'StatisticsGatheringProcessor' 'StatisticsGatheringProcessor'
); );
const uptime = await this.getUptime(); const uptime = await this.getUptime(monitorId);
await this.propertyService.put({ await this.propertyService.put({
key: PROPERTY_UPTIME, key: PROPERTY_UPTIME,
@ -179,12 +192,8 @@ export class StatisticsGatheringProcessor {
} }
} }
private async getUptime(): Promise<number> { private async getUptime(monitorId: string): Promise<number> {
try { try {
const monitorId = await this.propertyService.getByKey<string>(
PROPERTY_BETTER_UPTIME_MONITOR_ID
);
const { data } = await fetch( const { data } = await fetch(
`https://uptime.betterstack.com/api/v2/monitors/${monitorId}/sla?from=${format( `https://uptime.betterstack.com/api/v2/monitors/${monitorId}/sla?from=${format(
subDays(new Date(), 90), subDays(new Date(), 90),

Loading…
Cancel
Save