ping type globalping checks
This commit is contained in:
1 parent
188445c57a
commit
124a8c0b07
9 files changed
+80
-40
No files matched your search
@@ -885,7 +885,7 @@ const CreateMonitorPage = () => {
|
||||
/>
|
||||
)}
|
||||
|
||||
{watchedType === "http" && (
|
||||
{(watchedType === "http" || watchedType === "ping") && (
|
||||
<ConfigBox
|
||||
title={t("pages.createMonitor.form.geoChecks.title")}
|
||||
subtitle={t("pages.createMonitor.form.geoChecks.description")}
|
||||
|
||||
@@ -122,7 +122,11 @@ const UptimeDetailsPage = () => {
|
||||
);
|
||||
|
||||
const geoChecksUrl = useMemo(() => {
|
||||
if (!monitorId || monitor?.type !== "http" || !monitor?.geoCheckEnabled) {
|
||||
if (
|
||||
!monitorId ||
|
||||
(monitor?.type !== "http" && monitor?.type !== "ping") ||
|
||||
!monitor?.geoCheckEnabled
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
const params = new URLSearchParams();
|
||||
@@ -141,7 +145,11 @@ const UptimeDetailsPage = () => {
|
||||
|
||||
// Fetch paginated geo checks for the table
|
||||
const geoChecksTableUrl = useMemo(() => {
|
||||
if (!monitorId || monitor?.type !== "http" || !monitor?.geoCheckEnabled) {
|
||||
if (
|
||||
!monitorId ||
|
||||
(monitor?.type !== "http" && monitor?.type !== "ping") ||
|
||||
!monitor?.geoCheckEnabled
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
const params = new URLSearchParams();
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import { IGeoChecksRepository } from "./IGeoChecksRepository.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 mongoose from "mongoose";
|
||||
import { getDateForRange } from "@/utils/dataUtils.js";
|
||||
import { ILogger } from "@/utils/logger.js";
|
||||
|
||||
const SERVICE_NAME = "GeoChecksRepository";
|
||||
|
||||
class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||
static SERVICE_NAME = SERVICE_NAME;
|
||||
|
||||
private logger: any;
|
||||
constructor(logger: any) {
|
||||
private logger: ILogger;
|
||||
constructor(logger: ILogger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ export class GeoChecksService implements IGeoChecksService {
|
||||
}
|
||||
|
||||
// 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) {
|
||||
// GlobalPing API is down, skip this check
|
||||
|
||||
@@ -340,7 +340,7 @@ export class MonitorService implements IMonitorService {
|
||||
throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 });
|
||||
}
|
||||
|
||||
if (monitor.type !== "http" || !monitor.geoCheckEnabled) {
|
||||
if ((monitor.type !== "http" && monitor.type !== "ping") || !monitor.geoCheckEnabled) {
|
||||
return { groupedGeoChecks: [] };
|
||||
}
|
||||
|
||||
|
||||
@@ -125,8 +125,13 @@ export class SuperSimpleQueue implements ISuperSimpleQueue {
|
||||
data: monitor,
|
||||
});
|
||||
|
||||
// Return early if we don't need geo checks
|
||||
if (monitor.type !== "http" && monitor.type !== "ping") {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add geo check job if enabled for HTTP monitors
|
||||
if (monitor.geoCheckEnabled && monitor.type === "http") {
|
||||
if (monitor.geoCheckEnabled) {
|
||||
this.scheduler.addJob({
|
||||
id: `${monitorId}-geo`,
|
||||
template: "geo-check-job",
|
||||
@@ -175,7 +180,7 @@ export class SuperSimpleQueue implements ISuperSimpleQueue {
|
||||
|
||||
// Handle geo check job lifecycle
|
||||
const geoJobId = `${monitor.id}-geo`;
|
||||
if (monitor.geoCheckEnabled && monitor.type === "http") {
|
||||
if (monitor.geoCheckEnabled && (monitor.type === "http" || monitor.type === "ping")) {
|
||||
// Check if geo job exists
|
||||
const existingGeoJob = await this.scheduler.getJob(geoJobId);
|
||||
if (existingGeoJob) {
|
||||
|
||||
@@ -280,19 +280,18 @@ export class SuperSimpleQueueHelper implements ISuperSimpleQueueHelper {
|
||||
throw new AppError({ message: "No monitor id", service: SERVICE_NAME, method: "getGeoCheckJob" });
|
||||
}
|
||||
|
||||
if (monitor.type !== "http") {
|
||||
if (!monitor.geoCheckEnabled) {
|
||||
return;
|
||||
}
|
||||
if (monitor.type !== "http" && monitor.type !== "ping") {
|
||||
this.logger.debug({
|
||||
message: `Monitor ${monitorId} is not HTTP type, skipping geo check`,
|
||||
message: `Monitor ${monitorId} is not HTTP or Ping type, skipping geo check`,
|
||||
service: SERVICE_NAME,
|
||||
method: "getGeoCheckJob",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!monitor.geoCheckEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!monitor.geoCheckLocations || monitor.geoCheckLocations.length === 0) {
|
||||
this.logger.warn({
|
||||
message: `No geo check locations configured for monitor ${monitorId}`,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { GeoContinent, GeoCheckResult, GeoCheckTimings, GeoCheckLocation } from "@/types/geoCheck.js";
|
||||
import { MonitorType } from "@/types/index.js";
|
||||
import type { ILogger } from "@/utils/logger.js";
|
||||
import got from "got";
|
||||
|
||||
@@ -8,7 +9,7 @@ const POLL_INTERVAL_MS = 2000;
|
||||
const MAX_POLL_TIMEOUT_MS = 30000;
|
||||
|
||||
interface GlobalPingMeasurementRequest {
|
||||
type: "http";
|
||||
type: "http" | "ping";
|
||||
target: string;
|
||||
locations: Array<{ continent: GeoContinent }>;
|
||||
limit: number;
|
||||
@@ -44,13 +45,22 @@ interface GlobalPingProbeResult {
|
||||
firstByte: number;
|
||||
download: number;
|
||||
};
|
||||
stats?: {
|
||||
min: number;
|
||||
max: number;
|
||||
avg: number;
|
||||
total: number;
|
||||
loss: number;
|
||||
rcv: number;
|
||||
drop: number;
|
||||
};
|
||||
rawOutput?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface IGlobalPingService {
|
||||
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[]>;
|
||||
}
|
||||
|
||||
@@ -67,13 +77,16 @@ export class GlobalPingService implements IGlobalPingService {
|
||||
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 {
|
||||
if (monitorType !== "http" && monitorType !== "ping") {
|
||||
throw new Error(`Unsupported monitor type for GlobalPing: ${monitorType}`);
|
||||
}
|
||||
// GlobalPing API expects target without protocol (http:// or https://)
|
||||
const cleanTarget = url.replace(/^https?:\/\//, "");
|
||||
|
||||
const requestBody: GlobalPingMeasurementRequest = {
|
||||
type: "http",
|
||||
type: monitorType,
|
||||
target: cleanTarget,
|
||||
locations: locations.map((continent) => ({ continent })),
|
||||
limit: locations.length,
|
||||
@@ -88,10 +101,9 @@ export class GlobalPingService implements IGlobalPingService {
|
||||
const measurementId = response.body.id;
|
||||
|
||||
this.logger.debug({
|
||||
message: `Created GlobalPing measurement: ${measurementId}`,
|
||||
message: `Created GlobalPing measurement: ${measurementId} for target: ${cleanTarget}`,
|
||||
service: SERVICE_NAME,
|
||||
method: "createMeasurement",
|
||||
details: { measurementId, url, locations },
|
||||
});
|
||||
|
||||
return measurementId;
|
||||
@@ -165,8 +177,7 @@ export class GlobalPingService implements IGlobalPingService {
|
||||
const successfulResults: GeoCheckResult[] = [];
|
||||
|
||||
for (const probeResult of probeResults) {
|
||||
// Skip failed or timeout results
|
||||
if (probeResult.result.status !== "finished" || !probeResult.result.statusCode || !probeResult.result.timings) {
|
||||
if (probeResult.result.status !== "finished") {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -180,23 +191,38 @@ export class GlobalPingService implements IGlobalPingService {
|
||||
latitude: probeResult.probe.latitude,
|
||||
};
|
||||
|
||||
const timings: GeoCheckTimings = {
|
||||
total: probeResult.result.timings.total,
|
||||
dns: probeResult.result.timings.dns,
|
||||
tcp: probeResult.result.timings.tcp,
|
||||
tls: probeResult.result.timings.tls,
|
||||
firstByte: probeResult.result.timings.firstByte,
|
||||
download: probeResult.result.timings.download,
|
||||
};
|
||||
// HTTP results have statusCode and timings, ping results have stats
|
||||
if (probeResult.result.statusCode && probeResult.result.timings) {
|
||||
const timings: GeoCheckTimings = {
|
||||
total: probeResult.result.timings.total,
|
||||
dns: probeResult.result.timings.dns,
|
||||
tcp: probeResult.result.timings.tcp,
|
||||
tls: probeResult.result.timings.tls,
|
||||
firstByte: probeResult.result.timings.firstByte,
|
||||
download: probeResult.result.timings.download,
|
||||
};
|
||||
|
||||
const result: GeoCheckResult = {
|
||||
location,
|
||||
status: probeResult.result.statusCode >= 200 && probeResult.result.statusCode < 300,
|
||||
statusCode: probeResult.result.statusCode,
|
||||
timings,
|
||||
};
|
||||
|
||||
successfulResults.push(result);
|
||||
successfulResults.push({
|
||||
location,
|
||||
status: probeResult.result.statusCode >= 200 && probeResult.result.statusCode < 300,
|
||||
statusCode: probeResult.result.statusCode,
|
||||
timings,
|
||||
});
|
||||
} else if (probeResult.result.stats) {
|
||||
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;
|
||||
|
||||
@@ -33,6 +33,7 @@ export interface GeoCheckResult {
|
||||
status: boolean;
|
||||
statusCode: number;
|
||||
timings: GeoCheckTimings;
|
||||
|
||||
}
|
||||
|
||||
export interface GeoCheck {
|
||||
|
||||
Reference in new issue
Block a user