feat: ask several Globalping probes for ping monitors

A single Globalping probe can have a bad route or a bad moment, which
shows up as a false incident (#154). With `probes=N` in the check proxy
URL a TCP_PING or ICMP_PING monitor asks N probes in one measurement:

  checkProxy: 'globalping://<token>?magic=US&probes=2'

The result of the probe with the least packet loss is used, so the
monitor is only down when no probe gets a reply. It's still a single
measurement (one API request to create it, the same polling), each
probe costs a Globalping credit. HTTP monitors are not changed.

Co-Authored-By: Claude <noreply@anthropic.com>
pull/232/head
jakevis 2026-11-19 10:16:58 -08:00
parent e25b90cb2e
commit 8df76d6421
No known key found for this signature in database
2 changed files with 15 additions and 1 deletions

View File

@ -97,7 +97,9 @@ const workerConfig: WorkerConfig = {
// `target` should be a hostname or an IP address
target: '1.2.3.4',
// refer to docs https://github.com/lyc8503/UptimeFlare/wiki/Check-proxy-setup
checkProxy: 'globalping://<YOUR_GLOBALPING_TOKEN>?magic=US',
// [OPTIONAL] `probes=N` asks N probes instead of one (TCP_PING and ICMP_PING only), the monitor is up
// if any of them gets a reply. Every probe costs a Globalping credit.
checkProxy: 'globalping://<YOUR_GLOBALPING_TOKEN>?magic=US&probes=2',
},
],
// [Optional] Notification settings

View File

@ -169,6 +169,12 @@ export async function getStatusWithGlobalPing(
}
}
// Ping monitors can ask several probes (`probes=N`), the target is up if any of them gets a reply
const probes = Number(gpUrl.searchParams.get('probes') || 1)
if ((monitor.method === 'TCP_PING' || monitor.method === 'ICMP_PING') && probes > 1) {
globalPingRequest = { ...globalPingRequest, limit: probes }
}
const startTime = Date.now()
console.log(`Requesting the Global Ping API, payload: ${JSON.stringify(globalPingRequest)}`)
const measurement = await fetchTimeout('https://api.globalping.io/v1/measurements', 5000, {
@ -216,6 +222,12 @@ export async function getStatusWithGlobalPing(
)}, time elapsed: ${Date.now() - pollStart}ms`
)
if (measurementResult.results?.length > 1) {
// Multiple probes, use the result of the one with the least packet loss
const loss = (r: any) => (r.result.status === 'finished' ? r.result.stats?.loss ?? 100 : 101)
measurementResult.results.sort((a: any, b: any) => loss(a) - loss(b))
}
if (
measurementResult.status !== 'finished' ||
measurementResult.results[0].result.status !== 'finished'