-
Notifications
You must be signed in to change notification settings - Fork 37
Bulk monitors guide #1338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Bulk monitors guide #1338
Changes from 25 commits
dac0a36
5b124f2
8728cb4
68006c0
5dff046
7006ec4
07b6488
b6ce9e5
7eba844
bb7f06f
1172fcd
26ade4a
04e5d9f
c46b62e
be0d5ae
406e162
392b248
2dda78a
2fbdac2
aab4907
cc8707f
24c6234
8a834d3
7d05930
9f3b5da
5f1b85f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ site/resources/ | |
__checks__/screenshots | ||
.vercel | ||
checkly-github-report.md | ||
CLAUDE.md |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
--- | ||
title: Monitor 500 pages in 2 minutes with Checkly | ||
displayTitle: Monitor 500 pages in 2 minutes with Checkly | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found the headline slightly misleading when reading it for the first time. "Creating monitors" would be more tangible if we want to be explicit. |
||
description: >- | ||
By leveraging arrays, sitemap parsing, and dynamic monitor creation, you can ensure comprehensive coverage of your website, API routes, and third-party services—all from a single configuration file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: should we remove the part about third-party services? From a support POV, we recommend not monitoring sites you don't control (you can't fix it if it goes down, it can change at any moment, and third-parties have every right to block this kind of traffic) |
||
author: Nočnica Mellifera | ||
avatar: 'images/avatars/nica-mellifera.png' | ||
tags: | ||
- FAQ | ||
--- | ||
|
||
Checkly’s model of [Monitoring as Code](https://www.checklyhq.com/guides/getting-started-with-monitoring-as-code/) lets you create site monitors right from your IDE. With the recent release of uptime monitoring, we have the ability to monitor every single URL, API route, and even third party service that makes up our product. We don’t want to write out dozens or hundreds of files for all this monitoring coverage. | ||
|
||
If this is your first interaction with Monitoring as Code, check out our guide on [creating URL Monitors with Monitoring as Code](https://www.checklyhq.com/guides/url-monitoring/). That guide is all you need to create a project with a first monitor. | ||
|
||
## tl;dr Here’s how to create lots of monitors at once | ||
|
||
Here’s a single file that will create URL monitors from an array: | ||
|
||
```ts | ||
//urlArrayMonitors.check.ts | ||
//this will create URL monitors in your Checkly dashboard | ||
|
||
import { Frequency, UrlMonitor, UrlAssertionBuilder } from 'checkly/constructs' | ||
|
||
//just two URLs in this example, add as many as you want | ||
const sitemapUrls = [ | ||
'https://docs.anthropic.com/de/api/admin-api/workspace_members/get-workspace-member', | ||
'https://docs.anthropic.com/de/api/admin-api/workspace_members/list-workspace-members' | ||
] | ||
|
||
//create paths and friendly names for each monitor | ||
sitemapUrls.forEach((url, index) => { | ||
const urlPath = new URL(url).pathname.replace(/\//g, '-').replace(/^-+|-+$/g, '') || 'root' | ||
const monitorId = `checkly-${urlPath}-ping` | ||
const monitorName = `${urlPath.replace(/-/g, ' ')} pinger` | ||
|
||
//create each monitor with a five minute interval | ||
new UrlMonitor(monitorId, { | ||
frequency: Frequency.EVERY_5M, | ||
name: monitorName, | ||
activated: true, | ||
request: { | ||
url: url, | ||
skipSSL: false, | ||
followRedirects: true, | ||
assertions: [ | ||
UrlAssertionBuilder.statusCode().equals(200), | ||
] | ||
} | ||
}) | ||
}) | ||
``` | ||
|
||
This takes an array of URLs and creates a new monitor with a unique ID and name. We can test run these tests with `npx checkly test` and both monitors will run in our CLI’s default region. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I'm missing something but its unclear to me what to do with this file. Where does it live? Where do the generated monitors land? How can I execute it? |
||
|
||
 | ||
|
||
You can add as many URLs as you’d like to the array and get them monitored at the settings listed. Some lines from this file are worth noting: | ||
|
||
```ts | ||
const urlPath = new URL(url).pathname.replace(/\//g, '-').replace(/^-+|-+$/g, '') || 'root' | ||
``` | ||
|
||
Depending on how you format your input array, this cleanup step may be unnecessary. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be helpful to provide more context on what this cleanup step does so I can understand whether I need it or not. |
||
|
||
```ts | ||
const monitorId = `checkly-${urlPath}-ping` | ||
``` | ||
|
||
The monitor’s logical ID should stay as stable as possible in later updates. When you deploy this monitor to Checkly, a matching ID will be updated with the history of the monitor preserved. A new Logical ID will mean a new monitor is created, and any IDs that were previously deployed from this project that are now missing will be deleted! If you want to double-check your settings, be sure to run the preview command `npx checkly deploy -p` before deploying (for more detail on this, check out the [guide to creating URL Monitors](https://www.checklyhq.com/guides/url-monitoring/)). By contrast, feel free to update the syntax on the `name` value as much as you would like, this just updates the displayed name. | ||
|
||
```ts | ||
UrlAssertionBuilder.statusCode().equals(200), | ||
``` | ||
|
||
A URL Monitor is the most basic type of monitor that Checkly offers, so the `UrlAssertionBuilder` class only allows you to check the status code. For more advanced assertions on the response, try an [API check](https://www.checklyhq.com/docs/api-checks/#cli-example). | ||
|
||
## Parse a Sitemap and Monitor Every URL | ||
|
||
As just one extension of this concept, rather than manually downloading and parsing a list of URLs into an array, why don’t we parse our site’s sitemap into a list of URLs to monitor? This extension of the check above grabs a sitemap from a given URL and parses it to create our URL array. | ||
|
||
```ts | ||
// sitemapUrlMonitors.check.js | ||
import * as https from 'https'; | ||
import { Frequency, UrlMonitor, UrlAssertionBuilder } from 'checkly/constructs' | ||
const sitemapUrl = 'https://openai.com/sitemap.xml/webinar/'; | ||
|
||
function downloadSitemap(url: string): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
https.get(url, (response) => { | ||
let data = ''; | ||
|
||
response.on('data', (chunk) => { | ||
data += chunk; | ||
}); | ||
|
||
response.on('end', () => { | ||
resolve(data); | ||
}); | ||
|
||
response.on('error', (error) => { | ||
reject(error); | ||
}); | ||
}).on('error', (error) => { | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
|
||
function parseSitemap(xmlContent: string): string[] { | ||
const urls: string[] = []; | ||
// Simple regex to extract URLs from <loc> tags | ||
// this should work for most sitemaps but isn't universal. | ||
const locRegex = /<loc>(.*?)<\/loc>/g; | ||
let match; | ||
|
||
while ((match = locRegex.exec(xmlContent)) !== null) { | ||
urls.push(match[1]); | ||
} | ||
|
||
return urls; | ||
} | ||
|
||
console.log(`Downloading sitemap from: ${sitemapUrl}`); | ||
|
||
try { | ||
const xmlContent = await downloadSitemap(sitemapUrl); | ||
console.log('Sitemap downloaded successfully'); | ||
|
||
const sitemapUrls = parseSitemap(xmlContent); | ||
console.log(`Found ${sitemapUrls.length} URLs in sitemap`); | ||
console.log('\nSitemap URLs:'); | ||
console.log(sitemapUrls); | ||
|
||
//create paths and friendly names for each monitor | ||
sitemapUrls.forEach((url, index) => { | ||
const urlPath = new URL(url).pathname.replace(/\//g, '-').replace(/^-+|-+$/g, '') || 'root' | ||
const monitorId = `checkly-${urlPath}-ping` | ||
const monitorName = `Checkly ${urlPath.replace(/-/g, ' ')} Monitor` | ||
|
||
//create each monitor with a five minute interval | ||
new UrlMonitor(monitorId, { | ||
frequency: Frequency.EVERY_5M, | ||
name: monitorName, | ||
activated: true, | ||
request: { | ||
url: url, | ||
skipSSL: false, | ||
followRedirects: true, | ||
assertions: [ | ||
UrlAssertionBuilder.statusCode().equals(200), | ||
] | ||
} | ||
}) | ||
}) | ||
} catch (error) { | ||
console.error('Error:', error); | ||
process.exit(1); | ||
} | ||
``` | ||
|
||
Let's test these URL monitors and preview their deployment with: | ||
|
||
```bash | ||
npx checkly test && npx checkly deploy -p | ||
``` | ||
|
||
If you're using the sitemap URL above (for a list of OpenAI webinar pages), you'll get a short list of monitors that have been tested: | ||
|
||
 | ||
|
||
Followed by the deployment preview: | ||
|
||
 | ||
|
||
If these look correct, you’re ready to run `npx checkly deploy` and create your new monitors! | ||
|
||
## Next Steps: Grouping, and More Advanced Checks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be worth mentioning the global config file here as well? |
||
|
||
With all of our monitors managed with a single file, we can update their configuration just by changing the values in the `new UrlMonitor` block above. However, as we have more detailed and nuanced monitoring, it would be nice to have a single place to manage configuration for timing, alerting, and notification channels for a group of checks. All of that is possible with Checkly Groups. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Might be good to add a link to the groups doc here. https://www.checklyhq.com/docs/groups/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Laura, we should either link to the groups construct here or add an example code snippet below. Otherwise its a little unclear how to act on this. |
||
|
||
Next, we’d like to apply these tools to more advanced check types like API checks and Browser checks written with Playwright. Check out our documentation on [dynamic monitor creation](https://www.checklyhq.com/docs/cli/dynamic-check-creation/) to see examples of these more complex checks. | ||
|
||
# Conclusion | ||
|
||
Can you really monitor 500 pages in two minutes? Absolutely! | ||
|
||
With Checkly’s **Monitoring as Code** approach, scaling your monitoring to hundreds or even thousands of pages is effortless. By leveraging Checkly constructs, sitemap parsing, and dynamic monitor creation, you can ensure comprehensive coverage of your website, API routes, and third-party services—all from a single configuration file. | ||
|
||
**Key Takeaways:** | ||
|
||
- Bulk URL Monitoring: Easily create multiple URL monitors from an array or sitemap. | ||
- Flexible Configuration: Adjust frequency, assertions, and naming dynamically. | ||
- Preview Before Deploy: Use `npx checkly deploy -p` to verify changes before applying them. | ||
- Extend to Advanced Checks: Apply the same principles to [API checks](https://www.checklyhq.com/docs/api-checks/) and [browser checks](https://www.checklyhq.com/docs/browser-checks/). | ||
|
||
For more details on structuring and managing your monitors, check out our guides on: | ||
|
||
- [Creating URL Monitors](https://www.checklyhq.com/docs/url-monitors/) | ||
- [Dynamic Monitor Creation](https://www.checklyhq.com/docs/cli/dynamic-check-creation/) | ||
- [Organizing Checks with Groups](https://www.checklyhq.com/docs/groups/) | ||
|
||
Ready to supercharge your monitoring? Start deploying with Checkly and keep your applications reliable at scale! 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to have: A short intro sentence briefly summarizing the use case behind this. For example "When working with AI IDEs, you can provide them with context on Checkly, which enables automated generation of Checkly constructs, helping you speed up your monitor creation workflow."
Also: As a reader it'll be interesting to know if I can chose from one of the options listed below or if its recommended to provide as much context as possible e.g. reference the docs site + download the custom rules.