【发布时间】:2014-08-21 15:08:57
【问题描述】:
Spring Boot Actuator 提供了几个端点来监控一个应用程序:
/metrics
/beans
/health
...
检查端点:
curl http://localhost:8080/metrics
结果:
{"counter.status.200.env":1,"counter.status.200.health":1,"counter.status.200.info":2,"counter.status.200.metrics":2,"gauge.response.env":5.0,"gauge.response.health":22.0,"gauge.response.info":1.0,"gauge.response.metrics":1.0,"mem":1030144,"mem.free":56118,"processors":8,"uptime":5108095,"instance.uptime":5102906,"heap.committed":1030144,"heap.init":262144,"heap.used":974031,"heap":3728384,"threads.peak":81,"threads.daemon":21,"threads":77,"classes":8854,"classes.loaded":8860,"classes.unloaded":6,"gc.ps_scavenge.count":119,"gc.ps_scavenge.time":7223,"gc.ps_marksweep.count":12,"gc.ps_marksweep.time":17573}
这适合机器使用,但很难被人类阅读。
我想格式化(即漂亮打印)Spring Boot Actuator 端点的 JSON 输出,使其更易于阅读由操作人员。
类似:
{
"counter.status.200.env":1,
"counter.status.200.health":1,
"counter.status.200.info":2,
"counter.status.200.metrics":2,
"gauge.response.env":5.0,
"gauge.response.health":22.0,
"gauge.response.info":1.0,
...
}
我试过设置
http.mappers.json-pretty-print=true
但此设置不影响执行器输出。
是否有配置来启用漂亮打印 Spring Boot Actuator JSON输出?
更新:
official sample 适合我。
遵循@DaveSyer 的cmets 很重要:要设置的属性是
http.mappers.jsonPrettyPrint=true
调查仍在进行中。
与此同时,我使用 json 漂亮打印 命令行 作为解决方法:
安装 jsonpp(例如用于 OS X):
brew install jsonpp
然后将 curl 输出通过 jsonpp 管道传输,它会即时格式化 json 文件:
curl http://localhost:8080/metrics | jsonpp
结果:
{
"counter.status.200.env": 1,
"counter.status.200.health": 1,
"counter.status.200.info": 2,
"counter.status.200.metrics": 2,
...
}
【问题讨论】:
-
@T.J.Crowder 这是一个端点列表。他们返回 JSON。
-
您可以使用 jackson 漂亮地打印 JSON,请参阅:stackoverflow.com/a/14532435/179630
标签: json spring spring-boot