curl 返回json 并格式化

应用

curl http://url/path | python -m json.tool

例子

curl 'http://localhost:9090/api/v1/targets?state=active' | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   573  100   573    0     0  50087      0 --:--:-- --:--:-- --:--:-- 95500
{
    "status": "success",
    "data": {
        "activeTargets": [
            {
                "discoveredLabels": {
                    "__address__": "localhost:9090",
                    "__metrics_path__": "/metrics",
                    "__scheme__": "http",
                    "__scrape_interval__": "15s",
                    "__scrape_timeout__": "10s",
                    "job": "prometheus"
                },
                "labels": {
                    "instance": "localhost:9090",
                    "job": "prometheus"
                },
                "scrapePool": "prometheus",
                "scrapeUrl": "http://localhost:9090/metrics",
                "globalUrl": "http://5139fd605963:9090/metrics",
                "lastError": "",
                "lastScrape": "2022-08-24T07:16:13.163976926Z",
                "lastScrapeDuration": 0.013138167,
                "health": "up",
                "scrapeInterval": "15s",
                "scrapeTimeout": "10s"
            }
        ],
        "droppedTargets": []
    }
}
posted @ 2022-08-24 15:18  Star-Hitian  阅读(717)  评论(0编辑  收藏  举报