diff --git a/App/FeatureSet/Docs/Content/monitor/custom-code-monitor.md b/App/FeatureSet/Docs/Content/monitor/custom-code-monitor.md new file mode 100644 index 0000000000..3f74d1a1f2 --- /dev/null +++ b/App/FeatureSet/Docs/Content/monitor/custom-code-monitor.md @@ -0,0 +1,26 @@ +# Custom Code Monitor + +Custom Code Monitor allows you to write custom scripts to monitor your applications. You can use this feature to monitor your applications in a way that is not possible with the existing monitors. For example, you can have multi-step API requests. + +#### Example + +The following example shows how to use a Synthtic Monitor: + +```javascript +// You can use axios module, and page object from Playwright here. + +await axios.get('https://api.example.com/'); + +// Axios Documentation here: https://axios-http.com/docs/intro + +return { + data: 'Hello World' // return any data you like here. +}; +``` + +### Things to consider + +- You can use `console.log` to log the data in the console. This will be available in the logs section of the monitor. +- You can return the data from the script using the `return` statement. +- This is a JavaScript script, so you can use all the JavaScript features in the script. +- You can use `axios` module to make HTTP requests in the script. You can use it to make API calls from the script. \ No newline at end of file diff --git a/App/FeatureSet/Docs/Content/monitor/synthetic-monitor.md b/App/FeatureSet/Docs/Content/monitor/synthetic-monitor.md new file mode 100644 index 0000000000..5e5ccb0a6d --- /dev/null +++ b/App/FeatureSet/Docs/Content/monitor/synthetic-monitor.md @@ -0,0 +1,58 @@ +# Synthetic Monitor + +Synthetic monitoring is a way to proactively monitor your applications by simulating user interactions. You can create a synthetic monitor to check the availability and performance of your applications from different locations around the world. + +#### Example + +The following example shows how to use a Synthtic Monitor: + +```javascript +// You can use axios module, and page object from Playwright here. +// Page Object is a class that represents a single page in a browser. + +await page.goto('https://playwright.dev/'); + +// Playwright Documentation here: https://playwright.dev/docs/intro + +// Here are some of the variables that you can use in the context of the monitored object: + +console.log(browserType) // This will list the browser type in the current run context - Chromium, Firefox, Webkit + +console.log(screenSizeType) // This will list the screen size type in the current run context - Mobile, Tablet, Desktop + +// Playwright page object belongs to that specific browser context, so you can use it to interact with the browser. + +// To take screenshots, + +const screenshots = []; + +const screenshot = { + screenshotDataInBase64: (await page.screenshot()).toString('base64'), // returns base64 encoded image + screenshotName: 'Playwright Screenshot' +}; + +// make sure you add it to screnshot array + +screenshots.push(screenshot); + +// when you want to return a value, use return statement with data as a prop. You can also add screenshots in the screenshots array. + +return { + data: 'Hello World', + screenshots: screenshots // array of screenshots +}; +``` + +### Use of Playwright + +We use Playwright to simulate user interactions. You can use Playwright `page` object to interact with the browser and perform actions like clicking buttons, filling forms, and taking screenshots. + +### Things to consider + +- You only have `page` object available in the context of the script. This is from Playwright Page class. You can use it to run all the interactions with the browser. +- You can use `console.log` to log the data in the console. This will be available in the logs section of the monitor. +- You can return the data from the script using the `return` statement. You can also return screenshots in the screenshots array. +- You can use `browserType` and `screenSizeType` variables to get the browser type and screen size type in the current run context. Feel free to use them in your script if you like. +- This is a JavaScript script, so you can use all the JavaScript features in the script. +- You can use `axios` module to make HTTP requests in the script. You can use it to make API calls from the script. +- If you are using oneuptime.com, you will always have the latest version of Playwright & browsers available in the context of the script. If you're self-hosting, please make sure you update the probes to have the latest version of Playwright and the browsers. \ No newline at end of file diff --git a/App/FeatureSet/Docs/Utils/Nav.ts b/App/FeatureSet/Docs/Utils/Nav.ts index 761f2700d0..457fda36bc 100644 --- a/App/FeatureSet/Docs/Utils/Nav.ts +++ b/App/FeatureSet/Docs/Utils/Nav.ts @@ -38,10 +38,19 @@ const DocsNav: NavGroup[] = [ { title: 'Monitor', links: [ + { + title: 'Custom Code Monitor', + url: '/docs/monitor/custom-code-monitor', + }, + { + title: 'Synthetic Monitor', + url: '/docs/monitor/synthetic-monitor', + }, { title: 'JavaScript Expressions', url: '/docs/monitor/javascript-expression', }, + ], }, { diff --git a/Probe/Jobs/Monitor/FetchList.ts b/Probe/Jobs/Monitor/FetchList.ts index bd8b4bdf15..3d9addacb8 100644 --- a/Probe/Jobs/Monitor/FetchList.ts +++ b/Probe/Jobs/Monitor/FetchList.ts @@ -51,7 +51,6 @@ export default class FetchListAndProbe { private async fetchListAndProbe(): Promise { try { - logger.debug('Fetching monitor list'); const monitorListUrl: URL = URL.fromString( @@ -79,7 +78,6 @@ export default class FetchListAndProbe { ); for (const monitor of monitors) { - try { await MonitorUtil.probeMonitor(monitor); } catch (err) {