node_exporter使用textfile collector收集业务数据

上一篇文章讲了使用Pushgateway收集业务数据的方法,今天讲另外一种方式textfile collector

The textfile collector is similar to the Pushgateway, in that it allows exporting of statistics from batch jobs. The Pushgateway should be used for service-level metrics. The textfile module is for metrics that are tied to a machine.

textfile collector 和 Pushgateway类似,都可以收集监控数据,二者的不同是 Pushgateway是一个独立的组件、textfile collector是node_exporter的附加功能,Pushgateway适用于service-level的job,textfile collector适用于machine-level的job。

textfile collector的功能就是,让node_exporter在收集数据时,顺带把指定目录下文件的内容 也加入到metrics里面


To use it, set the --collector.textfile.directory flag on the node_exporter commandline. The collector will parse all files in that directory matching the glob *.prom using the text format.

要使用textfile collector,需要在node_exporter的启动命令中增加参数--collector.textfile.directory=dir_path

例:./node_exporter --collector.textfile.directory=/root/prometheus/prom 这样node_exporter会把/root/prometheus/prom下所有 .prom 文件的内容一并收集到metrics

.prom 文件的内容格式是这样:

# HELP http_requests_total The total number of HTTP requests.
# TYPE http_requests_total counter
http_requests_total{method="post",code="200"} 1027
http_requests_total{method="post",code="400"}    3

# A histogram, which has a pretty complex representation in the text format:
# HELP http_request_duration_seconds A histogram of the request duration.
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_bucket{le="0.05"} 24054
http_request_duration_seconds_bucket{le="0.1"} 33444
http_request_duration_seconds_bucket{le="0.2"} 100392
http_request_duration_seconds_bucket{le="0.5"} 129389
http_request_duration_seconds_bucket{le="1"} 133988
http_request_duration_seconds_bucket{le="+Inf"} 144320
http_request_duration_seconds_sum 53423
http_request_duration_seconds_count 144320

# Finally a summary, which has a complex representation, too:
# HELP rpc_duration_seconds A summary of the RPC duration in seconds.
# TYPE rpc_duration_seconds summary
rpc_duration_seconds{quantile="0.01"} 3102
rpc_duration_seconds{quantile="0.05"} 3272
rpc_duration_seconds{quantile="0.5"} 4773
rpc_duration_seconds{quantile="0.9"} 9001
rpc_duration_seconds{quantile="0.99"} 76656
rpc_duration_seconds_sum 1.7560473e+07
rpc_duration_seconds_count 2693

到prometheus页面就能查到上面的指标:

需要注意的是,如果不需要收集指标时,应该将对应的文件删除,否则node_exporter在每次收集数据时,将该文件的内容加入到metrics。(如上图,只要.prom文件没被删除或更新,就会搜到一堆不同时间戳下的重复值)

textfile collector是最简单的业务数据收集方式,不挑语言,只要有文件就行。

更多内容见官方文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值