有没有办法将json格式转换为Prometheus格式

时间:2019-10-21 16:17:14

标签: json prometheus rundeck

我有来自Rundeck http://localhost:4440/metrics/metrics的JSON响应,我需要将此JSON响应转换为Prometheus格式,

例如,我尝试使用外部插件github.com/mtulio/rundeck-exporter,但是在docker中运行它时遇到了问题,

[~/temp]>docker run -p 9802:9802 -it mtulio/rundeck-exporter:latest -rundeck.user=admin -rundeck.pass=admin -rundeck.url=http://127.0.0.1:4440/metrics/metrics -no-verify-ssl -rundeck.version=27 -rundeck.token=PMMOPwyJ5RtDAUBaORrXdQ4V41CD9HjT
INFO[0000] Retrieving metrics on the Startup...          file=init.go line=113
Unable to update Metrics:  Client SOA is not initializated
panic: Error initializing metrics from the server: Client SOA is not initializated

goroutine 1 [running]:
github.com/mtulio/rundeck-exporter/src/collector.(*RMetrics).InitMetrics(0xc00013a2d0, 0x0, 0x0, 0x0, 0x40cb2d, 0x900660)
    /home/marcobraga/.go/src/github.com/mtulio/rundeck-exporter/src/collector/metrics.go:61 +0x139a
github.com/mtulio/rundeck-exporter/src/collector.NewCollectorMetrics(0xc00000c1a0, 0x3c, 0x0, 0x0, 0x0, 0x0, 0xc000059e18, 0x40bf18)
    /home/marcobraga/.go/src/github.com/mtulio/rundeck-exporter/src/collector/metrics.go:46 +0x80
github.com/mtulio/rundeck-exporter/src/collector.NewCollectorMaster(0xc00000c1a0, 0x3c, 0xc000148000, 0xc00014a000, 0x3b)
    /home/marcobraga/.go/src/github.com/mtulio/rundeck-exporter/src/collector/master.go:52 +0x58
main.initPromCollector(0x9c8360, 0xc0000aa008)
    /home/marcobraga/.go/src/github.com/mtulio/rundeck-exporter/cmd/rundeck-exporter/init.go:131 +0x4e
main.init.0()
    /home/marcobraga/.go/src/github.com/mtulio/rundeck-exporter/cmd/rundeck-exporter/init.go:121 +0x660
(17:30:08)sibrahim@midtierbeta@sibrahim(physio-lit-1810)
[~/Projects/rundeck-prometheus-exporter]>#docker run -p 9802:9802 -id mtulio/rundeck-exporter:latest -rundeck.user='admin' -rundeck.pass='admin' -rundeck.url=http://127.0.0.1:4440/metrics/metrics -no-verify-ssl -rundeck.version=18 -rundeck.token=PMMOPwyJ5RtDAUBaORrXdQ4V41CD9HjT
(17:30:21)sibrahim@midtierbeta@sibrahim(physio-lit-1810)
[~/Projects/rundeck-prometheus-exporter]>docker run -p 9802:9802 -id mtulio/rundeck-exporter:latest -rundeck.user='admin' -rundeck.pass='admin' -rundeck.url=http://127.0.0.1:4440/metrics/metrics -no-verify-ssl -rundeck.version=18 -rundeck.token=PMMOPwyJ5RtDAUBaORrXdQ4V41CD9HjT
412961c446bd63f0944e6af8235d45d68ce671935ebc1719f85b6b88a8f22dc7
(17:30:25)sibrahim@midtierbeta@sibrahim(physio-lit-1810)
[~/Projects/rundeck-prometheus-exporter]>docker run -p 9802:9802 -it mtulio/rundeck-exporter:latest -rundeck.user='admin' -rundeck.pass='admin' -rundeck.url=http://127.0.0.1:4440/metrics/metrics -no-verify-ssl -rundeck.version=18 -rundeck.token=PMMOPwyJ5RtDAUBaORrXdQ4V41CD9HjT
INFO[0000] Retrieving metrics on the Startup...          file=init.go line=113
Unable to update Metrics:  Client SOA is not initializated
panic: Error initializing metrics from the server: Client SOA is not initializated

goroutine 1 [running]:
github.com/mtulio/rundeck-exporter/src/collector.(*RMetrics).InitMetrics(0xc0001302d0, 0x0, 0x0, 0x0, 0x40cb2d, 0x900660)
    /home/marcobraga/.go/src/github.com/mtulio/rundeck-exporter/src/collector/metrics.go:61 +0x139a
github.com/mtulio/rundeck-exporter/src/collector.NewCollectorMetrics(0xc00000c1a0, 0x3c, 0x0, 0x0, 0x0, 0x0, 0xc000087e18, 0x40bf18)
    /home/marcobraga/.go/src/github.com/mtulio/rundeck-exporter/src/collector/metrics.go:46 +0x80
github.com/mtulio/rundeck-exporter/src/collector.NewCollectorMaster(0xc00000c1a0, 0x3c, 0xc00013e000, 0xc000140000, 0x3b)
    /home/marcobraga/.go/src/github.com/mtulio/rundeck-exporter/src/collector/master.go:52 +0x58
main.initPromCollector(0x9c8360, 0xc0000aa008)
    /home/marcobraga/.go/src/github.com/mtulio/rundeck-exporter/cmd/rundeck-exporter/init.go:131 +0x4e
main.init.0()
    /home/marcobraga/.go/src/github.com/mtulio/rundeck-exporter/cmd/rundeck-exporter/init.go:121 +0x660

如果您可以向我建议将JSON格式解析为Prometheus格式的方法,
感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

另一种方法是使用API​​以JSON格式获取指标:

curl --location --request GET "http://yourhost:4440/api/33/metrics/metrics" --header "Accept: application/json" --header "X-Rundeck-Auth-Token: your-user-token" > myfile.json

然后使用jq进行转换。 看看这个thread

实际上,您可以创建一个Rundeck作业来自动执行此过程。