monitor.check() 函数
monitor.check()
检查输入数据,并根据谓词函数为每一行分配一个级别(ok
、info
、warn
或 crit
)。
monitor.check()
将状态存储在 _level
列中,并将结果写入 _monitoring
bucket 中的 statuses
measurement。
函数类型签名
(
<-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
有关更多信息,请参阅 函数类型签名。
参数
crit
确定 crit
状态的谓词函数。默认为 (r) => false
。
warn
确定 warn
状态的谓词函数。默认为 (r) => false
。
info
确定 info
状态的谓词函数。默认为 (r) => false
。
ok
确定 ok
状态的谓词函数。默认为 (r) => true
。
messageFn
(必需) 构造要附加到每一行的消息的谓词函数。
消息存储在 _message
列中。
data
(必需) 检查要附加到用于标识此检查的输出的数据。
此数据指定要与发送的通知关联的通知规则和通知端点。数据记录必须包含以下属性
- _check_id: 检查 ID (字符串)
- _check_name: 检查名称 (字符串)
- _type: 检查类型(阈值、deadman 或自定义) (字符串)
- tags: 要附加到输出行的自定义标签 (记录) InfluxDB 监控和警报系统使用
monitor.check()
来检查状态并自动分配这些值。如果编写自定义检查任务,我们建议为数据记录属性使用唯一的任意值。
tables
输入数据。默认为管道转发数据 (<-
)。
示例
监控 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: {},
},
)
此页面是否对您有帮助?
感谢您的反馈!