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

Is there a way to convert json format to Prometheus format

我有来自 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 格式的方法,
感谢您的帮助。

另一种方法是使用 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转换。 看看这个.

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