Global Uptime Monitoring with New Relic Synthetics
PythonUptime monitoring is vital for ensuring that your website or web application is accessible to users around the world. By setting up a synthetic monitor, you can simulate user interactions with your site from various global locations. This not only helps to detect outages but also provides insights into performance and can alert you to fix issues before they affect your users.
In this explanation, we will create a Pulumi program using the New Relic Synthetics resources to set up global uptime monitoring.
Resources Used
newrelic.synthetics.Monitor
: This represents a New Relic Synthetics monitor, which will regularly check your site's availability from different locations.newrelic.synthetics.AlertCondition
: It allows you to specify the conditions under which an alert should be created if your site's uptime metrics cross pre-defined thresholds.
Monitoring Setup Explanation
- First, you will define a synthetic monitor with the URL of your site. You can tag the monitor for easier identification and specify the type of monitor, for example, a simple ping.
- Then, specify the locations from which you want the synthetic checks to be executed. This helps in global monitoring, as these locations should be spread across different continents or regions relevant to your user base.
- Next, set up an alert condition linked to the synthetic monitor. If the monitor detects downtime or any performance issues that cross the thresholds set, an alert is triggered.
- You can include a runbook URL, which is a link to a document that provides a set of instructions on how to handle the alert situation.
Below is the Pulumi program written in Python that sets up a global uptime monitor using New Relic Synthetics.
import pulumi import pulumi_newrelic as newrelic # Initialize a New Relic Synthetics monitor for your website. synthetics_monitor = newrelic.synthetics.Monitor("uptime-monitor", uri="https://example.com", # Replace with your website's URL name="Global Uptime Monitor", type="SIMPLE", # Type of the monitor (e.g., "SCRIPT_BROWSER", "SIMPLE", "BROWSER", etc.) status="ENABLED", # Status of the monitor (e.g., "MUTED", "DISABLED", "ENABLED") locationsPublics=["AWS_US_WEST_1", "AWS_EU_CENTRAL_1"], # List public locations to run the monitor from # Other optional configurations like `verifySsl`, `frequency`, etc., can be set according to your needs. ) # Define an alert condition for the synthetic monitor. alert_condition = newrelic.synthetics.AlertCondition("uptime-alert-condition", policyId=123, # Replace with your New Relic policy ID monitorId=synthetics_monitor.id, # Associates this alert condition with the created synthetic monitor name="Uptime Failure Alert", enabled=True, runbookUrl="https://example.com/runbook" # URL pointing to runbook instructions ) # Export the monitor's ID for later use if needed. pulumi.export('monitor_id', synthetics_monitor.id)
In the program above:
- We create a New Relic Synthetics monitor with a simple ping check to
https://example.com
. You should update theuri
parameter with the URL you want to monitor. - We specify the type of the monitor as
SIMPLE
for a basic uptime check. Other types of monitors include more complex checks like scripted browser interactions. - We configure the monitor to check from two AWS regions,
AWS_US_WEST_1
andAWS_EU_CENTRAL_1
. You can add more regions according to New Relic's public locations or your requirements. - We associate an alert condition with our synthetic monitor by passing
monitorId
as the ID of the synthetic monitor. We also reference a policy ID which groups this alert condition. Make sure you replace123
with the actual policy ID from your New Relic account. - Finally, we set a runbook URL that points to a set of instructions to follow whenever this alert triggers.
Run this program with the Pulumi CLI by executing
pulumi up
, and it will deploy these resources to New Relic, setting up your global uptime monitoring.