Skip to content

Commit

Permalink
beautify the doc
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveYurongSu committed Apr 26, 2021
1 parent 55ea2fd commit 673fbb9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 60 deletions.
8 changes: 4 additions & 4 deletions docs/UserGuide/Advanced-Features/Alerting.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ at present, users can use these two modules with `AlertManager` to realize the w
The pre-compiled binary file can be downloaded [here](https://prometheus.io/download/).

Running command:
````
````shell
./alertmanager --config.file=<your_file>
````

Expand All @@ -60,7 +60,7 @@ Available at [Quay.io](https://hub.docker.com/r/prom/alertmanager/)
or [Docker Hub](https://quay.io/repository/prometheus/alertmanager).

Running command:
````
````shell
docker run --name alertmanager -d -p 127.0.0.1:9093:9093 quay.io/prometheus/alertmanager
````

Expand Down Expand Up @@ -345,7 +345,7 @@ on the `root.ln.wf01.wt01.temperature` time series,
whose operation logic is defined
by `org.apache.iotdb.trigger.AlertingTriggerExample` java class.

``` roomsql
``` sql
CREATE TRIGGER root-ln-wf01-wt01-alert
AFTER INSERT
ON root.ln.wf01.wt01.temperature
Expand All @@ -359,7 +359,7 @@ When we finish the deployment and startup of AlertManager as well as the creatio
we can test the alerting
by writing data to the time series.

``` roomsql
``` sql
INSERT INTO root.ln.wf01.wt01(timestamp, temperature) VALUES (1, 0);
INSERT INTO root.ln.wf01.wt01(timestamp, temperature) VALUES (2, 30);
INSERT INTO root.ln.wf01.wt01(timestamp, temperature) VALUES (3, 60);
Expand Down
53 changes: 28 additions & 25 deletions docs/UserGuide/Advanced-Features/Triggers.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,18 +566,21 @@ for (int i = 0; i < 100; ++i) {
}
```



#### AlertManagerSink

In a trigger, you can use `AlertManagerSink` to send messages to AlertManager。

You need to specify the endpoint to send alerts of your AlertManager when constructing
`AlertManagerConfiguration`
```

```java
AlertManagerConfiguration(String endpoint);
```

`AlertManagerEvent` offers three types of constructors:
```
```java
AlertManagerEvent(String alertname);
AlertManagerEvent(String alertname, Map<String, String> extraLabels);
AlertManagerEvent(String alertname, Map<String, String> extraLabels, Map<String, String> annotations);
Expand All @@ -587,7 +590,7 @@ AlertManagerEvent(String alertname, Map<String, String> extraLabels, Map<String,
* `extraLabels` is optional. In the backend, it is combined with `alertname` to form `labels` to identify an `alert`, which can be used for grouping and deduplication when `AlertManager` sends alarms.
* `annotations` is optional, and its value can use Go style template `{{.<label_key>}}`. `{{.<label_key>}}` will be replaced with `labels[<label_key>]` when the message is finally generated.
* `labels` and `annotations` will be parsed into json string and sent to `AlertManager`:
```
```json
{
"labels": {
"alertname": "<requiredAlertName>",
Expand All @@ -600,41 +603,41 @@ AlertManagerEvent(String alertname, Map<String, String> extraLabels, Map<String,
}
}
```

Call the `onEvent(AlertManagerEvent event)` method of `AlertManagerHandler` to send an alert.

Example 1:


**Example 1:**

Only pass `alertname`.

```java
AlertManagerConfiguration alertManagerConfiguration =
new AlertManagerConfiguration("http://127.0.0.1:9093/api/v1/alerts");
AlertManagerHandler alertManagerHandler = new AlertManagerHandler();

alertManagerHandler.open(alertManagerConfiguration);
alertManagerHandler.open(new AlertManagerConfiguration("http://127.0.0.1:9093/api/v1/alerts"));

String alertName = "test0";
final String alertName = "test0";

AlertManagerEvent alertManagerEvent = new AlertManagerEvent(alertName);

alertManagerHandler.onEvent(alertManagerEvent);
```

Example 2:


**Example 2:**

Pass `alertname` and `extraLabels`.

```java
AlertManagerConfiguration alertManagerConfiguration =
new AlertManagerConfiguration("http://127.0.0.1:9093/api/v1/alerts");
AlertManagerHandler alertManagerHandler = new AlertManagerHandler();

alertManagerHandler.open(alertManagerConfiguration);
alertManagerHandler.open(new AlertManagerConfiguration("http://127.0.0.1:9093/api/v1/alerts"));

String alertName = "test1";
final String alertName = "test1";

HashMap<String, String> extraLabels = new HashMap<>();
final HashMap<String, String> extraLabels = new HashMap<>();
extraLabels.put("severity", "critical");
extraLabels.put("series", "root.ln.wt01.wf01.temperature");
extraLabels.put("value", String.valueOf(100.0));
Expand All @@ -644,35 +647,35 @@ AlertManagerEvent alertManagerEvent = new AlertManagerEvent(alertName, extraLabe
alertManagerHandler.onEvent(alertManagerEvent);
```

Example 3:


**Example 3:**

Pass `alertname``extraLabels``annotations`.

The final value of the `description` field will be parsed as `test2: root.ln.wt01.wf01.temperature is 100.0`.

```java
AlertManagerConfiguration alertManagerConfiguration =
new AlertManagerConfiguration("http://127.0.0.1:9093/api/v1/alerts");
AlertManagerHandler alertManagerHandler = new AlertManagerHandler();

alertManagerHandler.open(alertManagerConfiguration);
alertManagerHandler.open(new AlertManagerConfiguration("http://127.0.0.1:9093/api/v1/alerts"));

String alertName = "test2";
final String alertName = "test2";

HashMap<String, String> extraLabels = new HashMap<>();
final HashMap<String, String> extraLabels = new HashMap<>();
extraLabels.put("severity", "critical");
extraLabels.put("series", "root.ln.wt01.wf01.temperature");
extraLabels.put("value", String.valueOf(100.0));

HashMap<String, String> annotations = new HashMap<>();
final HashMap<String, String> annotations = new HashMap<>();
annotations.put("summary", "high temperature");
annotations.put("description", "{{.alertname}}: {{.series}} is {{.value}}");

AlertManagerEvent alertManagerEvent = new AlertManagerEvent(alertName, extraLabels, annotations);

alertManagerHandler.onEvent(alertManagerEvent);
alertManagerHandler.onEvent(new AlertManagerEvent(alertName, extraLabels, annotations));
```



## Maven Project Example

If you use [Maven](http://search.maven.org/), you can refer to our sample project **trigger-example**.
Expand Down
10 changes: 4 additions & 6 deletions docs/zh/UserGuide/Advanced-Features/Alerting.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ IoTDB 告警功能预计支持两种模式:
预编译好的二进制文件可在 [这里](https://prometheus.io/download/) 下载。

运行方法:
````
````shell
./alertmanager --config.file=<your_file>
````

Expand All @@ -58,7 +58,7 @@ IoTDB 告警功能预计支持两种模式:
[Docker Hub](https://quay.io/repository/prometheus/alertmanager) 获得。

运行方法:
````
````shell
docker run --name alertmanager -d -p 127.0.0.1:9093:9093 quay.io/prometheus/alertmanager
````

Expand Down Expand Up @@ -344,7 +344,7 @@ public class AlertingTriggerExample implements Trigger {
运行逻辑由 `org.apache.iotdb.trigger.AlertingTriggerExample`
类定义的触发器。

``` roomsql
``` sql
CREATE TRIGGER root-ln-wf01-wt01-alert
AFTER INSERT
ON root.ln.wf01.wt01.temperature
Expand All @@ -356,7 +356,7 @@ public class AlertingTriggerExample implements Trigger {
当我们完成 AlertManager 的部署和启动、Trigger 的创建,
可以通过向时间序列写入数据来测试告警功能。

``` roomsql
``` sql
INSERT INTO root.ln.wf01.wt01(timestamp, temperature) VALUES (1, 0);
INSERT INTO root.ln.wf01.wt01(timestamp, temperature) VALUES (2, 30);
INSERT INTO root.ln.wf01.wt01(timestamp, temperature) VALUES (3, 60);
Expand All @@ -376,5 +376,3 @@ INSERT INTO root.ln.wf01.wt01(timestamp, temperature) VALUES (5, 120);





50 changes: 25 additions & 25 deletions docs/zh/UserGuide/Advanced-Features/Triggers.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,17 +583,19 @@ for (int i = 0; i < 100; ++i) {
}
```



#### AlertManagerSink

触发器可以使用`AlertManagerSink` 向 AlertManager 发送消息。

`AlertManagerConfiguration` 的构造需传入 AlertManager 的发送告警的 endpoint。
```
```java
AlertManagerConfiguration(String endpoint);
```

`AlertManagerEvent` 提供三种构造函数:
```
```java
AlertManagerEvent(String alertname);
AlertManagerEvent(String alertname, Map<String, String> extraLabels);
AlertManagerEvent(String alertname, Map<String, String> extraLabels, Map<String, String> annotations);
Expand All @@ -604,7 +606,7 @@ AlertManagerEvent(String alertname, Map<String, String> extraLabels, Map<String,
* `annotations` 可选传,它的 value 值可使用 Go 语言模板风格的 `{{.<label_key>}}`
`{{.<label_key>}}` 在最终生成消息时会被替换为 `labels[<label_key>]`
* `labels``annotations` 会被解析成 json 字符串发送给 `AlertManager`
```
```json
{
"labels": {
"alertname": "<requiredAlertName>",
Expand All @@ -617,41 +619,41 @@ AlertManagerEvent(String alertname, Map<String, String> extraLabels, Map<String,
}
}
```

调用 `AlertManagerHandler``onEvent(AlertManagerEvent event)` 方法发送一个告警。

使用示例 1:


**使用示例 1:**

只传 `alertname`

```java
AlertManagerConfiguration alertManagerConfiguration =
new AlertManagerConfiguration("http://127.0.0.1:9093/api/v1/alerts");
AlertManagerHandler alertManagerHandler = new AlertManagerHandler();

alertManagerHandler.open(alertManagerConfiguration);
alertManagerHandler.open(new AlertManagerConfiguration("http://127.0.0.1:9093/api/v1/alerts"));

String alertName = "test0";
final String alertName = "test0";

AlertManagerEvent alertManagerEvent = new AlertManagerEvent(alertName);

alertManagerHandler.onEvent(alertManagerEvent);
```

使用示例 2:


**使用示例 2:**

传入 `alertname``extraLabels`

```java
AlertManagerConfiguration alertManagerConfiguration =
new AlertManagerConfiguration("http://127.0.0.1:9093/api/v1/alerts");
AlertManagerHandler alertManagerHandler = new AlertManagerHandler();

alertManagerHandler.open(alertManagerConfiguration);
alertManagerHandler.open(new AlertManagerConfiguration("http://127.0.0.1:9093/api/v1/alerts"));

String alertName = "test1";
final String alertName = "test1";

HashMap<String, String> extraLabels = new HashMap<>();
final HashMap<String, String> extraLabels = new HashMap<>();
extraLabels.put("severity", "critical");
extraLabels.put("series", "root.ln.wt01.wf01.temperature");
extraLabels.put("value", String.valueOf(100.0));
Expand All @@ -661,33 +663,31 @@ AlertManagerEvent alertManagerEvent = new AlertManagerEvent(alertName, extraLabe
alertManagerHandler.onEvent(alertManagerEvent);
```

使用示例 3:


**使用示例 3:**

传入 `alertname``extraLabels``annotations`

最终 `description` 字段的值会被解析为 `test2: root.ln.wt01.wf01.temperature is 100.0`

```java
AlertManagerConfiguration alertManagerConfiguration =
new AlertManagerConfiguration("http://127.0.0.1:9093/api/v1/alerts");
AlertManagerHandler alertManagerHandler = new AlertManagerHandler();

alertManagerHandler.open(alertManagerConfiguration);
alertManagerHandler.open(new AlertManagerConfiguration("http://127.0.0.1:9093/api/v1/alerts"));

String alertName = "test2";
final String alertName = "test2";

HashMap<String, String> extraLabels = new HashMap<>();
final HashMap<String, String> extraLabels = new HashMap<>();
extraLabels.put("severity", "critical");
extraLabels.put("series", "root.ln.wt01.wf01.temperature");
extraLabels.put("value", String.valueOf(100.0));

HashMap<String, String> annotations = new HashMap<>();
final HashMap<String, String> annotations = new HashMap<>();
annotations.put("summary", "high temperature");
annotations.put("description", "{{.alertname}}: {{.series}} is {{.value}}");

AlertManagerEvent alertManagerEvent = new AlertManagerEvent(alertName, extraLabels, annotations);

alertManagerHandler.onEvent(alertManagerEvent);
alertManagerHandler.onEvent(new AlertManagerEvent(alertName, extraLabels, annotations));
```


Expand Down

0 comments on commit 673fbb9

Please sign in to comment.