monitor.check() 函数
monitor.check() 检查输入数据并根据谓词函数为每行分配一个级别 (ok, info, warn, 或 crit)。
monitor.check() 将状态存储在 _level 列中,并将结果写入 statuses 度量值在 _monitoring 桶中。
函数类型签名
(
<-tables: stream[J],
data: {A with tags: E, _type: D, _check_name: C, _check_id: B},
messageFn: (
r: {
F with
_type: D,
_time: H,
_time: time,
_source_timestamp: int,
_source_measurement: G,
_measurement: G,
_measurement: string,
_level: string,
_check_name: C,
_check_id: B,
},
) => I,
?crit: (r: {F with _time: H, _measurement: G}) => bool,
?info: (r: {F with _time: H, _measurement: G}) => bool,
?ok: (r: {F with _time: H, _measurement: G}) => bool,
?warn: (r: {F with _time: H, _measurement: G}) => bool,
) => stream[{
F with
_type: D,
_time: H,
_time: time,
_source_timestamp: int,
_source_measurement: G,
_message: I,
_measurement: G,
_measurement: string,
_level: string,
_check_name: C,
_check_id: B,
}] where E: Record, J: Record
有关更多信息,请参见 Function type signatures。
参数
危害
确定crit状态的谓词函数。默认为(r) => false。
警告
谓词函数,用于确定 warn 状态。默认值为 (r) => false。
信息
谓词函数,用于确定 info 状态。默认值为 (r) => false。
好的
确定ok状态的谓词函数。默认是 (r) => true.
消息函数
(必填) 谓词函数,用于构造要附加到每行的消息。
消息存储在 _message 列中。
数据
(必需) 检查要附加到输出的数据,以用于识别此检查。
这些数据指定了与发送的通知相关联的通知规则和通知端点。 数据记录必须包含以下属性:
- _check_id: 检查 ID (string)
- _check_name: 检查名称 (string)
- _type: 检查类型(阈值,死人的,或自定义) (string)
- 标签: 自定义标签以附加到输出行 (记录)
InfluxDB 监控和警报系统使用
monitor.check()来 检查状态并自动分配这些值。 如果编写自定义检查任务,我们建议使用 唯一任意 值作为数据记录属性。
表格
输入数据。默认是管道转发数据 (<-).
示例
通过Telegraf监控InfluxDB磁盘使用情况
import "influxdata/influxdb/monitor"
from(bucket: "telegraf")
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "disk" and r._field == "used_percent")
|> monitor.check(
crit: (r) => r._value > 90.0,
warn: (r) => r._value > 80.0,
info: (r) => r._value > 70.0,
ok: (r) => r._value <= 60.0,
messageFn: (r) =>
if r._level == "crit" then
"Critical alert!! Disk usage is at ${r._value}%!"
else if r._level == "warn" then
"Warning! Disk usage is at ${r._value}%."
else if r._level == "info" then
"Disk usage is at ${r._value}%."
else
"Things are looking good.",
data: {
_check_name: "Disk Utilization (Used Percentage)",
_check_id: "disk_used_percent",
_type: "threshold",
tags: {},
},
)