Set Up Custom SQL Monitors
Write your own SQL scripts to set up tests specific to your needs.
Custom SQL Monitor provides and easy and flexible interface for monitoring the database based on custom SQL filter. This feature takes in the select query provided by the user and wraps it in a subquery which does a row_count
on the result and record incident if row_count > 0
.
You can choose either to set up a Normal
Custom SQL monitor or one that has a Group-by
column selected as a segmentation.
How to Set Up a Custom SQL Monitor
Select the “Custom SQL” card from the Config module.

You’ll be directed to the “Create a New Monitor” form with Setup and Configure steps.
Step 1: Set-up
Select a Data Source.
Choose Monitor Mode (Scheduled or On-Demand).
If applicable you can set your monitor as
Grouped by
, you can turn on thetoggle
Click “Proceed to Monitor Setup” to continue.


Step 2: Configure: Schedule Monitor
Once you proceed to setup, you’ll reach the “Configure” page, where you can review your previous selections.

Within the "Configure" popup, users must complete the necessary fields to save their preferences and successfully set up their Custom SQL monitor. These required fields include:
Monitor Name
Monitor Description is Optional.
Frequency
Add your Custom SQL query: Enter the query and Click on Validate, Once query is validated success message (Query successfully validated) will be displayed.

Get Notified/Custom Alert
To set custom alerts, you must first turn on the
"Notify default channel"
toggle. Activating this will allow users to specify their desired alert channels, be it via emails or Slack channels.You can select the desired alert channels in the dropdown.
Mention the address or channel name in the field.
At last select the Incident Levels

Click on
Submit
and your monitor is created successfully.Once you click on
Submit
you’ll be redirected toAll Monitor
tab.
Configure: On-demand Monitor
Set-up
Select the
data source
andMonitor Mode
If applicable you can set your monitor as
Grouped by
, by turning on thetoggle

Once you click on
Proceed to monitor setup
,you will reach the next page (Configure).Here, on the top you can see the previous page selection overview.

Within the "Configure" popup, users must complete the necessary fields to save their preferences and successfully set up their Custom SQL monitor. These required fields include:
Monitor Name
Monitor Description is Optional.
Add your Custom SQL query: Enter the query and Click on Validate, Once query is validated success message (Query successfully validated) will be displayed.

Upon completing the required fields to create an On Demand monitor for Custom SQL, users can complete the set up process by choosing either of the following confirmation buttons based on their preferred use case:
Save
: This is an applicable option for users who wish to set up an on demand monitor without running the monitor scan immediately after creation.Save an run
: This option is applicable for users who wish to run the On Demand Monitor immediately upon creation. For the next time users wish to run the on demand monitor again, users can navigate to theAll Monitor's.
After selecting the above option you will be redirected to ALL MONITORS tab.
Modify Monitoring
To modify an existing monitor:
Go to All Monitors.
Click the ellipsis (︙) and select View Monitor.
Click on
Run once
to run the monitor manually.
For setting up On-demand Monitor/Schedule Grouped By you can refer to Configure: On-demand /Schedule Monitor Grouped By for Custom SQL
Tips and Tricks
In this section, we will show a few ways you can configure the monitor using the power of SQL!
Label invalidation
Filtering records with specified label to trigger an incident
SELECT *
FROM public.sale
WHERE created_at BETWEEN
NOW() - '30mins'::INTERVAL AND NOW()
AND status in ('pending', 'rejected')
Value Sum
Filtering sum of value over a threshold of a specified interval
SELECT 1
FROM public.sale
WHERE created_at BETWEEN
NOW() - '30mins'::INTERVAL AND NOW()
HAVING SUM(price * quantity) > 10000
Discrepancy
The discrepancy between 2 tables
WITH sale AS (
SELECT SUM(price * quantity) as amount
FROM public.sale
WHERE created_at BETWEEN
NOW() - '30mins'::INTERVAL AND NOW()
)
, in_flow AS (
SELECT SUM(amount) as amount
FROM public.in_flow
WHERE created_at BETWEEN
NOW() - '30mins'::INTERVAL AND NOW()
)
, base AS (
SELECT
(SELECT amount FROM sale)
- (SELECT amount FROM in_flow)
AS discrepancy
)
SELECT discrepancy
FROM base
WHERE discrepancy > 10000
Last updated