Skip to content

Instantly share code, notes, and snippets.

@eidam
Last active March 16, 2024 20:54
Show Gist options
  • Save eidam/942cee25e3ec6ef8de61cc14823293b2 to your computer and use it in GitHub Desktop.
Save eidam/942cee25e3ec6ef8de61cc14823293b2 to your computer and use it in GitHub Desktop.
A Cloudflare GQL API request to get health checks RTT (round-trip time), grouped by region.
// GQL API docs => https://developers.cloudflare.com/analytics/graphql-api/
// tldr; => POST https://api.cloudflare.com/client/v4/graphql
const requestBody = {
query: `
query RequestsAndDataTransferByHostname($zoneTag: string, $filter: filter) {
viewer {
zones(filter: {zoneTag: $zoneTag}) {
healthCheckEventsAdaptiveGroups(limit: 10000, filter: $filter) {
dimensions {
healthCheckName
datetimeFiveMinutes
region
}
avg {
rttMs
}
}
}
}
}`,
variables: {
zoneTag, // Health Checks' Cloudflare Zone ID
filter: {
datetime_geq: new Date(Date.now() - 60 * 60 * 24 * 1000).toISOString(),
rttMs_lt: 1000,
OR: [
{ healthCheckName: "rlimit-com-cf-proxied" },
{ healthCheckName: "rlimit-com-direct" },
],
},
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment