mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Tonypowa/tutorials (#96747)
* replaced request bin * advanced options * test data + screenshot
This commit is contained in:
parent
169b61b98d
commit
59e9b42557
@ -217,16 +217,6 @@ Create a notification policy if you want to handle metrics returned by alert rul
|
||||
|
||||
The alert rule that you are about to create is meant to monitor web traffic page views. The objective is to explore what an alert instance is and how to leverage routing individual alert instances by using label matchers and notification policies.
|
||||
|
||||
### Add a data source
|
||||
|
||||
Grafana includes a [test data source](https://grafana.com/docs/grafana/latest/datasources/testdata/) that creates simulated time series data.
|
||||
|
||||
1. In Grafana navigate to **Connections > Add new connection**.
|
||||
1. Search for **TestData**.
|
||||
1. Click **Add new data source**.
|
||||
1. Click **Save & test**.
|
||||
|
||||
You should see a message confirming that the data source is working.
|
||||
<!-- INTERACTIVE page step5.md END -->
|
||||
<!-- INTERACTIVE page step6.md START -->
|
||||
|
||||
@ -243,6 +233,8 @@ Make it short and descriptive as this will appear in your alert notification. Fo
|
||||
|
||||
In this section, we use the default options for Grafana-managed alert rule creation. The default options let us define the query, a expression (used to manipulate the data -- the `WHEN` field in the UI), and the condition that must be met for the alert to be triggered (in default mode is the threshold).
|
||||
|
||||
Grafana includes a [test data source](https://grafana.com/docs/grafana/latest/datasources/testdata/) that creates simulated time series data. This data source is included in the demo environment for this tutorial. If you're working in Grafana Cloud or your own local Grafana instance, you can add the data source through the **Connections** menu.
|
||||
|
||||
1. Select **TestData** data source from the drop-down menu.
|
||||
1. From **Scenario** select **CSV Content**.
|
||||
1. In the Query editor, switch to **Code** mode by clicking the button on the right.
|
||||
|
@ -189,15 +189,9 @@ Next, we establish an [alert rule](https://grafana.com/docs/grafana/latest/alert
|
||||
|
||||
In this section, we use the default options for Grafana-managed alert rule creation. The default options let us define the query, a expression (used to manipulate the data -- the `WHEN` field in the UI), and the condition that must be met for the alert to be triggered (in default mode is the threshold).
|
||||
|
||||
1. Select the **Prometheus** data source from the drop-down menu.
|
||||
1. In the Query editor, switch to **Code** mode by clicking the button on the right.
|
||||
1. Enter the following query:
|
||||
Grafana includes a [test data source](https://grafana.com/docs/grafana/latest/datasources/testdata/) that creates simulated time series data. This data source is included in the demo environment for this tutorial. If you're working in Grafana Cloud or your own local Grafana instance, you can add the data source through the **Connections** menu.
|
||||
|
||||
```promql
|
||||
vector(1)
|
||||
```
|
||||
|
||||
In Prometheus, `vector(1)` is a special type of PromQL query that generates a constant vector. This is useful in testing and query manipulation, where you might need a constant value for calculations or comparisons. This query allows you to create an alert rule that is always firing.
|
||||
1. Select the **TestData** data source from the drop-down menu.
|
||||
|
||||
1. In the **Alert condition** section:
|
||||
|
||||
@ -205,9 +199,9 @@ In this section, we use the default options for Grafana-managed alert rule creat
|
||||
|
||||
1. Click **Preview alert rule condition** to run the query.
|
||||
|
||||
It should return a single sample with the value 1 at the current timestamp. And, since `1` is above `0`, the alert condition has been met, and the alert rule state is `Firing`.
|
||||
It should return random time series data. The alert rule state should be `Firing`.
|
||||
|
||||
{{< figure src="/media/docs/alerting/firing-alert-preview.png" max-width="1200px" caption="A preview of a firing alert" >}}
|
||||
{{< figure src="/media/docs/alerting/random-walk-firing-alert-rule.png" max-width="1200px" caption="A preview of a firing alert" >}}
|
||||
|
||||
### Set evaluation behavior
|
||||
|
||||
|
@ -392,24 +392,23 @@ To begin, let's set up a webhook contact point. Once we have a usable endpoint,
|
||||
|
||||
### Create a contact point for Grafana-managed alert rules
|
||||
|
||||
In this step, we set up a new contact point. This contact point uses the _webhooks_ channel. In order to make this work, we also need an endpoint for our webhook channel to receive the alert notification. We can use [requestbin.com](https://requestbin.com) to quickly set up that test endpoint. This way we can make sure that our alert manager is actually sending a notification somewhere.
|
||||
In this step, we set up a new contact point. This contact point uses the _webhooks_ channel. In order to make this work, we also need an endpoint for our webhook channel to receive the alert notification. We can use [Webhook.site](https://webhook.site/) to quickly set up that test endpoint. This way we can make sure that our alert manager is actually sending a notification somewhere.
|
||||
|
||||
1. Browse to [requestbin.com](https://requestbin.com).
|
||||
1. Under the **Create Request Bin** button, click the link to create a **public bin** instead.
|
||||
1. From Request Bin, copy the endpoint URL.
|
||||
1. Browse to [Webhook.site](https://webhook.site/).
|
||||
1. Copy Your unique URL.
|
||||
|
||||
Your Request Bin is now waiting for the first request.
|
||||
Your webhook endpoint is now waiting for the first request.
|
||||
|
||||
Next, let's configure a Contact Point in Grafana's Alerting UI to send notifications to our Request Bin.
|
||||
Next, let's configure a Contact Point in Grafana's Alerting UI to send notifications to our webhook endpoint.
|
||||
|
||||
1. Return to Grafana. In Grafana's sidebar, hover over the **Alerting** (bell) icon and then click **Manage Contact points**.
|
||||
1. Click **+ Add contact point**.
|
||||
1. In **Name**, write **RequestBin**.
|
||||
1. In **Name**, write **Webhook**.
|
||||
1. In **Integration**, choose **Webhook**.
|
||||
1. In **URL**, paste the endpoint to your request bin.
|
||||
1. In **URL**, paste the endpoint to your webhook endpoint.
|
||||
|
||||
1. Click **Test**, and then click **Send test notification** to send a test alert notification to your request bin.
|
||||
1. Navigate back to the Request Bin you created earlier. On the left side, there's now a `POST /` entry. Click it to see what information Grafana sent.
|
||||
1. Click **Test**, and then click **Send test notification** to send a test alert notification to your webhook endpoint.
|
||||
1. Navigate back to the webhook endpoint you created earlier. On the left side, there's now a `POST /` entry. Click it to see what information Grafana sent.
|
||||
1. Return to Grafana and click **Save contact point**.
|
||||
|
||||
We have now created a dummy webhook endpoint and created a new Alerting Contact Point in Grafana. Now we can create an alert rule and link it to this new channel.
|
||||
@ -424,24 +423,25 @@ Now that Grafana knows how to notify us, it's time to set up an alert rule:
|
||||
|
||||
1. In Grafana's sidebar, hover over the **Alerting** (bell) icon and then click **Alert rules**.
|
||||
|
||||
In this tutorial, we use the default options for Grafana-managed alert rule creation. The default options let us define the query, a expression (used to manipulate the data -- the `WHEN` field in the UI), and the condition that must be met for the alert to be triggered (in default mode is the threshold).
|
||||
In this tutorial, we use the advanced options for Grafana-managed alert rule creation. The advanced options let us define queries, expressions (used to manipulate the data), and the condition that must be met for the alert to be triggered (the default condition is the threshold).
|
||||
|
||||
1. Click **+ New alert rule**.
|
||||
1. For **Section 1**, name the rule `fundamentals-test`.
|
||||
1. For **Section 2**, Find the **query A** box, and choose your Prometheus data source.
|
||||
1. For **Section 2**, toggle the **Advanced options** button.
|
||||
1. Find the **query A** box, and choose your Prometheus data source.
|
||||
1. Enter the same Prometheus query that we used in our earlier panel:
|
||||
|
||||
```
|
||||
sum(rate(tns_request_duration_seconds_count[5m])) by(route)
|
||||
```
|
||||
|
||||
1. Scroll down to bottom of section #2 and click the **Preview alert rule condition** button. You should see some data returned.
|
||||
1. Keep `Last` as the value for the reducer function (`WHEN`), and `0.2` as the threshold value. This is the value above which the alert rule should trigger. [You can read more about queries and conditions here](/docs/grafana/latest/alerting/fundamentals/alert-rules/queries-conditions/#expression-queries).
|
||||
1. Keep expressions **B** and **C** as they are. These expressions (Reduce and Threshold, respectively) are included by default when creating a new rule. Enter `0.2` as threshold value. You can read more about queries and conditions [here](/docs/grafana/latest/alerting/fundamentals/alert-rules/queries-conditions/#expression-queries).
|
||||
1. Scroll down to bottom of section #2 and click the **Preview** button. You should see some data returned.
|
||||
1. In **Section 3**, in Folder, create a new folder, by clicking `New folder` and typing a name for the folder. This folder contains our alert rules. For example: `fundamentals`. Then, click `create`.
|
||||
1. In the Evaluation group, repeat the above step to create a new one. Name it `fundamentals` too.
|
||||
1. Choose an Evaluation interval (how often the alert rule are evaluated). For example, every `10s` (10 seconds).
|
||||
1. Set the pending period. This is the time that a condition has to be met until the alert instance enters in Firing state and a notification is sent. Enter `0s`. For the purposes of this tutorial, the evaluation interval is intentionally short. This makes it easier to test. This setting makes Grafana wait until an alert instance has fired for a given time before Grafana sends the notification.
|
||||
1. In **Section 4**, choose **RequestBin** as the **Contact point**.
|
||||
1. In **Section 4**, choose **Webhook** as the **Contact point**.
|
||||
1. Click **Save rule and exit** at the top of the page.
|
||||
|
||||
### Trigger a Grafana-managed alert rule
|
||||
@ -451,7 +451,7 @@ We have now configured an alert rule and a contact point. Now let's see if we ca
|
||||
1. Browse to [localhost:8081](http://localhost:8081).
|
||||
1. Add a new title and URL, repeatedly click the vote button, or refresh the page to generate a traffic spike.
|
||||
|
||||
Once the query `sum(rate(tns_request_duration_seconds_count[5m])) by(route)` returns a value greater than `0.2` Grafana triggers our alert rule. Browse to the Request Bin we created earlier and find the sent Grafana alert notification with details and metadata.
|
||||
Once the query `sum(rate(tns_request_duration_seconds_count[5m])) by(route)` returns a value greater than `0.2` Grafana triggers our alert rule. Browse to the webhook endpoint we created earlier and find the sent Grafana alert notification with details and metadata.
|
||||
|
||||
<!-- INTERACTIVE ignore START -->
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user