greptimedb-trigger

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GreptimeDB Trigger Guide

GreptimeDB 触发器指南

Create GreptimeDB trigger definition as an alternative to Prometheus alerting rule. GreptimeDB trigger maps most concepts from Prometheus alert rules in its own DDL.
创建GreptimeDB触发器定义,作为Prometheus告警规则的替代方案。GreptimeDB触发器在其DDL中映射了Prometheus告警规则的大部分概念。

The workflow

工作流程

To create Greptime trigger, we should follow these phases:
要创建Greptime触发器,需遵循以下阶段:

Phase 1. Understanding GreptimeDB Trigger

阶段1. 了解GreptimeDB触发器

First, we should read greptimedb trigger definitions and how it works from GreptimeDB's documentation.
There are pages available, use WebFetch to load and understand them:
  1. High level information of Trigger https://docs.greptime.com/enterprise/trigger/
  2. The trigger syntax reference https://docs.greptime.com/reference/sql/trigger-syntax/
首先,我们需要从GreptimeDB的文档中读取触发器定义及其工作原理。
可通过WebFetch加载以下相关页面进行了解:
  1. 触发器的高级信息 https://docs.greptime.com/enterprise/trigger/
  2. 触发器语法参考 https://docs.greptime.com/reference/sql/trigger-syntax/

Phase 2. Create an initial trigger

阶段2. 创建初始触发器

Create the trigger based on user provided information.
Note that
CREATE TRIGGER
can also use Greptime TQL to define the rule. The TQL is Greptime's embedded PromQL in SQL, so using TQL makes migration from Prometheus alert rules easier.
In most case, the query in trigger should use aggregation and
GROUP BY
for time-series and time window. This is like using SQL to simulate PromQL behaviour. If possible, we can use PromQL as TQL to simplify the query.
It can be either existing Prometheus alerting rule yaml, or detailed requirements described by user.
Return the
CREATE TRIGGER
SQL statement, with some dummy data for the webhook part if user didn't provide webhook information.
根据用户提供的信息创建触发器。
注意,
CREATE TRIGGER
也可以使用Greptime TQL来定义规则。TQL是Greptime在SQL中嵌入的PromQL,因此使用TQL可简化从Prometheus告警规则的迁移过程。
大多数情况下,触发器中的查询应针对时间序列和时间窗口使用聚合函数与
GROUP BY
。这类似于用SQL模拟PromQL的行为。如果可能,我们可以使用PromQL作为TQL来简化查询。
用户提供的信息可以是现有的Prometheus告警规则yaml文件,或是用户描述的详细需求。
返回
CREATE TRIGGER
SQL语句,若用户未提供webhook相关信息,则在webhook部分使用一些模拟数据。

Phase 3. Configure webhook for trigger

阶段3. 为触发器配置webhook

If the user already has a Prometheus Alertmanager setup, use their Alertmanager information for webhook.
如果用户已搭建Prometheus Alertmanager,可使用其Alertmanager信息来配置webhook。

Reference

参考资料

Prometheus Alertmanager

Prometheus Alertmanager

Alertmanager is typically configured in
prometheus.yml
like this
yaml
...
Alertmanager通常在
prometheus.yml
中配置,示例如下:
yaml
...

Alerting specifies settings related to the Alertmanager

Alerting specifies settings related to the Alertmanager

alerting: alertmanagers: - static_configs: - targets: # Alertmanager's default port is 9093 - localhost:9093

We can use the target for our webhook destination.
alerting: alertmanagers: - static_configs: - targets: # Alertmanager's default port is 9093 - localhost:9093

我们可以将该目标作为webhook的目的地。

Step-by-step guide

分步指南

Greptime TQL

Greptime TQL