Bosun:当需要字符串时,查找给出整数

Bosun: Lookup is giving integer when string is expected

我正在调整我的 bosun.conf 以允许我的 os.cpu.high 警报在根据主机确定要使用的持续时间时使用查找:

lookup high_cpu {

    entry host=* {
        time = 5m
    }
    entry host=*graylog* {
        time = 1h
    }
}

alert os.cpu.high {
    template = generic.graph
    macro = host.based.contacts
    $notes = Find CPU usage that is continually high
    $duration = lookup("high_cpu", "time")
    $host = *
    $metric = "sum:rate{counter,,1}:os.cpu{host=$host}"
    $q_cpu = q($metric, "$duration", "")
    $q = avg($q_cpu)

    warn = $q > 95
    crit = $q > 99

    ignoreUnknown = true
    $q_format = %f
    $unit_string = %
    $generic_graph = $q_cpu
    $graph_unit = %
}

这是我在测试时得到的错误:

conf: Test Config:424:4: at <warn = $q > 95>: expr: unexpected "high" in func

我对 bosun 不是很熟悉,这可能是一个简单的解决方法,但我已经无计可施了。任何帮助将不胜感激

您不能这样做,因为查找不支持字符串 return 类型。

这种特殊情况无论如何都会有问题,因为您尝试做的是根据查询结果查询不同的次数,所以您遇到了先有鸡还是先有蛋的问题。

您可以做的是查询您要查询的最大时间量,然后使用 crop 函数缩短集合中的一些结果。但是裁剪功能还没有发布,所以你必须在 master 中获得它。您现在可以在 this commit 中查看包含您正在尝试执行的操作示例的文档,即:

lookup test {
    entry host=ny-bosun01 {
        start = 30
    }
    entry host=* {
        start = 60
    }
}

alert test {
    template = test
    $q = q("avg:rate:os.cpu{host=ny-bosun*}", "5m", "")
    $c = crop($q, lookup("test", "start") , 0)
    crit = avg($c)
}