From 673fbb98602ecbcd20d4373148e5651bc258bd80 Mon Sep 17 00:00:00 2001 From: SteveYurongSu Date: Mon, 26 Apr 2021 10:01:16 +0800 Subject: [PATCH] beautify the doc --- docs/UserGuide/Advanced-Features/Alerting.md | 8 +-- docs/UserGuide/Advanced-Features/Triggers.md | 53 ++++++++++--------- .../UserGuide/Advanced-Features/Alerting.md | 10 ++-- .../UserGuide/Advanced-Features/Triggers.md | 50 ++++++++--------- 4 files changed, 61 insertions(+), 60 deletions(-) diff --git a/docs/UserGuide/Advanced-Features/Alerting.md b/docs/UserGuide/Advanced-Features/Alerting.md index 9b2b63e5988f..6ff4e283b5ee 100644 --- a/docs/UserGuide/Advanced-Features/Alerting.md +++ b/docs/UserGuide/Advanced-Features/Alerting.md @@ -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= ```` @@ -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 ```` @@ -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 @@ -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); diff --git a/docs/UserGuide/Advanced-Features/Triggers.md b/docs/UserGuide/Advanced-Features/Triggers.md index 478445f4d4b3..4352be16c5d9 100644 --- a/docs/UserGuide/Advanced-Features/Triggers.md +++ b/docs/UserGuide/Advanced-Features/Triggers.md @@ -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 extraLabels); AlertManagerEvent(String alertname, Map extraLabels, Map annotations); @@ -587,7 +590,7 @@ AlertManagerEvent(String alertname, Map extraLabels, Map}}`. `{{.}}` will be replaced with `labels[]` when the message is finally generated. * `labels` and `annotations` will be parsed into json string and sent to `AlertManager`: -``` +```json { "labels": { "alertname": "", @@ -600,41 +603,41 @@ AlertManagerEvent(String alertname, Map extraLabels, Map extraLabels = new HashMap<>(); +final HashMap extraLabels = new HashMap<>(); extraLabels.put("severity", "critical"); extraLabels.put("series", "root.ln.wt01.wf01.temperature"); extraLabels.put("value", String.valueOf(100.0)); @@ -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 extraLabels = new HashMap<>(); +final HashMap extraLabels = new HashMap<>(); extraLabels.put("severity", "critical"); extraLabels.put("series", "root.ln.wt01.wf01.temperature"); extraLabels.put("value", String.valueOf(100.0)); -HashMap annotations = new HashMap<>(); +final HashMap 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**. diff --git a/docs/zh/UserGuide/Advanced-Features/Alerting.md b/docs/zh/UserGuide/Advanced-Features/Alerting.md index 97c94b59b28f..356645f6d398 100644 --- a/docs/zh/UserGuide/Advanced-Features/Alerting.md +++ b/docs/zh/UserGuide/Advanced-Features/Alerting.md @@ -49,7 +49,7 @@ IoTDB 告警功能预计支持两种模式: 预编译好的二进制文件可在 [这里](https://prometheus.io/download/) 下载。 运行方法: -```` +````shell ./alertmanager --config.file= ```` @@ -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 ```` @@ -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 @@ -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); @@ -376,5 +376,3 @@ INSERT INTO root.ln.wf01.wt01(timestamp, temperature) VALUES (5, 120); - - diff --git a/docs/zh/UserGuide/Advanced-Features/Triggers.md b/docs/zh/UserGuide/Advanced-Features/Triggers.md index 637bc3b8bf83..be66f8294538 100644 --- a/docs/zh/UserGuide/Advanced-Features/Triggers.md +++ b/docs/zh/UserGuide/Advanced-Features/Triggers.md @@ -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 extraLabels); AlertManagerEvent(String alertname, Map extraLabels, Map annotations); @@ -604,7 +606,7 @@ AlertManagerEvent(String alertname, Map extraLabels, Map}}`, `{{.}}` 在最终生成消息时会被替换为 `labels[]`。 * `labels` 和 `annotations` 会被解析成 json 字符串发送给 `AlertManager`: -``` +```json { "labels": { "alertname": "", @@ -617,41 +619,41 @@ AlertManagerEvent(String alertname, Map extraLabels, Map extraLabels = new HashMap<>(); +final HashMap extraLabels = new HashMap<>(); extraLabels.put("severity", "critical"); extraLabels.put("series", "root.ln.wt01.wf01.temperature"); extraLabels.put("value", String.valueOf(100.0)); @@ -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 extraLabels = new HashMap<>(); +final HashMap extraLabels = new HashMap<>(); extraLabels.put("severity", "critical"); extraLabels.put("series", "root.ln.wt01.wf01.temperature"); extraLabels.put("value", String.valueOf(100.0)); -HashMap annotations = new HashMap<>(); +final HashMap 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)); ```