Alerting
Cortex supports setting alerts for your APIs out-of-the-box. Alerts are an effective way of identifying problems in your system as they occur.
The following dashboards can be configured with alerts:
RealtimeAPI
BatchAPI
Cluster resources
Node resources
This page demonstrates the process for configuring alerts for a realtime API. The same principles apply to the others as well. Alerts can be configured for a variety of notification channels such as for Slack, Discord, Microsoft Teams, PagerDuty, Telegram and traditional webhooks. In this example, we'll use Slack.
If you don't know how to access the Grafana dashboard for your API, make sure you check out this page first.
Create a Slack channel
Create a slack channel on your team's Slack workspace. We'll name ours "cortex-alerts".
Add an Incoming Webhook to your channel and retrieve the webhook URL. It will look like something like https://hooks.slack.com/services/<XXX>/<YYY>/<ZZZ>
.
Create a Grafana notification channel
Go to Grafana and on the left-hand side panel, hover over the alerting bell and select "Notification channels".
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F26958764%2F114937638-b6667780-9e46-11eb-963a-8a53e5655c3d.png&width=768&dpr=4&quality=100&sign=9f33b00e&sv=1)
Click on "Create channel", add the name of your channel, select Slack as the type of the channel, and paste your Slack webhook URL.
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F26958764%2F114937856-06ddd500-9e47-11eb-8f47-47b043b0bb5c.png&width=768&dpr=4&quality=100&sign=8bb61c67&sv=1)
Click "Test" and see if a sample notification is sent to your Slack channel. If the message goes through, click on "Save".
Create alerts
Now that the notification channel is functioning properly, we can create alerts for our APIs and cluster. For all of our examples, we are using the mpg-estimator
API as an example.
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F26958764%2F114939831-a8662600-9e49-11eb-8774-fbac3ce627d9.png&width=768&dpr=4&quality=100&sign=4c8c884a&sv=1)
API replica threshold alert
Let's create an alert for the "Active Replicas" panel. We want to send notifications every time the number of replicas for the given API exceeds a certain threshold.
Edit the "Active Replicas" panel.
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F26958764%2F114941416-d2b8e300-9e4b-11eb-8def-ee64535fc799.png&width=768&dpr=4&quality=100&sign=85c23f41&sv=1)
Create a copy of the primary query by clicking on the "duplicate" icon.
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F26958764%2F114941557-fe3bcd80-9e4b-11eb-8f69-b9d43ff8eb28.png&width=768&dpr=4&quality=100&sign=847b5058&sv=1)
In the copied query, replace the $api_name
variable with the name of the API you want to create the alert for. In our case, it's mpg-estimator
. Also, click on the eye icon to disable the query from being shown on the graph - otherwise, you'll see duplicates.
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F26958764%2F114941701-275c5e00-9e4c-11eb-991b-34d660d0d05c.png&width=768&dpr=4&quality=100&sign=c3424cf2&sv=1)
Go to the "Alert" tab and click "Create Alert".
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F26958764%2F114941779-40fda580-9e4c-11eb-9aee-514e6b4832ba.png&width=768&dpr=4&quality=100&sign=aaa97a3d&sv=1)
Configure your alert like in the following example and click "Apply".
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F26958764%2F114944749-d7cc6100-9e50-11eb-9b6b-b2c3dabcc78c.png&width=768&dpr=4&quality=100&sign=2a113806&sv=1)
The next time the threshold is exceeded, a notification will be sent to your Slack channel.
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F26958764%2F114948423-a3a86e80-9e57-11eb-8717-94e456a15298.png&width=768&dpr=4&quality=100&sign=84222e84&sv=1)
In-flight requests spike alert
Let's add an alert on the "In-Flight Requests" panel. We want to send an alert if the metric exceeds 50 in-flight requests. For this, follow the same set of instructions as for the previous alert, but this time configure the alert to match the following screenshot:
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F26958764%2F114949182-1bc36400-9e59-11eb-9c19-0d788872a388.png&width=768&dpr=4&quality=100&sign=9ed2bf88&sv=1)
An alert triggered for this will look like:
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F26958764%2F114949593-000c8d80-9e5a-11eb-8cb5-b2c9a2b344e8.png&width=768&dpr=4&quality=100&sign=8a4e4f3&sv=1)
Memory usage alert
Let's add another alert, this time for the "Avg Memory Usage" panel. We want to send an alert if the average memory usage per API replica exceeds its memory request. For this, we need to follow the same set of instructions as for the first alert, but this time the hidden query needs to be expressed as the ratio between the memory usage and memory request:
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F26958764%2F114951903-f1c07080-9e5d-11eb-9aaf-898d46efb7ef.png&width=768&dpr=4&quality=100&sign=196bfcf2&sv=1)
The memory usage alert can to be defined like in the following screenshot:
The resulting alert will look like this:
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F26958764%2F114952346-bd00e900-9e5e-11eb-879a-5851dab7630b.png&width=768&dpr=4&quality=100&sign=ac74369e&sv=1)
Persistent changes
To save your changes permanently, go back to your dashboard and click on the save icon on the top-right corner.
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F26958764%2F114953264-af4c6300-9e60-11eb-8095-40e438c125d8.png&width=768&dpr=4&quality=100&sign=631d1121&sv=1)
Copy the JSON to your clipboard.
Click on the settings button on the top-right corner of your dashboard.
Go to the "JSON Model" section and replace the JSON with the one you've copied to your clipboard. Then click "Save Changes".
Your dashboard now has stored the alert configuration permanently.
Multiple APIs alerts
Due to how Grafana was built, you'll need to re-do the steps of setting a given alert for each individual API. That's because Grafana doesn't currently support alerts on template or transformation queries.
Last updated