A SiSense SQL alert can run SQL on a schedule and trigger an email when a certain criteria or rule, such as a threshold or target, is met. This email can optionally generate a message in a slack channel.
Query
underneath the SQL.exploration
Copy to clipboard
and paste it to a Google sheet.case
statement that returns 0
if everything is ok and 1
if it should alert.Query from the graph:
select date_trunc(week,created_at_date) as day, count(*) as widgets_created_per_day
from widget_log
where created_at_date < DATEADD(day,-90,CURRENT_DATE()
group by 1
Query changed to be daily:
select date_trunc(day,created_at_date) as day, count(*) as widgets_created_per_day
from widget_log
where created_at_date < DATEADD(day,-90,CURRENT_DATE()
group by 1
Average over the last 7 days
select avg(widghets_created_per_day) from (
select date_trunc(day,created_at_date) as day, count(*) as widgets_created_per_day
from widget_log
where created_at_date < DATEADD(day,-7,CURRENT_DATE()
group by 1) as T
Average over the last 30 days
select avg(widghets_created_per_day) from (
select date_trunc(day,created_at_date) as day, count(*) as widgets_created_per_day
from widget_log
where created_at_date < DATEADD(day,-30,CURRENT_DATE()
group by 1) as T
Standard deviation over the last 7 days
select stdev(widghets_created_per_day) from (
select date_trunc(day,created_at_date) as day, count(*) as widgets_created_per_day
from widget_log
where created_at_date < DATEADD(day,-7,CURRENT_DATE()
group by 1) as T
Example for an alert if metric is above acceptable threshold
Change the >
to a <
for checking it is under (in a separate alert)
select case when
/* copy above average over the last 7 days */
>
(
/* copy above average over the last 30 days */
+
/* copy above standard deviation over the last 30 days */
)
then 'alert'
else 'ok'
end
Confidential inside GitLab due to specific metrics that were discussed that are not things we can be publicly transparent about