文档文档

monitor.notify() 函数

monitor.notify() 向端点发送通知,并将其记录在 _monitoring Bucket 的 notifications 测量中。

函数类型签名
(
    <-tables: stream[E],
    data: A,
    endpoint: (<-: stream[{B with _time: C, _time: time, _status_timestamp: int, _measurement: string}]) => stream[D],
) => stream[D] where A: Record, D: Record, E: Record

有关更多信息,请参阅 函数类型签名

参数

endpoint

必需)一个函数,用于构造通知并将其发送到端点。

data

必需)要附加到输出的通知数据。

此数据指定要与发送的通知关联的通知规则和通知端点。数据记录必须包含以下属性

  • _notification_rule_id
  • _notification_rule_name
  • _notification_endpoint_id
  • _notification_endpoint_name InfluxDB 监控和警报系统使用 monitor.notify() 来存储有关已发送通知的信息,并自动分配这些值。如果编写自定义通知任务,我们建议为数据记录属性使用唯一的任意值。

tables

输入数据。默认值为管道转发数据 (<-)。

示例

向 Slack 发送严重状态通知

import "influxdata/influxdb/monitor"
import "influxdata/influxdb/secrets"
import "slack"

token = secrets.get(key: "SLACK_TOKEN")

endpoint =
    slack.endpoint(token: token)(
        mapFn: (r) => ({channel: "Alerts", text: r._message, color: "danger"}),
    )

notification_data = {
    _notification_rule_id: "0000000000000001",
    _notification_rule_name: "example-rule-name",
    _notification_endpoint_id: "0000000000000002",
    _notification_endpoint_name: "example-endpoint-name",
}

monitor.from(range: -5m, fn: (r) => r._level == "crit")
    |> range(start: -5m)
    |> monitor.notify(endpoint: endpoint, data: notification_data)

此页对您有帮助吗?

感谢您的反馈!


Flux 的未来

Flux 即将进入维护模式。您可以继续像现在一样使用它,而无需对代码进行任何更改。

阅读更多

现已全面上市

InfluxDB 3 Core 和 Enterprise

快速启动。更快扩展。

获取更新

InfluxDB 3 Core 是一个开源、高速、最近数据引擎,可实时收集和处理数据,并将其持久化到本地磁盘或对象存储。InfluxDB 3 Enterprise 构建在 Core 的基础上,增加了高可用性、只读副本、增强的安全性以及数据压缩,以实现更快的查询和优化的存储。InfluxDB 3 Enterprise 的免费层可供非商业家庭或业余爱好者使用。

有关更多信息,请查看