Monitors
This document provides references to create or update the different type of monitors.
Please note that the sample queries below only show a subset of the fields available for brevity. You can use introspection to see all available fields.
Adding Monitors Using the API vs Monitors as Code
This page is for setting up monitors using our API. If you are interesting in setting up monitors in a large environment using code, please see: Monitors as Code
Create or update monitors
Each monitor type is created or updated by calling a different GraphQL operation.
- CreateOrUpdateValidation: Create or update a Validation monitor
- CreateOrUpdateMetricMonitor: Create or update a Metric monitor
- CreateOrUpdateCustomSqlRule: Create or update a Custom SQL monitor
- CreateOrUpdateComparisonRule: Create or update a Comparison monitor
- CreateOrUpdateQueryPerfRule: Create or update a Query Performance monitor
- CreateOrUpdateJsonSchemaMonitor: Create or update a JSON Schema monitor
Below you can find some examples for Metric and Custom SQL monitors.
Create vs Update
Please note the only difference between making a new monitor and updating one is providing the monitor
uuid
in the API call.
Create or Update Metric Monitors
Metric monitors can be updated via the API. Use cases include updating the description, changing the monitor interval or schedule, and modifying the monitor alert conditions
Bootstrapped Data
Please be aware that during the initial creation of Metric Monitors, Monte Carlo will attempt to backfill backfill a year's worth of metric history. We do this to generate a threshold more quickly. In order to minimize strain on your resources, there is a safeguard so that no more than 4 backfills are being run at any given time. After the initial collection, the monitors default to running one query twice a day.
mutation createOrUpdateMetricMonitor {
createOrUpdateMetricMonitor(
description: "Metric monitor for Row count on <table>"
dwId: "<WAREHOUSE UUID>"
dataSource: { type: TABLE, mcon: "<TABLE MCON>" }
aggregate: {
timeAxis: {
field: "created_time"
type: FIELD
}
by: DAY
}
collectionLagHours: 0
scheduleConfig: {
scheduleType: FIXED
intervalMinutes: 1440
startTime: "2024-11-27T01:00:00.000Z"
}
alertConditions: [
{
type: "threshold",
operator: "AUTO",
metric: "ROW_COUNT_CHANGE",
fields: []
}
],
){
metricMonitor{
uuid
createdBy { email }
}
}
}
{
"data": {
"createOrUpdateMetricMonitor": {
"metricMonitor": {
"uuid": "932615cd-3296-45b8-8760-3cc618a57375",
"createdBy": {
"email": "[email protected]"
}
}
}
}
}
Return uuid
It's important to return the
uuid
in the above command! If you need to update or change your rule, this is the id you will need to rerun this command.
Create or Update Custom SQL Monitors
Custom SQL monitors can be updated via the API. Use cases include updating the description, changing the monitor interval or schedule, and modifying the monitor alert conditions.
mutation createOrUpdateCustomSqlRule {
createOrUpdateCustomSqlRule(
description: "No error rows in table"
dwId: "<WAREHOUSE UUID>"
sql: "SELECT * FROM <table> WHERE <field> = 'error'"
scheduleConfig: {
scheduleType: FIXED
intervalMinutes: 1440
startTime: "2024-11-27T01:00:00.000Z"
}
alertCondition: {
type: THRESHOLD,
operator: GT,
threshold: 0
}
) {
customRule {
uuid
creatorId
}
}
}
{
"data": {
"createOrUpdateCustomSqlRule": {
"customRule": {
"uuid": "d312568e-0651-4838-bac5-e3dd640ea911",
"creatorId": "[email protected]"
}
}
}
}
Return uuid
It's important to return the
uuid
in the above command! If you need to update or change your rule, this is the id you will need to rerun this command.
Listing Custom SQL Monitors
If you would like to view a Custom SQL monitor after the fact, you can always run the following query with the uuid
that was returned from the create mutation:
query {
getCustomRule(
ruleId: "<rule_uuid>"
) {
intervalMinutes
comparisons {
comparisonType
metric
operator
threshold
}
description
timezone
startTime
customSql
}
}
{
"data": {
"getCustomRule": {
"intervalMinutes": 1440,
"comparisons": [
{
"comparisonType": "THRESHOLD",
"metric": "custom_metric_<rule_uuid>",
"operator": "GT",
"threshold": 0
}
],
"description": "Sample description",
"timezone": "UTC",
"startTime": "2021-06-30T19:00:00+00:00",
"customSql": "<sql_query>"
}
}
}
If you are updating an existing SQL rule, you can find a list of your existing rule uuid
s by running:
query {
getCustomRules (
first: 5
ruleType: "CUSTOM_SQL"
) {
edges {
node {
uuid
creatorId
createdTime
description
isDeleted
entities
scheduleConfig {
intervalMinutes
startTime
}
}
}
}
}
{
"errors": <There might be some errors here. For the most part, you can ignore!>,
"data": {
"getCustomRules": {
"edges": [
{
"node": {
"uuid": "<this is the uuid you are looking for>",
"creatorId": "<email>",
"createdTime": "2021-06-29T20:01:22.427007+00:00",
"description": "Sample Description",
"isDeleted": false,
"entities": [
"<full_table_id>"
],
"scheduleConfig": {
"intervalMinutes": 1440,
"startTime": "2021-06-30T19:00:00+00:00"
}
}
},
….
]
}
}
}
This query accepts the following arguments to narrow in on the rule you are looking for: before
, after
, first
, last
, and ruleType
. Once you have found the necessary uuid
, you can follow step 2 above to update it by adding the uuid
argument in the call.
Updated 9 days ago