var db = 'telegraf' var rp = 'autogen' var name = 'booboo' var idName = name + 'wei' var query = '''select host from telegraf.autogen where cpu='total' '''
整数声明
var int_num = 1
浮点型声明
var float_num = 1.1
持续时间声明
var period = 5m
字符串列表
var cpu_groups = [ 'host', 'cpu' ]
正则表达式声明
var cz_turbines = /^cz\d+/ var adr_senegal = /\.sn$/ var local_ips = /^192\.168\..*/ var locals = lambda: "192.168.1.1" =~ local_ips
lambda表达式声明
Lambda表达式始终对点数据进行操作;
它可以包装布尔表达式,数学表达式,对内部函数的调用或这三者的组合
var my_lambda = lambda: 1 > 0 var lazy_lambda = lambda: "usage_idle" < 95 ... var data = stream |from() ... var alert = data |eval(lambda: sigma("stat")) .as('sigma') .keep() |alert() .id('{{ index .Tags "host"}}/cpu_used') .message('{{ .ID }}:{{ index .Fields "stat" }}') .info(lambda: "stat" > 70OR"sigma" > 2.5) .warn(lambda: "stat" > 80OR"sigma" > 3.0) .crit(lambda: "stat" > 90OR"sigma" > 3.5)
节点声明
节点表达式:
var data = stream |from() .database('telegraf') .retentionPolicy('autogen') .measurement('cpu') .groupBy('host') .where(lambda: "cpu" == 'cpu-total') |eval(lambda: 100.0 - "usage_idle") .as('used') |window() .period(span) .every(frequency) |mean('used') .as('stat') ... var alert = data |eval(lambda: sigma("stat")) .as('sigma') .keep() |alert() .id('{{ index .Tags "host"}}/cpu_used') ...