有三种方式
一、Python 格式化
在curl命令后面添加 | python -m json.tool 即可。
➜ views git:(master) ✗ curl -g 'http://10.4.110.138:9090/api/v1/series?match[]=up&match[]=process_start_time_seconds{job="prometheus"}' | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 183 100 183 0 0 27568 0 --:--:-- --:--:-- --:--:-- 30500
{
"data": [
{
"__name__": "process_start_time_seconds",
"instance": "localhost:9090",
"job": "prometheus"
},
{
"__name__": "up",
"instance": "localhost:9090",
"job": "prometheus"
}
],
"status": "success"
}
二、Nodejs 格式化
安装json命令
npm install -g json
在curl命令后面添加 | json 即可。
例如:
views git:(master) ✗ curl -g 'http://10.4.110.138:9090/api/v1/series?match[]=up&match[]=process_start_time_seconds{job="prometheus"}' | json
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 183 100 183 0 0 31250 0 --:--:-- --:--:-- --:--:-- 36600
{
"status": "success",
"data": [
{
"__name__": "process_start_time_seconds",
"instance": "localhost:9090",
"job": "prometheus"
},
{
"__name__": "up",
"instance": "localhost:9090",
"job": "prometheus"
}
]
}
第三中
通过jq工具
curl -g 'http://10.4.110.138:9090/api/v1/series?match[]=up&match[]=process_start_time_seconds{job="prometheus"}' | jq .
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 183 100 183 0 0 25771 0 --:--:-- --:--:-- --:--:-- 30500
{
"status": "success",
"data": [
{
"__name__": "process_start_time_seconds",
"instance": "localhost:9090",
"job": "prometheus"
},
{
"__name__": "up",
"instance": "localhost:9090",
"job": "prometheus"
}
]
}
参考: