-
Notifications
You must be signed in to change notification settings - Fork 50
docs: trigger overview and quick start #1994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
916f999
docs: trigger overview
fengys1996 7d0cfc2
chore: add trigger in sidebars.ts
fengys1996 ebc850b
fix: ci
fengys1996 bdaa8a2
fix: ci
fengys1996 c049f39
docs: restructure trigger documentation
fengys1996 b9df40d
fix: sidebars
fengys1996 3081d6d
chore: add link for trigger in enterprise/overview
fengys1996 e4c969d
fix: code review
fengys1996 758dca2
fix: code review
fengys1996 e142517
add config link about alertmanager
fengys1996 215236d
fix: cr
fengys1996 de5de62
fix: picture
fengys1996 3c42b05
also fix in i18n
fengys1996 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| keywords: [Trigger, GreptimeDB Enterprise, SQL, Webhook] | ||
| description: The overview of GreptimeDB Trigger. | ||
| --- | ||
|
|
||
| # Trigger | ||
|
|
||
| Trigger allows you to define evaluation rules with SQL. | ||
| GreptimeDB evaluates these rules periodically; once the condition is met, a | ||
| notification is sent out. | ||
|
|
||
| - [Quick Start Example](./quick-start.md): A step-by-step guide to set up a | ||
| Trigger that monitors system load and raises alerts. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| --- | ||
| keywords: [Trigger, Alert, GreptimeDB Enterprise, SQL, Webhook, Alertmanager, Slack] | ||
| description: This guide demonstrates how GreptimeDB Triggers enable seamless integration with the Prometheus Alertmanager ecosystem for comprehensive monitoring and alerting. | ||
| --- | ||
|
|
||
| # Quick Start Example | ||
|
|
||
| This section walks through an end-to-end example that uses Trigger to monitor | ||
| system load and raise an alert. | ||
|
|
||
| The diagram illustrates the complete end-to-end workflow of the example. | ||
|
|
||
|  | ||
|
|
||
| 1. Vector continuously scrapes host metrics and writes them to GreptimeDB. | ||
| 2. A Trigger in GreptimeDB evaluates a rule every minute; whenever the condition | ||
| is met, it sends a notification to Alertmanager. | ||
| 3. Alertmanager applies its own policies and finally delivers the alert to Slack. | ||
|
|
||
| ## Use Vector to Scrape Host Metrics | ||
|
|
||
| Use Vector to scrape host metrics and write it to GreptimeDB. Below is a Vector | ||
| configuration example: | ||
|
|
||
| ```toml | ||
| [sources.in] | ||
| type = "host_metrics" | ||
| scrape_interval_secs = 15 | ||
|
|
||
| [sinks.out] | ||
| inputs = ["in"] | ||
| type = "greptimedb" | ||
| endpoint = "localhost:4001" | ||
| ``` | ||
|
|
||
| GreptimeDB auto-creates tables on the first write. The `host_load1` table stores | ||
| the system load averaged over the last minute. It is a key performance indicator | ||
| for measuring system activity. We can create a monitoring rule to track values | ||
| in this table. The schema of this table is shown below: | ||
|
|
||
| ```sql | ||
| +-----------+----------------------+------+------+---------+---------------+ | ||
| | Column | Type | Key | Null | Default | Semantic Type | | ||
| +-----------+----------------------+------+------+---------+---------------+ | ||
| | ts | TimestampMillisecond | PRI | NO | | TIMESTAMP | | ||
| | collector | String | PRI | YES | | TAG | | ||
| | host | String | PRI | YES | | TAG | | ||
| | val | Float64 | | YES | | FIELD | | ||
| +-----------+----------------------+------+------+---------+---------------+ | ||
| ``` | ||
|
|
||
| ## Set up Alertmanager with a Slack Receiver | ||
|
|
||
| The payload of GreptimeDB Trigger's Webhook is compatible with [Prometheus | ||
| Alertmanager](https://prometheus.io/docs/alerting/latest/alertmanager/), so we | ||
| can reuse Alertmanager’s grouping, inhibition, silencing and routing features | ||
| without any extra glue code. | ||
|
|
||
| You can refer to the [official documentation](https://prometheus.io/docs/alerting/latest/configuration/) | ||
| to configure Prometheus Alertmanager. Below is a minimal message template you | ||
| can use: | ||
|
|
||
| ```text | ||
| {{ define "slack.text" }} | ||
| {{ range .Alerts }} | ||
|
|
||
| Labels: | ||
| {{- range .Labels.SortedPairs }} | ||
| - {{ .Name }}: {{ .Value }} | ||
| {{ end }} | ||
|
|
||
| Annotations: | ||
| {{- range .Annotations.SortedPairs }} | ||
| - {{ .Name }}: {{ .Value }} | ||
| {{ end }} | ||
|
|
||
| {{ end }} | ||
| {{ end }} | ||
| ``` | ||
|
|
||
fengys1996 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Generating a Slack message using the above template will iterate over all alerts | ||
| and display the labels and annotations for each alert. | ||
|
|
||
| Start Alertmanager once the configuration is ready. | ||
|
|
||
fengys1996 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Create Trigger | ||
|
|
||
fengys1996 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Connect to GreptimeDB with MySql client and run the following SQL: | ||
|
|
||
| ```sql | ||
| CREATE TRIGGER IF NOT EXISTS load1_monitor | ||
| ON ( | ||
| SELECT collector AS label_collector, | ||
| host as label_host, | ||
| val | ||
| FROM host_load1 WHERE val > 10 and ts >= now() - '1 minutes'::INTERVAL | ||
| ) EVERY '1 minute'::INTERVAL | ||
| LABELS (severity=warning) | ||
| ANNOTATIONS (comment='Your computer is smoking, should take a break.') | ||
| NOTIFY( | ||
| WEBHOOK alert_manager URL 'http://localhost:9093' WITH (timeout="1m") | ||
| ); | ||
| ``` | ||
|
|
||
| The above SQL will create a trigger named `load1_monitor` that runs every minute. | ||
| It evaluates the last 60 seconds of data in `host_load1`; if any load1 value | ||
| exceeds 10, the `WEBHOOK` option in the `NOTIFY` syntax specifies that this | ||
| trigger will send a notification to Alertmanager which running on localhost with | ||
| port 9093. | ||
|
|
||
| You can execute `SHOW TRIGGERS` to view the list of created Triggers. | ||
|
|
||
| ```sql | ||
| SHOW TRIGGERS; | ||
| ``` | ||
|
|
||
| The output should look like this: | ||
|
|
||
| ```text | ||
| +---------------+ | ||
| | Triggers | | ||
| +---------------+ | ||
| | load1_monitor | | ||
| +---------------+ | ||
| ``` | ||
|
|
||
| ## Test Trigger | ||
|
|
||
| Use [stress-ng](https://github.com/ColinIanKing/stress-ng) to simulate high CPU | ||
| load for 60s: | ||
|
|
||
| ```bash | ||
| stress-ng --cpu 100 --cpu-load 10 --timeout 60 | ||
| ``` | ||
|
|
||
| The load1 will rise quickly, the Trigger notification will fire, and within a | ||
| minute Slack channel will receive an alert like: | ||
|
|
||
|  | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
i18n/zh/docusaurus-plugin-content-docs/current/enterprise/trigger/overview.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| keywords: [触发器, 告警, GreptimeDB 企业版, SQL, Webhook] | ||
| description: GreptimeDB 触发器概述。 | ||
| --- | ||
|
|
||
| # Trigger | ||
|
|
||
| Trigger 允许用户基于 SQL 语句定义触发规则,GreptimeDB 根据这些触发规则进行周期性 | ||
| 计算,当满足条件后对外发出通知。 | ||
|
|
||
| - [快读启动示例](./quick-start.md): 手把手教你使用 Trigger, 用于监控系统负载并在 | ||
| 负载过高时触发告警。 |
133 changes: 133 additions & 0 deletions
133
i18n/zh/docusaurus-plugin-content-docs/current/enterprise/trigger/quick-start.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| --- | ||
| keywords: [触发器, 告警, GreptimeDB企业版, SQL, Webhook, Alertmanager, Slack] | ||
| description: 本指南演示GreptimeDB触发器如何与Prometheus Alertmanager生态系统无缝集成,实现监控和告警功能。 | ||
| --- | ||
|
|
||
| ## 快速入门示例 | ||
|
|
||
| 本节将通过一个端到端示例展示如何使用触发器监控系统负载并触发告警。 | ||
|
|
||
| 下图展示了该示例的完整端到端工作流程。 | ||
|
|
||
|  | ||
|
|
||
| 1. Vector 持续采集主机指标并写入 GreptimeDB。 | ||
| 2. GreptimeDB 中的 Trigger 每分钟评估规则;当条件满足时,会向 Alertmanager 发送 | ||
| 通知。 | ||
| 3. Alertmanager 依据自身配置完成告警分组、抑制及路由,最终通过 Slack 集成将消息 | ||
| 发送至指定频道。 | ||
|
|
||
| ## 使用 Vector 采集主机指标 | ||
|
|
||
| 首先,使用 Vector 采集本机的负载数据,并将数据写入 GreptimeDB 中。Vector 的配置 | ||
| 示例如下所示: | ||
|
|
||
| ```toml | ||
| [sources.in] | ||
| type = "host_metrics" | ||
| scrape_interval_secs = 15 | ||
|
|
||
| [sinks.out] | ||
| inputs = ["in"] | ||
| type = "greptimedb" | ||
| endpoint = "localhost:4001" | ||
| ``` | ||
|
|
||
| GreptimeDB 会在数据写入的时候自动创建表,其中,`host_load1`表记录了 load1 数据, | ||
| load1 是衡量系统活动的关键性能指标。我们可以创建监控规则来跟踪此表中的值。表结构 | ||
| 如下所示: | ||
|
|
||
| ```sql | ||
| +-----------+----------------------+------+------+---------+---------------+ | ||
| | Column | Type | Key | Null | Default | Semantic Type | | ||
| +-----------+----------------------+------+------+---------+---------------+ | ||
| | ts | TimestampMillisecond | PRI | NO | | TIMESTAMP | | ||
| | collector | String | PRI | YES | | TAG | | ||
| | host | String | PRI | YES | | TAG | | ||
| | val | Float64 | | YES | | FIELD | | ||
| +-----------+----------------------+------+------+---------+---------------+ | ||
| ``` | ||
|
|
||
| ## 配置 Alertmanager 与 Slack 集成 | ||
|
|
||
| GreptimeDB Trigger 的 Webhook payload 与 [Prometheus Alertmanager](https://prometheus.io/docs/alerting/latest/alertmanager/) | ||
| 兼容,因此我们可以复用 Alertmanager 的分组、抑制、静默和路由功能,而无需任何额外 | ||
| 的胶水代码。 | ||
|
|
||
| 你可以参考 [官方文档](https://prometheus.io/docs/alerting/latest/configuration/) | ||
| 对 Prometheus Alertmanager 进行配置。为在 Slack 消息中呈现一致、易读的内容,可以 | ||
| 配置以下消息模板。 | ||
|
|
||
| ```text | ||
| {{ define "slack.text" }} | ||
| {{ range .Alerts }} | ||
|
|
||
| Labels: | ||
| {{- range .Labels.SortedPairs }} | ||
| - {{ .Name }}: {{ .Value }} | ||
| {{ end }} | ||
|
|
||
| Annotations: | ||
| {{- range .Annotations.SortedPairs }} | ||
| - {{ .Name }}: {{ .Value }} | ||
| {{ end }} | ||
|
|
||
| {{ end }} | ||
| {{ end }} | ||
| ``` | ||
|
|
||
| 使用上述模板生成 slack 消息会遍历所有的告警,并把每个告警的标签和注解展示出来。 | ||
|
|
||
| 当配置完成之后,启动 Alertmanager。 | ||
|
|
||
| ## 创建 Trigger | ||
|
|
||
| 在 GreptimeDB 中创建 Trigger。使用 MySql 客户端连接 GreptimeDB 并执行以下 SQL: | ||
|
|
||
| ```sql | ||
| CREATE TRIGGER IF NOT EXISTS load1_monitor | ||
| ON ( | ||
| SELECT collector AS label_collector, | ||
| host as label_host, | ||
| val | ||
| FROM host_load1 WHERE val > 10 and ts >= now() - '1 minutes'::INTERVAL | ||
| ) EVERY '1 minute'::INTERVAL | ||
| LABELS (severity=warning) | ||
| ANNOTATIONS (comment='Your computer is smoking, should take a break.') | ||
| NOTIFY( | ||
| WEBHOOK alert_manager URL 'http://localhost:9093' WITH (timeout="1m") | ||
| ); | ||
| ``` | ||
|
|
||
| 上述 SQL 将创建一个名为 `load1_monitor` 的触发器,每分钟运行一次。它会评估 `host_load1` | ||
| 表中最近 60 秒的数据;如果任何 load1 值超过 10,则 `NOTIFY` 子句中的 `WEBHOOK` | ||
| 选项会指定 Trigger 向在本地主机上运行且端口为 9093 的 Alertmanager 发送通知。 | ||
|
|
||
| 执行 `SHOW TRIGGERS` 查看已创建的触发器列表。 | ||
|
|
||
| ```sql | ||
| SHOW TRIGGERS; | ||
| ``` | ||
|
|
||
| 输出结果应如下所示: | ||
|
|
||
| ```text | ||
| +---------------+ | ||
| | Triggers | | ||
| +---------------+ | ||
| | load1_monitor | | ||
| +---------------+ | ||
| ``` | ||
|
|
||
| ## 测试 Trigger | ||
|
|
||
| 使用 [stress-ng](https://github.com/ColinIanKing/stress-ng) 模拟 60 秒的高 CPU 负载: | ||
|
|
||
| ```bash | ||
| stress-ng --cpu 100 --cpu-load 10 --timeout 60 | ||
| ``` | ||
|
|
||
| load1 值将快速上升,Trigger 通知将被触发,在一分钟之内,指定的 Slack 频道将收到如下 | ||
| 告警: | ||
|
|
||
|  |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.