Merge pull request #3385 from bluewave-labs/feat/globalping-ping-type
feat: globalping ping type
This commit is contained in:
10 files changed
+97
-58
No files matched your search
@@ -32,7 +32,12 @@ import {
|
|||||||
import { SPACING, LAYOUT } from "@/Utils/Theme/constants";
|
import { SPACING, LAYOUT } from "@/Utils/Theme/constants";
|
||||||
import { useGet, usePost, usePatch, useDelete } from "@/Hooks/UseApi";
|
import { useGet, usePost, usePatch, useDelete } from "@/Hooks/UseApi";
|
||||||
import { useMonitorForm } from "@/Hooks/useMonitorForm";
|
import { useMonitorForm } from "@/Hooks/useMonitorForm";
|
||||||
import type { Monitor, MonitorType, GamesMap } from "@/Types/Monitor";
|
import {
|
||||||
|
type Monitor,
|
||||||
|
type MonitorType,
|
||||||
|
type GamesMap,
|
||||||
|
supportsGeoCheck,
|
||||||
|
} from "@/Types/Monitor";
|
||||||
import type { Notification } from "@/Types/Notification";
|
import type { Notification } from "@/Types/Notification";
|
||||||
import type { MonitorFormData } from "@/Validation/monitor";
|
import type { MonitorFormData } from "@/Validation/monitor";
|
||||||
|
|
||||||
@@ -885,7 +890,7 @@ const CreateMonitorPage = () => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{watchedType === "http" && (
|
{supportsGeoCheck(watchedType) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.createMonitor.form.geoChecks.title")}
|
title={t("pages.createMonitor.form.geoChecks.title")}
|
||||||
subtitle={t("pages.createMonitor.form.geoChecks.description")}
|
subtitle={t("pages.createMonitor.form.geoChecks.description")}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import { useState, useMemo } from "react";
|
|||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { useGet } from "@/Hooks/UseApi";
|
import { useGet } from "@/Hooks/UseApi";
|
||||||
import type { MonitorDetailsResponse } from "@/Types/Monitor";
|
import { type MonitorDetailsResponse, supportsGeoCheck } from "@/Types/Monitor";
|
||||||
import type { ChecksResponse } from "@/Types/Check";
|
import type { ChecksResponse } from "@/Types/Check";
|
||||||
import type {
|
import type {
|
||||||
GeoChecksResult,
|
GeoChecksResult,
|
||||||
@@ -122,7 +122,7 @@ const UptimeDetailsPage = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const geoChecksUrl = useMemo(() => {
|
const geoChecksUrl = useMemo(() => {
|
||||||
if (!monitorId || monitor?.type !== "http" || !monitor?.geoCheckEnabled) {
|
if (!monitorId || !supportsGeoCheck(monitor?.type) || !monitor?.geoCheckEnabled) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
@@ -141,7 +141,7 @@ const UptimeDetailsPage = () => {
|
|||||||
|
|
||||||
// Fetch paginated geo checks for the table
|
// Fetch paginated geo checks for the table
|
||||||
const geoChecksTableUrl = useMemo(() => {
|
const geoChecksTableUrl = useMemo(() => {
|
||||||
if (!monitorId || monitor?.type !== "http" || !monitor?.geoCheckEnabled) {
|
if (!monitorId || !supportsGeoCheck(monitor?.type) || !monitor?.geoCheckEnabled) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|||||||
@@ -16,6 +16,15 @@ export const MonitorTypes = [
|
|||||||
] as const;
|
] as const;
|
||||||
export type MonitorType = (typeof MonitorTypes)[number];
|
export type MonitorType = (typeof MonitorTypes)[number];
|
||||||
|
|
||||||
|
export const GeoCheckSupportedTypes: readonly MonitorType[] = ["http", "ping"] as const;
|
||||||
|
|
||||||
|
export const supportsGeoCheck = (type: MonitorType | undefined): boolean => {
|
||||||
|
if (!type) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return GeoCheckSupportedTypes.includes(type);
|
||||||
|
};
|
||||||
|
|
||||||
export const MonitorStatuses = [
|
export const MonitorStatuses = [
|
||||||
"up",
|
"up",
|
||||||
"down",
|
"down",
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
import { IGeoChecksRepository } from "./IGeoChecksRepository.js";
|
import { IGeoChecksRepository } from "./IGeoChecksRepository.js";
|
||||||
import type { GeoCheck, GeoCheckMetadata, GeoCheckResult, GroupedGeoCheck, GeoContinent, FlatGeoCheck } from "@/types/geoCheck.js";
|
import type { GeoCheck, GeoCheckMetadata, GeoCheckResult, GroupedGeoCheck, GeoContinent, FlatGeoCheck } from "@/types/geoCheck.js";
|
||||||
import type { GeoChecksQueryResult, FlatGeoChecksQueryResult } from "./IGeoChecksRepository.js";
|
import type { FlatGeoChecksQueryResult } from "./IGeoChecksRepository.js";
|
||||||
import { GeoCheckModel, type GeoCheckDocument } from "@/db/models/index.js";
|
import { GeoCheckModel, type GeoCheckDocument } from "@/db/models/index.js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { getDateForRange } from "@/utils/dataUtils.js";
|
import { getDateForRange } from "@/utils/dataUtils.js";
|
||||||
|
import { ILogger } from "@/utils/logger.js";
|
||||||
|
|
||||||
const SERVICE_NAME = "GeoChecksRepository";
|
const SERVICE_NAME = "GeoChecksRepository";
|
||||||
|
|
||||||
class MongoGeoChecksRepository implements IGeoChecksRepository {
|
class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
private logger: any;
|
private logger: ILogger;
|
||||||
constructor(logger: any) {
|
constructor(logger: ILogger) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export class GeoChecksService implements IGeoChecksService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Step 1: Create measurement request
|
// Step 1: Create measurement request
|
||||||
const measurementId = await this.globalPingService.createMeasurement(monitor.url, monitor.geoCheckLocations);
|
const measurementId = await this.globalPingService.createMeasurement(monitor.type, monitor.url, monitor.geoCheckLocations);
|
||||||
|
|
||||||
if (!measurementId) {
|
if (!measurementId) {
|
||||||
// GlobalPing API is down, skip this check
|
// GlobalPing API is down, skip this check
|
||||||
@@ -76,7 +76,6 @@ export class GeoChecksService implements IGeoChecksService {
|
|||||||
message: "Skipping geo check due to API unavailability",
|
message: "Skipping geo check due to API unavailability",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "buildGeoCheck",
|
method: "buildGeoCheck",
|
||||||
details: { monitorId: monitor.id },
|
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -90,7 +89,6 @@ export class GeoChecksService implements IGeoChecksService {
|
|||||||
message: "No successful geo check results",
|
message: "No successful geo check results",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "buildGeoCheck",
|
method: "buildGeoCheck",
|
||||||
details: { monitorId: monitor.id, measurementId },
|
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -102,17 +100,16 @@ export class GeoChecksService implements IGeoChecksService {
|
|||||||
message: `Geo check completed for monitor ${monitor.id}`,
|
message: `Geo check completed for monitor ${monitor.id}`,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "buildGeoCheck",
|
method: "buildGeoCheck",
|
||||||
details: { monitorId: monitor.id, resultsCount: results.length },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return geoCheck;
|
return geoCheck;
|
||||||
} catch (error: any) {
|
} catch (error: unknown) {
|
||||||
this.logger.error({
|
this.logger.error({
|
||||||
message: "Error executing geo check",
|
message: "Error executing geo check",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "buildGeoCheck",
|
method: "buildGeoCheck",
|
||||||
details: { monitorId: monitor.id, error: error.message },
|
details: { monitorId: monitor.id, error: error instanceof Error ? error.message : "Unknown error" },
|
||||||
stack: error.stack,
|
stack: error instanceof Error ? error.stack : undefined,
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -172,19 +169,9 @@ export class GeoChecksService implements IGeoChecksService {
|
|||||||
|
|
||||||
const { sortOrder, dateRange, page, rowsPerPage, continent } = query;
|
const { sortOrder, dateRange, page, rowsPerPage, continent } = query;
|
||||||
const continents = continent ? (Array.isArray(continent) ? continent : [continent]) : undefined;
|
const continents = continent ? (Array.isArray(continent) ? continent : [continent]) : undefined;
|
||||||
|
|
||||||
this.logger.debug({
|
|
||||||
message: "getGeoChecksByMonitor query params",
|
|
||||||
service: SERVICE_NAME,
|
|
||||||
method: "getGeoChecksByMonitor",
|
|
||||||
details: { continent, continents, query },
|
|
||||||
});
|
|
||||||
|
|
||||||
const parsedPage = page ? parseInt(page) : page;
|
const parsedPage = page ? parseInt(page) : page;
|
||||||
const parsedRowsPerPage = rowsPerPage ? parseInt(rowsPerPage) : rowsPerPage;
|
const parsedRowsPerPage = rowsPerPage ? parseInt(rowsPerPage) : rowsPerPage;
|
||||||
|
|
||||||
const result = await this.geoChecksRepository.findByMonitorId(monitorId, sortOrder, dateRange, parsedPage, parsedRowsPerPage, continents);
|
const result = await this.geoChecksRepository.findByMonitorId(monitorId, sortOrder, dateRange, parsedPage, parsedRowsPerPage, continents);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ import type {
|
|||||||
PageSpeedDetailsResult,
|
PageSpeedDetailsResult,
|
||||||
GamesMap,
|
GamesMap,
|
||||||
} from "@/types/monitor.js";
|
} from "@/types/monitor.js";
|
||||||
|
import { supportsGeoCheck } from "@/types/monitor.js";
|
||||||
import type { GeoContinent } from "@/types/geoCheck.js";
|
import type { GeoContinent } from "@/types/geoCheck.js";
|
||||||
import type {
|
import type {
|
||||||
IChecksRepository,
|
IChecksRepository,
|
||||||
@@ -340,7 +341,7 @@ export class MonitorService implements IMonitorService {
|
|||||||
throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 });
|
throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monitor.type !== "http" || !monitor.geoCheckEnabled) {
|
if (!supportsGeoCheck(monitor.type) || !monitor.geoCheckEnabled) {
|
||||||
return { groupedGeoChecks: [] };
|
return { groupedGeoChecks: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { IMonitorsRepository } from "@/repositories/index.js";
|
|||||||
import { ILogger } from "@/utils/logger.js";
|
import { ILogger } from "@/utils/logger.js";
|
||||||
import Scheduler from "super-simple-scheduler";
|
import Scheduler from "super-simple-scheduler";
|
||||||
import { ISuperSimpleQueueHelper } from "@/service/infrastructure/SuperSimpleQueue/SuperSimpleQueueHelper.js";
|
import { ISuperSimpleQueueHelper } from "@/service/infrastructure/SuperSimpleQueue/SuperSimpleQueueHelper.js";
|
||||||
|
import { supportsGeoCheck } from "@/types/monitor.js";
|
||||||
const SERVICE_NAME = "JobQueue";
|
const SERVICE_NAME = "JobQueue";
|
||||||
|
|
||||||
type QueueJobFailure = {
|
type QueueJobFailure = {
|
||||||
@@ -125,8 +126,13 @@ export class SuperSimpleQueue implements ISuperSimpleQueue {
|
|||||||
data: monitor,
|
data: monitor,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Return early if we don't need geo checks
|
||||||
|
if (!supportsGeoCheck(monitor.type)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Add geo check job if enabled for HTTP monitors
|
// Add geo check job if enabled for HTTP monitors
|
||||||
if (monitor.geoCheckEnabled && monitor.type === "http") {
|
if (monitor.geoCheckEnabled) {
|
||||||
this.scheduler.addJob({
|
this.scheduler.addJob({
|
||||||
id: `${monitorId}-geo`,
|
id: `${monitorId}-geo`,
|
||||||
template: "geo-check-job",
|
template: "geo-check-job",
|
||||||
@@ -175,7 +181,7 @@ export class SuperSimpleQueue implements ISuperSimpleQueue {
|
|||||||
|
|
||||||
// Handle geo check job lifecycle
|
// Handle geo check job lifecycle
|
||||||
const geoJobId = `${monitor.id}-geo`;
|
const geoJobId = `${monitor.id}-geo`;
|
||||||
if (monitor.geoCheckEnabled && monitor.type === "http") {
|
if (monitor.geoCheckEnabled && supportsGeoCheck(monitor.type)) {
|
||||||
// Check if geo job exists
|
// Check if geo job exists
|
||||||
const existingGeoJob = await this.scheduler.getJob(geoJobId);
|
const existingGeoJob = await this.scheduler.getJob(geoJobId);
|
||||||
if (existingGeoJob) {
|
if (existingGeoJob) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const SERVICE_NAME = "JobQueueHelper";
|
const SERVICE_NAME = "JobQueueHelper";
|
||||||
import type { Monitor } from "@/types/monitor.js";
|
import type { Monitor } from "@/types/monitor.js";
|
||||||
|
import { supportsGeoCheck } from "@/types/monitor.js";
|
||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
import { INetworkService, INotificationsService, IStatusService, IncidentService, type IGeoChecksService } from "@/service/index.js";
|
import { INetworkService, INotificationsService, IStatusService, IncidentService, type IGeoChecksService } from "@/service/index.js";
|
||||||
import type { StatusChangeResult } from "@/types/index.js";
|
import type { StatusChangeResult } from "@/types/index.js";
|
||||||
@@ -280,19 +281,18 @@ export class SuperSimpleQueueHelper implements ISuperSimpleQueueHelper {
|
|||||||
throw new AppError({ message: "No monitor id", service: SERVICE_NAME, method: "getGeoCheckJob" });
|
throw new AppError({ message: "No monitor id", service: SERVICE_NAME, method: "getGeoCheckJob" });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monitor.type !== "http") {
|
if (!monitor.geoCheckEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!supportsGeoCheck(monitor.type)) {
|
||||||
this.logger.debug({
|
this.logger.debug({
|
||||||
message: `Monitor ${monitorId} is not HTTP type, skipping geo check`,
|
message: `Monitor ${monitorId} type does not support geo checks, skipping`,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "getGeoCheckJob",
|
method: "getGeoCheckJob",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!monitor.geoCheckEnabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!monitor.geoCheckLocations || monitor.geoCheckLocations.length === 0) {
|
if (!monitor.geoCheckLocations || monitor.geoCheckLocations.length === 0) {
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
message: `No geo check locations configured for monitor ${monitorId}`,
|
message: `No geo check locations configured for monitor ${monitorId}`,
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import type { GeoContinent, GeoCheckResult, GeoCheckTimings, GeoCheckLocation } from "@/types/geoCheck.js";
|
import type { GeoContinent, GeoCheckResult, GeoCheckTimings, GeoCheckLocation } from "@/types/geoCheck.js";
|
||||||
|
import { supportsGeoCheck } from "@/types/monitor.js";
|
||||||
|
import { MonitorType } from "@/types/index.js";
|
||||||
import type { ILogger } from "@/utils/logger.js";
|
import type { ILogger } from "@/utils/logger.js";
|
||||||
import got from "got";
|
import got from "got";
|
||||||
|
|
||||||
@@ -8,7 +10,7 @@ const POLL_INTERVAL_MS = 2000;
|
|||||||
const MAX_POLL_TIMEOUT_MS = 30000;
|
const MAX_POLL_TIMEOUT_MS = 30000;
|
||||||
|
|
||||||
interface GlobalPingMeasurementRequest {
|
interface GlobalPingMeasurementRequest {
|
||||||
type: "http";
|
type: MonitorType;
|
||||||
target: string;
|
target: string;
|
||||||
locations: Array<{ continent: GeoContinent }>;
|
locations: Array<{ continent: GeoContinent }>;
|
||||||
limit: number;
|
limit: number;
|
||||||
@@ -44,13 +46,22 @@ interface GlobalPingProbeResult {
|
|||||||
firstByte: number;
|
firstByte: number;
|
||||||
download: number;
|
download: number;
|
||||||
};
|
};
|
||||||
|
stats?: {
|
||||||
|
min: number;
|
||||||
|
max: number;
|
||||||
|
avg: number;
|
||||||
|
total: number;
|
||||||
|
loss: number;
|
||||||
|
rcv: number;
|
||||||
|
drop: number;
|
||||||
|
};
|
||||||
rawOutput?: string;
|
rawOutput?: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IGlobalPingService {
|
export interface IGlobalPingService {
|
||||||
readonly serviceName: string;
|
readonly serviceName: string;
|
||||||
createMeasurement(url: string, locations: GeoContinent[]): Promise<string | null>;
|
createMeasurement(monitorType: MonitorType, url: string, locations: GeoContinent[]): Promise<string | null>;
|
||||||
pollForResults(measurementId: string, timeoutMs?: number): Promise<GeoCheckResult[]>;
|
pollForResults(measurementId: string, timeoutMs?: number): Promise<GeoCheckResult[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,13 +78,16 @@ export class GlobalPingService implements IGlobalPingService {
|
|||||||
return GlobalPingService.SERVICE_NAME;
|
return GlobalPingService.SERVICE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createMeasurement(url: string, locations: GeoContinent[]): Promise<string | null> {
|
async createMeasurement(monitorType: MonitorType, url: string, locations: GeoContinent[]): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
|
if (!supportsGeoCheck(monitorType)) {
|
||||||
|
throw new Error(`Unsupported monitor type for GlobalPing: ${monitorType}`);
|
||||||
|
}
|
||||||
// GlobalPing API expects target without protocol (http:// or https://)
|
// GlobalPing API expects target without protocol (http:// or https://)
|
||||||
const cleanTarget = url.replace(/^https?:\/\//, "");
|
const cleanTarget = url.replace(/^https?:\/\//, "");
|
||||||
|
|
||||||
const requestBody: GlobalPingMeasurementRequest = {
|
const requestBody: GlobalPingMeasurementRequest = {
|
||||||
type: "http",
|
type: monitorType,
|
||||||
target: cleanTarget,
|
target: cleanTarget,
|
||||||
locations: locations.map((continent) => ({ continent })),
|
locations: locations.map((continent) => ({ continent })),
|
||||||
limit: locations.length,
|
limit: locations.length,
|
||||||
@@ -88,10 +102,9 @@ export class GlobalPingService implements IGlobalPingService {
|
|||||||
const measurementId = response.body.id;
|
const measurementId = response.body.id;
|
||||||
|
|
||||||
this.logger.debug({
|
this.logger.debug({
|
||||||
message: `Created GlobalPing measurement: ${measurementId}`,
|
message: `Created GlobalPing measurement: ${measurementId} for target: ${cleanTarget}`,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "createMeasurement",
|
method: "createMeasurement",
|
||||||
details: { measurementId, url, locations },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return measurementId;
|
return measurementId;
|
||||||
@@ -165,8 +178,7 @@ export class GlobalPingService implements IGlobalPingService {
|
|||||||
const successfulResults: GeoCheckResult[] = [];
|
const successfulResults: GeoCheckResult[] = [];
|
||||||
|
|
||||||
for (const probeResult of probeResults) {
|
for (const probeResult of probeResults) {
|
||||||
// Skip failed or timeout results
|
if (probeResult.result.status !== "finished") {
|
||||||
if (probeResult.result.status !== "finished" || !probeResult.result.statusCode || !probeResult.result.timings) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,23 +192,38 @@ export class GlobalPingService implements IGlobalPingService {
|
|||||||
latitude: probeResult.probe.latitude,
|
latitude: probeResult.probe.latitude,
|
||||||
};
|
};
|
||||||
|
|
||||||
const timings: GeoCheckTimings = {
|
// HTTP results have statusCode and timings, ping results have stats
|
||||||
total: probeResult.result.timings.total,
|
if (probeResult.result.statusCode && probeResult.result.timings) {
|
||||||
dns: probeResult.result.timings.dns,
|
const timings: GeoCheckTimings = {
|
||||||
tcp: probeResult.result.timings.tcp,
|
total: probeResult.result.timings.total,
|
||||||
tls: probeResult.result.timings.tls,
|
dns: probeResult.result.timings.dns,
|
||||||
firstByte: probeResult.result.timings.firstByte,
|
tcp: probeResult.result.timings.tcp,
|
||||||
download: probeResult.result.timings.download,
|
tls: probeResult.result.timings.tls,
|
||||||
};
|
firstByte: probeResult.result.timings.firstByte,
|
||||||
|
download: probeResult.result.timings.download,
|
||||||
|
};
|
||||||
|
|
||||||
const result: GeoCheckResult = {
|
successfulResults.push({
|
||||||
location,
|
location,
|
||||||
status: probeResult.result.statusCode >= 200 && probeResult.result.statusCode < 300,
|
status: probeResult.result.statusCode >= 200 && probeResult.result.statusCode < 300,
|
||||||
statusCode: probeResult.result.statusCode,
|
statusCode: probeResult.result.statusCode,
|
||||||
timings,
|
timings,
|
||||||
};
|
});
|
||||||
|
} else if (probeResult.result.stats) {
|
||||||
successfulResults.push(result);
|
successfulResults.push({
|
||||||
|
location,
|
||||||
|
status: probeResult.result.stats.loss === 0,
|
||||||
|
statusCode: probeResult.result.stats.loss === 0 ? 200 : 5000,
|
||||||
|
timings: {
|
||||||
|
total: probeResult.result.stats.avg,
|
||||||
|
dns: 0,
|
||||||
|
tcp: 0,
|
||||||
|
tls: 0,
|
||||||
|
firstByte: 0,
|
||||||
|
download: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return successfulResults;
|
return successfulResults;
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ export type { GeoContinent } from "@/types/geoCheck.js";
|
|||||||
export const MonitorTypes = ["http", "ping", "pagespeed", "hardware", "docker", "port", "game", "grpc", "unknown"] as const;
|
export const MonitorTypes = ["http", "ping", "pagespeed", "hardware", "docker", "port", "game", "grpc", "unknown"] as const;
|
||||||
export type MonitorType = (typeof MonitorTypes)[number];
|
export type MonitorType = (typeof MonitorTypes)[number];
|
||||||
|
|
||||||
|
export const GeoCheckSupportedTypes: readonly MonitorType[] = ["http", "ping"] as const;
|
||||||
|
export const supportsGeoCheck = (type: MonitorType): boolean => GeoCheckSupportedTypes.includes(type);
|
||||||
|
|
||||||
export const MonitorStatuses = ["up", "down", "paused", "initializing", "maintenance", "breached"] as const;
|
export const MonitorStatuses = ["up", "down", "paused", "initializing", "maintenance", "breached"] as const;
|
||||||
export type MonitorStatus = (typeof MonitorStatuses)[number];
|
export type MonitorStatus = (typeof MonitorStatuses)[number];
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user