【发布时间】:2020-04-05 16:42:09
【问题描述】:
我在 k8s 上部署了 Prometheus Node Exporter pod。效果很好。
但是当我尝试通过在我的自定义 Go 应用程序中调用 Node Exporter 指标 API 来获取系统指标时
curl -X GET "http://[my Host]:9100/metrics"
结果格式是这样的
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 1.7636e-05
go_gc_duration_seconds{quantile="0.25"} 2.466e-05
go_gc_duration_seconds{quantile="0.5"} 5.7992e-05
go_gc_duration_seconds{quantile="0.75"} 9.1109e-05
go_gc_duration_seconds{quantile="1"} 0.004852894
go_gc_duration_seconds_sum 1.291217651
go_gc_duration_seconds_count 11338
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 8
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.12.5"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 2.577128e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 2.0073577064e+10
.
.
.
something like this
那些长文本很难解析,我想得到 JSON 格式的结果以便轻松解析。
https://github.com/prometheus/node_exporter/issues/1062
我检查了 Prometheus Node Exporter GitHub 问题,有人推荐了 prom2json。 但这不是我要找的。因为我必须运行额外的进程来执行 prom2json 才能得到结果。我想通过简单地在我的代码中调用 HTTP 请求或某种 Go 原生包来获取 Node Exporter 的系统指标。
如何获取 JSON 格式的 Node Exporter 指标?
【问题讨论】:
-
为什么不使用
prom2json代码库作为库?据我所知,节点导出器没有这样的端点以 JSON 格式公开指标。 -
这是标准的 Prometheus 指标格式,所有导出器都将遵循相同的格式。我宁愿问,为什么要json格式,也就是要json格式的metrics做什么?
标签: go kubernetes prometheus prometheus-node-exporter