-
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 6 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
| 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 users 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,133 @@ | ||
| --- | ||
| 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 | ||
|
|
||
| ## Overview | ||
fengys1996 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This section walks through a 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 it to GreptimeDB. | ||
fengys1996 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 2. A Trigger in GreptimeDB evaluates the rule `load1 > 10` every minute; whenever | ||
fengys1996 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| the condition is met, it sends a notification to Alertmanager. | ||
| 3. Alertmanager applies its own policies and finally delivers the alert to Slack. | ||
|
|
||
| > The payload of GreptimeDB Trigger's Webhook is compatible with Prometheus | ||
fengys1996 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Alertmanager, so we can reuse Alertmanager’s grouping, inhibition, silencing and | ||
| routing features without any extra glue code. | ||
|
|
||
| ## Prerequisites | ||
fengys1996 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Use Vector to scrapes 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 resulting `host_load1` | ||
| table stores the load1 metrics; its schema is shown below: | ||
fengys1996 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```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 | | ||
| +-----------+----------------------+------+------+---------+---------------+ | ||
| ``` | ||
|
|
||
| > "load1" refers to the load average of the Linux system over the past minute. | ||
fengys1996 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| It is one of the key performance indicators for measuring how busy the system is. | ||
|
|
||
| Set up Alertmanager with a Slack receiver. Below is a minimal message template | ||
| you can use: | ||
fengys1996 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```text | ||
| {{ define "slack.text" }} | ||
|
|
||
| Alert: {{ .CommonLabels.alertname }} (Status: {{ .CommonLabels.status }}) | ||
| Severity: {{ .CommonLabels.severity }} | ||
|
|
||
| Annotations: | ||
| {{ range .CommonAnnotations.SortedPairs }} | ||
| - {{ .Name }}: {{ .Value }} | ||
| {{ end }} | ||
|
|
||
| Labels: | ||
| {{ range .CommonLabels.SortedPairs }} | ||
| - {{ .Name }}: {{ .Value }} | ||
| {{ end }} | ||
|
|
||
| {{ end }} | ||
| ``` | ||
|
|
||
fengys1996 marked this conversation as resolved.
Show resolved
Hide resolved
fengys1996 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Start Alertmanager once the configuration is ready. | ||
|
|
||
fengys1996 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Demo | ||
fengys1996 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
fengys1996 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Create the Trigger in GreptimeDB. | ||
| 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://127.0.0.1localhost: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, it sends a notification to Alertmanager. | ||
fengys1996 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Execute `SHOW TRIGGERS` to view the list of created Triggers. | ||
fengys1996 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```sql | ||
| SHOW TRIGGERS; | ||
| ``` | ||
|
|
||
| The output should look like this: | ||
|
|
||
| ```text | ||
| +---------------+ | ||
| | Triggers | | ||
| +---------------+ | ||
| | load1_monitor | | ||
| +---------------+ | ||
| ``` | ||
|
|
||
| Use stress-ng to simulate high CPU load for 60 s: | ||
fengys1996 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```bash | ||
| stress-ng --cpu 100 --cpu-load 10 --timeout 60 | ||
| ``` | ||
|
|
||
| The load1 will rise quickly, the notify of Trigger will fire, and within a minute | ||
| Slack channel will receive an alert like: | ||
|
|
||
|  | ||
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, 用于监控系统负载并在 | ||
| 负载过高时触发告警。 |
131 changes: 131 additions & 0 deletions
131
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,131 @@ | ||
| --- | ||
| keywords: [触发器, 告警, GreptimeDB企业版, SQL, Webhook, Alertmanager, Slack] | ||
| description: 本指南演示GreptimeDB触发器如何与Prometheus Alertmanager生态系统无缝集成,实现监控和告警功能。 | ||
| --- | ||
|
|
||
| ## 快速入门示例 | ||
|
|
||
| ## 概述 | ||
|
|
||
| 本节将通过一个端到端示例展示如何使用触发器监控系统负载并触发告警。 | ||
|
|
||
| 下图展示了该示例的完整端到端工作流程。 | ||
|
|
||
|  | ||
|
|
||
| 1. Vector 持续采集主机指标并写入GreptimeDB。 | ||
| 2. GreptimeDB 中的 Trigger 每分钟评估规则`load1 > 10`;当条件满足时,会向 Alertmanager | ||
| 发送通知。 | ||
| 3. Alertmanager 依据自身配置完成告警分组、抑制及路由,最终通过 Slack 集成将消息 | ||
| 发送至指定频道。 | ||
|
|
||
|
|
||
| > GreptimeDB 的 Webhook 输出格式与 Prometheus Alertmanager 完全兼容,可以直接接 | ||
| 入 Alertmanager 生态。 | ||
|
|
||
| ## 前置工作 | ||
|
|
||
| 首先,使用 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 数据, | ||
| 表结构如下所示: | ||
|
|
||
| ```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 | | ||
| +-----------+----------------------+------+------+---------+---------------+ | ||
| ``` | ||
|
|
||
| > “load1” 指的是 Linux 系统中过去 1 分钟的平均负载(load average),它是衡量系统 | ||
| 繁忙程度的关键性能指标之一。 | ||
|
|
||
| 配置 Alertmanager 的 Slack Receiver 的具体过程不在此赘述。为在 Slack 消息中呈现 | ||
| 一致、易读的内容,可以配置以下模板。 | ||
|
|
||
| ```text | ||
| {{ define "slack.text" }} | ||
|
|
||
| Alert: {{ .CommonLabels.alertname }} (Status: {{ .CommonLabels.status }}) | ||
| Severity: {{ .CommonLabels.severity }} | ||
|
|
||
| Annotations: | ||
| {{ range .CommonAnnotations.SortedPairs }} | ||
| - {{ .Name }}: {{ .Value }} | ||
| {{ end }} | ||
|
|
||
| Labels: | ||
| {{ range .CommonLabels.SortedPairs }} | ||
| - {{ .Name }}: {{ .Value }} | ||
| {{ end }} | ||
|
|
||
| {{ end }} | ||
| ``` | ||
|
|
||
| 当配置完成之后,启动 Alertmanager。 | ||
|
|
||
| ## 演示示例 | ||
|
|
||
| 在 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://127.0.0.1localhost:9093' WITH (timeout="1m") | ||
| ); | ||
| ``` | ||
|
|
||
| 上述SQL将创建一个名为`load1_monitor`的触发器,每分钟运行一次。它会评估 `host_load1` | ||
fengys1996 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 表中最近 60 秒的数据;如果任何 load1 值超过10,就会触发 GreptimeDB 向 Alertmanager | ||
fengys1996 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 发送通知。 | ||
|
|
||
| 执行`SHOW TRIGGERS`查看已创建的触发器列表。 | ||
|
|
||
| ```sql | ||
| SHOW TRIGGERS; | ||
| ``` | ||
|
|
||
| 输出结果应如下所示: | ||
|
|
||
| ```text | ||
| +---------------+ | ||
| | Triggers | | ||
| +---------------+ | ||
| | load1_monitor | | ||
| +---------------+ | ||
| ``` | ||
|
|
||
| 使用 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.