pushgateway或节点导出器 - 如何添加字符串数据?

时间:2017-10-27 15:03:07

标签: sql cron prometheus

我有一个每天运行sql查询的cron作业,并给我一个重要的整数。

我必须将该整数暴露给Prometheus服务器。

正如我所见,我有两种选择;使用 pushgateway 节点导出程序

但是我从sql查询获得的度量(整数)也需要一些信息(比如公司名称,以及我从中获取的数据库)。

什么是更好的方式?

例如,这就是我为我的指标所做的:

    count = some number

    registry = CollectorRegistry()
    g = Gauge('machine_number', 'machfoobarine_stat', registry=registry).set(count)
    push_to_gateway('localhost:9091', job='batchA', registry=registry)

那么如何在上面的指标中添加键值对? 我是否必须为每个sql计数更改作业名称('batchA')并将其作为指标公开到pushgateway,因为我只能看到最后一个?

TNX, 汤姆

1 个答案:

答案 0 :(得分:1)

最好的方法是为您的指标设置一般名称,例如animal_count,然后使用label对其进行专门化。这是一个伪代码:

g = Gauge.build("animal_count", "Number of animal in zoo")
    .labelsName("sex", "classes")
    .create();

g.labels("male", "mammals")
    .set(count);