Alerts can be configured to notify site admins when there is something wrong or noteworthy on the Sourcegraph instance.
Alerts are configured in Grafana. (Prometheus Alertmanager may also be used, but this documentation prefers Grafana.)
Before configuring specific alerts in Grafana, you must set up alert channels. Each channel corresponds to an external service to which Grafana will push alerts.
- Access Grafana directly as a Grafana admin:
- Follow these instructions to access Grafana directly (instead of going through the Sourcegraph Site Admin Monitoring page as usual).
- Navigate to the Grafana
/loginURL (e.g.,http://localhost:3070/-/debug/grafana/loginor append/loginto your Grafana direct access URL if different). If you are doing this for the first time, user the username and passwordadminandadmin. - In the left sidebar, click the bell icon 🔔 and select
Notification channels. - Click
New channeland then specify the settings of your channel. TheTypefield selects the type of external service (e.g., PagerDuty, Slack, Email). Some service types will require additional configuration in the service itself. Here are some examples: - Slack
- Go to
https://api.slack.com/appsto create a new Slack App. - Click
Create an App, give the app a name, and clickCreate App. - Click
Incoming Webhooksand toggle onActivate Incoming Webhooks. - Click
Add New Webhook to Workspace. - Pick the channel to which this Slack App will post.
- Back on the Grafana New Notification Channel page, copy the webhook URL to the
Urlfield.
- Go to
- PagerDuty
- Go to
https://app.pagerduty.com/developer/apps. - Click
Create New App. Give the app a name and decription, and set the category to "Application Performance Management". For "Would you like to publish the app for all PagerDuty users?", select "No". ClickSave. - On the Configure App page, under Functionality > Events Integration, click
Add. - On the Event Integration page, under Events Integration Test > Create a Test Service, enter a name and click
Create. - Copy the Integration Key. Click
Saveand thenSaveagain on the Configure App page. - Back in the Grafana New Notification Channel page, paste the Integration Key into the
Integration Keyfield.
- Go to
- After you have specified the settings on the Grafana New Notification Channel page, click
Send Testto send a test notification. You should receive a notification from Grafana via your specified channel. If this worked, clickSave.
NOTE: Alerts have a link back to the relevant Grafana panel. In order for these links to work properly Grafana needs to know under which external URL it is running (note: this is usually different from the direct access URL you used earlier). Set the environment variable
GF_SERVER_ROOT_URLto your Sourcegraph instance external URL followed by the path/-/debug/grafana.
After adding the appropriate notification channels, configure individual alerts to notify those channels.
- Navigate to the dashboard with the panel and metric for which you'd like to configure an
alert.
- Make sure the dashboard is not read-only (the default Sourcegraph-provided dashboards are
read-only, because they are provisioned from disk). If the dashboard is read-only, go to the
dashboard settings (the gear icon in the upper right) and click
Save As..to create a writeable copy.
- Make sure the dashboard is not read-only (the default Sourcegraph-provided dashboards are
read-only, because they are provisioned from disk). If the dashboard is read-only, go to the
dashboard settings (the gear icon in the upper right) and click
- The panel title has a small dropdown next to it. Click the dropdown icon and select
Edit. - In the left sidebar, choose the bell icon 🔔 for Alert.
- Fill out the fields for the alert rule and select a notification channel.
- Verify your rule by clicking
Test Ruleor viewingState History. - Return to the dashboard page by clicking the left arrow in the upper left. Save the dashboard by clicking the save icon in the upper right.