• Log inStart now

Synthetic monitoring best practices guide

With synthetic monitoring, you can monitor and test your apps and address issues before they affect your end users. Here are five tips so you can take advantage of its full power.

1. Choose your synthetic monitor

Synthetic monitors are virtual browsers that measure the performance of your website and capture aggregate numbers for load time, uptime, and average download size. You'll also have access to detailed statistics about downtime incidents and each page resource.

We have seven types of synthetic monitors to choose from, depending on what you want to monitor and how you'd like to do it. For example, a step monitor is a great way to create what essentially functions as a scripted browser without writing code. If you're looking for automated management of your synthetic monitors, our NerdGraph API lets you create, update, and delete your synthetic monitors through API calls.

Add your synthetic monitor

  1. To add a monitor, go to one.newrelic.com > Synthetics. (If you have an EU-based account, go to one.eu.newrelic.com.) Click Create monitor.
  1. Select a monitor type, then fill in all required fields.

  2. You can add tags, change the period, or select a different runtime version. For ping and simple browser monitors, you can add a validation string. You can use the advanced options to enable substring monitoring for the following types of response validations:

    • Verify SSL (for ping and simple browser). This option verifies the validity of the SSL certificate chain. It can be duplicated by running the following syntax:

      bash
      $
      openssl s_client -servername <var>{YOUR_HOSTNAME}</var> -connect <var>{YOUR_HOSTNAME</var>}:443 -CApath /etc/ssl/certs > /dev/null
    • Bypass HEAD request (for ping monitors). This option skips the default HEAD request and instead uses the GET verb with a ping check. GET requests will always happen if the HEAD request fails.

    • Redirect is Failure (for ping). If a redirect result occurs when Redirect is Failure is enabled, your synthetic monitors categorize it as a failure rather than following the redirect and checking the resulting URL.

  3. Select the locations from where you want your monitor to run. We recommend choosing at least three locations to avoid false positives. In other words, if at least one location returns a successful result then the endpoint must be up and triggering of an alert can be avoided.

  4. Depending on the monitor type, you'll be prompted to either Save monitor, Validate, or Write script.

  5. View your results as they're received in the summary page.

2. View the summary page for your synthetic monitors

On the summary page, you'll see information about the status of your synthetic monitor. If something created an active incident that triggered an alert, then click the critical alert for this monitor to open in a new tab. You can also access all your alert policies for your monitors when you click to manage alert policies for all monitors at the top of the page.

3. Get an overview of your application's performance

To ensure that web services are in place, working as expected, and error-free, you'll want continuous access to the results of your application's performance. Synthetic monitoring gives this type of assurance by performing automated tests on your web application for each selected location. Your synthetic monitors will note downtime instances (called "violations") and collect the aggregated numbers, results, and detailed statistics for each page resource.

To get quickly discover failing monitors, you can use the index of synthetic monitors page to see which monitors have open violations, success rate over 24 hours, number of failing locations, the monitor period, and monitor type. Clicking on a monitor, you'll be taken to the Summary page where you'll be presented with information to assess where that particular monitor is failing, why it is failing (last error message, error response codes, duration by domain), and more, to give you a deeper insight into your application's performance over time.

View your monitors in Explorer

4. View individual monitor results

You need to view the performance of your web apps as they're accessed from different parts of the globe. Your Results page shows how everything from development to production affects user experience. You can sort what's listed to better identify problem areas or unusual results. Try filtering by location to compare monitor performance from different locations. (The "Network timings" graph below provides a snapshot of webpage performance over a given period.) To do this, you'll:

  1. Go to one.newrelic.com > Synthetics.
  2. From the Monitors tab, select your monitor.
  3. Click Monitor, then click Results.

Results gives you an up-to-the-minute view of the slowest page loads for every monitored location.

5. Understand the load-time impact of each resource

The synthetics resources page shows how the different components of your website (for example, CSS, JavaScript, images, HTML, etc.) is affecting your overall load. You can drill into detailed metrics collected at run time, locate performance information for time spent by third-party resources, and identify HTTP response codes for each resource. To do this, you'll:

  1. Go to one.newrelic.com, then click Synthetics.
  2. From the Monitors dropdown menu, select your monitor.
  3. Click Monitor, then click Resources.

6. Configure and develop a scripted browser test

Using scripted browsers, you can build complex monitoring workflows with the Selenium JavaScript Webdriver bindings. For example, you can log in to the application, navigate to a particular link, and wait for a page element to load and add an assertion. To do this, you'll:

  1. Go to one.newrelic.com > Synthetics.
  2. Select your monitor type (for example, scripted browser).
  3. Enter the name and details of your monitor (for example, sitename.com scripted browser)
  4. Select the locations from where you want your monitor to run (for example, Mumbai, Seoul, Columbus, and Montreal).
  5. Choose a frequency for how often your monitor will run from this (for example, five minutes).
  6. Set a notification method to alert your team when performance violations occur.
  7. You are now ready to write your script. (Below is an example script to test performance of newrelic.com and check that certain elements have loaded.)
/**
* Script Name: scripted browser - next gen runtime
* Author: New Relic
* Version: 1.1
* Purpose: best practices example
* Reference: https://docs.newrelic.com/docs/synthetics/synthetic-monitoring/scripting-monitors/synthetic-scripted-browser-reference-monitor-versions-chrome-100/
*/
// -------------------- CONSTANTS
const SCRIPT_NAME = "scripted browser - next gen runtime" // name to record in script log
const DEFAULT_TIMEOUT = 10000 // default is 10 seconds to locate page
const PAGE_LOAD_TIMEOUT = 60000 // fail early to prevent long duration timeouts
const USER_AGENT = "default" // set the user agent for Chrome
const PROTOCOL = "https://" // set the protocol
const USERNAME = "" // username:
const PASSWORD = "" // password@
const DOMAIN = "newrelic.com" // your domain
const PATH = "" // /path/to/page
const CHECK = "All your telemetry in one secure cloud." // text to match on page
const AUTH = USERNAME + PASSWORD
const FULL_URL = PROTOCOL + AUTH + DOMAIN + PATH
// -------------------- CONFIGURATION
var assert = require("assert")
// script-wide timeout (ms) for functions: waitForAndFindElement and waitForPendingRequests
// better to fail early if it is expected to take less time than the DEFAULT_TIMEOUT
// in order to release the heavy worker thread on the minion for the next job
$webDriver.manage().setTimeouts({pageLoad: DEFAULT_TIMEOUT}) // sets element load timeout
$webDriver.manage().setTimeouts({pageLoad: PAGE_LOAD_TIMEOUT}) // sets page load timeout
// -------------------- VARIABLES
var By = $selenium.By
var loc = {
main: By.id("main-content"),
nav: By.className("js-header-site-nav"),
telemetry: By.xpath("//*[@id='main-content']/article/div[5]/div[2]/div/div[1]/a/div/div/div[2]"),
tools: [
{ service: 'apm', selector: By.xpath("//*[@id='tab-21882']/div/span[2]") },
{ service: 'infra', selector: By.xpath("//*[@id='tab-22578']/div/span[2]") },
{ service: 'k8s', selector: By.xpath("//*[@id='tab-22579']/div/span[2]") },
{ service: 'logs', selector: By.xpath("//*[@id='tab-22580']/div/span[2]") },
{ service: 'errors', selector: By.xpath("//*[@id='tab-22581']/div/span[2]") },
{ service: 'browser', selector: By.xpath("//*[@id='tab-22582']/div/span[2]") },
{ service: 'mobile', selector: By.xpath("//*[@id='tab-22583']/div/span[2]") },
{ service: 'synthetics', selector: By.xpath("//*[@id='tab-22584']/div/span[2]") },
{ service: 'npm', selector: By.xpath("//*[@id='tab-22585']/div/span[2]") },
{ service: 'codestream', selector: By.xpath("//*[@id='tab-22586']/div/span[2]") }
]
}
// -------------------- FUNCTIONS
// for backwards compatibility with legacy runtimes
async function waitForAndFindElement(locator, timeout) {
const webElement = await $webDriver.wait(
$selenium.until.elementLocated(locator),
timeout,
"Timed-out waiting for element to be located using: " + locator
)
await $webDriver.wait(
$selenium.until.elementIsVisible(webElement),
timeout,
"Timed-out waiting for element to be visible using ${element}"
)
return await $webDriver.findElement(locator)
}
// -------------------- START OF SCRIPT
console.log("Starting synthetics script: " + SCRIPT_NAME)
console.log("Default timeout is set to " + DEFAULT_TIMEOUT / 1000 + " seconds")
console.log("URI: " + FULL_URL)
// Setting user agent is not then-able, so we do this first (if defined and not default)
if (USER_AGENT && 0 !== USER_AGENT.trim().length && USER_AGENT != "default") {
$headers.add("User-Agent", USER_AGENT)
console.log("Setting User-Agent to " + USER_AGENT)
}
// Step 1
// if an error happens at any step, script execution is halted and a failed result is returned
console.log("1. first step")
await $webDriver.get(FULL_URL)
// Step 2
// verify id for main has loaded
console.log("2. waitForAndFindElement: ", loc.main.value)
await waitForAndFindElement(loc.main, DEFAULT_TIMEOUT)
// Step 3
// verify site nav has loaded
console.log("3. waitForAndFindElement: ", loc.nav.value)
await waitForAndFindElement(loc.nav, DEFAULT_TIMEOUT)
// Step 4
console.log("4. findElement: ", loc.telemetry.value)
const element = await $webDriver.findElement(loc.telemetry, DEFAULT_TIMEOUT)
// Step 5
console.log("5. getText")
const text = await element.getText()
// Step 6
console.log("6. assert.equal: " + text + " == " + CHECK)
assert.equal(text, CHECK, "validation text not found")
// Step 7 (if assert is equal)
console.log("7. verify tools:")
loc.tools.forEach(async function (nr, i, arr) {
let n = i+1
try{
// verify each asset has loaded
console.log(" " + n + ". " + nr.service)
await $webDriver.findElement(nr.selector, DEFAULT_TIMEOUT)
}catch(exception){
console.error("Failure in Step 7." + n)
throw err
}
})
Copyright © 2022 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.