New Relic allows you use NerdGraph to create ping monitors (also known as simple monitors). Ping monitors check if a URL or endpoint is accessible by making HTTP requests at regular intervals. This tutorial provides examples of how to use the NerdGraph API to automate the creation of ping monitors.
Create a ping monitor
You can create a ping monitor using the syntheticsCreateSimpleMonitor mutation. This mutation allows you to configure monitoring for any publicly accessible URL or endpoint.
Input parameters
Parameter | Data Type | Is it Required? | Description |
|---|---|---|---|
| Integer | Yes | Your New Relic account ID where the monitor will be created. |
| Array | Yes | Array of public location identifiers where the monitor will run checks (e.g., |
| String | Yes | The display name for your ping monitor. |
| Enum | Yes | How often the monitor runs. Options: |
| Enum | Yes | The monitor status. Options: |
| String | Yes | The URL or endpoint to monitor (e.g., |
| String | No | Text that must appear in the response for the check to pass. If specified, the monitor will fail if this text is not found in the response body. |
| Boolean | No | Whether to validate the TLS/SSL certificate. Set to |
| Float | No | The monitor's Apdex target in seconds, used to populate SLA reports. Defaults to 7.0 seconds. |
Sample request
mutation { syntheticsCreateSimpleMonitor( accountId: ACCOUNT_ID monitor: { locations: { public: ["LOCATION_1", "LOCATION_2"] } name: "YOUR_MONITOR_NAME" period: PERIOD status: STATUS uri: "MONITORED_URI" advancedOptions: { customHeaders: { name: "HEADER_NAME", value: "HEADER_VALUE" } redirectIsFailure: REDIRECT_IS_FAILURE responseValidationText: "VALIDATION_TEXT" shouldBypassHeadRequest: BYPASS_HEAD_REQUEST useTlsValidation: TLS_VALIDATION } apdexTarget: APDEX_TARGET } ) { errors { description type } }}Sample response
A successful response returns null for errors:
{ "data": { "syntheticsCreateSimpleMonitor": { "errors": null } }}If there are any issues creating the monitor, the errors array will contain objects with description and type fields explaining what went wrong.
Update a ping monitor
You can update an existing ping monitor using the syntheticsUpdateSimpleMonitor mutation. This allows you to modify the configuration of a ping monitor that has already been created.
Input parameters
Parameter | Data Type | Is it Required? | Description |
|---|---|---|---|
| String | Yes | The unique entity GUID of the monitor you want to update. |
| Array | No | Array of public location identifiers where the monitor will run checks (e.g., |
| String | No | The updated display name for your ping monitor. |
| Enum | No | How often the monitor runs. Options: |
| Enum | No | The monitor status. Options: |
| String | No | The URL or endpoint to monitor (e.g., |
| Object | No | Custom HTTP headers to include in the request. Each header has a |
| Boolean | No | If |
| String | No | Text that must appear in the response for the check to pass. If specified, the monitor will fail if this text is not found in the response body. |
| Boolean | No | If |
| Boolean | No | Whether to validate the TLS/SSL certificate. Set to |
| Float | No | The monitor's Apdex target in seconds, used to populate SLA reports. Defaults to 7.0 seconds. |
Sample request
mutation { syntheticsUpdateSimpleMonitor( guid: "ENTITY_GUID" monitor: { locations: { public: ["LOCATION_1", "LOCATION_2"] } name: "YOUR_MONITOR_NAME" period: PERIOD status: STATUS uri: "MONITORED_URI" advancedOptions: { customHeaders: { name: "HEADER_NAME", value: "HEADER_VALUE" } redirectIsFailure: REDIRECT_IS_FAILURE responseValidationText: "VALIDATION_TEXT" shouldBypassHeadRequest: BYPASS_HEAD_REQUEST useTlsValidation: TLS_VALIDATION } apdexTarget: APDEX_TARGET } ) { errors { description type } }}Sample response
A successful response returns null for errors:
{ "data": { "syntheticsUpdateSimpleMonitor": { "errors": null } }}If there are any issues updating the monitor, the errors array will contain objects with description and type fields explaining what went wrong.
Delete a synthetic monitor
This API allows you to delete an existing monitor using the syntheticsDeleteMonitor mutation with the guid parameter.
Input parameters
Parameter | Data Type | Is it Required? | Description |
|---|---|---|---|
| String | Yes | The unique entity GUID of the monitor you want to delete. |
Sample request
mutation { syntheticsDeleteMonitor(guid: "ENTITY_GUID") { deletedGuid }}Sample response
A successful deletion returns the GUID of the deleted monitor:
{ "data": { "syntheticsDeleteMonitor": { "deletedGuid": "ENTITY_GUID" } }}If there are any issues deleting the monitor, an error will be returned with details about what went wrong.