BatchNode
batch
节点处理多个子 QueryNode 或 QueryFluxNode 的创建。每次调用 query
或 queryFlux
都会创建一个可以进一步配置的子批处理节点。请参阅 QueryNode 和 QueryFluxNode。 批处理任务中的 batch
变量是 BatchNode 的一个实例。
使用 BatchNode 时,需要 QueryNode 或 QueryFluxNode。它们定义了批处理数据的源和计划,并且应在任何其他 链式方法 (chaining methods) 之前使用。
示例 (Examples)
var errors = batch
|query('SELECT value from errors')
...
var views = batch
|query('SELECT value from views')
...
var errors = batch
|queryFlux('''
from(bucket: "example-bucket")
|> range(start: -1m)
|> filter(fn: (r) => r._measurement == "errors")
''')
...
var views = batch
|queryFlux('''
from(bucket: "example-bucket")
|> range(start: -1m)
|> filter(fn: (r) => r._measurement == "views")
''')
...
可用统计信息 (Available Statistics)
- query_errors: 查询时出错的次数 (number of errors when querying)
- batches_queried: 从查询返回的批次数 (number of batches returned from queries)
- points_queried: 批次中的点总数 (total number of points in batches)
构造函数 (Constructor)
链式方法 (Chaining Method) | 描述 (Description) |
---|---|
batch | 没有构造函数签名 (Has no constructor signature)。 |
属性方法 (Property Methods)
设置器 (Setters) | 描述 (Description) |
---|---|
quiet ( ) | 禁止来自此节点的所有错误日志记录事件 (Suppress all error logging events from this node)。 |
链式方法 (Chaining Methods)
Deadman, Query, FluxQuery, Stats
属性 (Properties)
属性方法修改调用节点上的状态。它们不会向管道添加另一个节点,并且始终返回对调用节点的引用。属性方法使用 .
运算符标记。
Quiet
禁止来自此节点的所有错误日志记录事件 (Suppress all error logging events from this node)。
batch.quiet()
链式方法 (Chaining Methods)
链式方法在管道中创建一个新节点作为调用节点的子节点。它们不会修改调用节点。链式方法使用 |
运算符标记。
Deadman
用于在低吞吐量(又名“deadman’s switch”)上创建告警的辅助函数 (Helper function for creating an alert on low throughput, a.k.a. deadman’s switch)。
- 阈值 (Threshold):如果吞吐量降至低于阈值(点/间隔)则触发告警 (trigger alert if throughput drops below threshold in points/interval)。
- 间隔 (Interval):检查吞吐量的频率 (how often to check the throughput)。
- 表达式 (Expressions):也要评估的可选表达式列表 (optional list of expressions to also evaluate)。用于一天中的时间告警 (Useful for time of day alerting)。
示例 (Example)
var data = batch
|query()...
// Trigger critical alert if the throughput drops below 100 points per 10s and checked every 10s.
data
|deadman(100.0, 10s)
//Do normal processing of data
data...
以上示例等效于此示例 (The above is equivalent to this example)
var data = batch
|query()...
// Trigger critical alert if the throughput drops below 100 points per 10s and checked every 10s.
data
|stats(10s)
.align()
|derivative('emitted')
.unit(10s)
.nonNegative()
|alert()
.id('node \'stream0\' in task \'{{ .TaskName }}\'')
.message('{{ .ID }} is {{ if eq .Level "OK" }}alive{{ else }}dead{{ end }}: {{ index .Fields "emitted" | printf "%0.3f" }} points/10s.')
.crit(lambda: "emitted" <= 100.0)
//Do normal processing of data
data...
id
和 message
告警属性可以通过 ‘deadman’ 配置部分全局配置 (can be configured globally via the ‘deadman’ configuration section)。
由于 AlertNode 是最后一部分,因此可以像往常一样进一步修改 (can be further modified as usual)。示例 (Example)
var data = batch
|query()...
// Trigger critical alert if the throughput drops below 100 points per 10s and checked every 10s.
data
|deadman(100.0, 10s)
.slack()
.channel('#dead_tasks')
//Do normal processing of data
data...
您可以指定其他 lambda 表达式以进一步约束何时触发“deadman’s switch”。示例 (Example)
var data = batch
|query()...
// Trigger critical alert if the throughput drops below 100 points per 10s and checked every 10s.
// Only trigger the alert if the time of day is between 8am-5pm.
data
|deadman(100.0, 10s, lambda: hour("time") >= 8 AND hour("time") <= 17)
//Do normal processing of data
data...
batch|deadman(threshold float64, interval time.Duration, expr ...ast.LambdaNode)
返回值 (Returns):AlertNode
Query
要执行的查询。WHERE
子句中不得包含时间条件,也不得包含 GROUP BY
子句。时间条件根据周期、偏移和计划动态添加。GROUP BY
子句根据传递给 groupBy
方法的维度动态添加。
batch|query(q string)
返回值 (Returns):QueryNode
QueryFlux
要执行的 Flux 查询 (The Flux query to execute)。
batch|QueryFlux(queryStr string)
返回值 (Returns):QueryFluxNode
Stats
创建一个新的数据流,其中包含节点的内部统计信息 (Create a new stream of data that contains the internal statistics of the node)。间隔表示基于实时发出统计信息的频率 (The interval represents how often to emit the statistics based on real time)。这意味着间隔时间独立于源节点正在接收的数据点的时间 (This means the interval time is independent of the times of the data points the source node is receiving)。
batch|stats(interval time.Duration)
返回值 (Returns):StatsNode
此页是否对您有帮助? (Was this page helpful?)
感谢您的反馈! (Thank you for your feedback!)
支持和反馈 (Support and feedback)
感谢您成为我们社区的一份子!我们欢迎并鼓励您提供关于 Kapacitor 和此文档的反馈和错误报告 (We welcome and encourage your feedback and bug reports for Kapacitor and this documentation)。要获得支持,请使用以下资源 (To find support, use the following resources)