Spring Boot Actuator provides several endpoints to monitor an application as:
/metrics
/b
I use Python's commonly installed json.tool
module:
curl --silent http://localhost:8080/metrics | python -mjson.tool
With spring-boot 1.2.6, you need to use:
spring.jackson.serialization.INDENT_OUTPUT=true
From my log when using the old http.mappers.*:
http.mappers.json-pretty-print is deprecated. If you are using Jackson, spring.jackson.serialization.INDENT_OUTPUT=true should be used instead.
If you're using gson serialization with Spring, then none of the other answers will work for you. You'll have to use this configuration option:
spring.gson.pretty-printing=true
Confirmed working with Spring Boot as of version 2.0.3.Release
.
I use jq
for pretty printing JSON as well as filtering it. It's basically sed
for JSON. On the mac, it can be installed with homebrew. (https://stedolan.github.io/jq/)
curl http://localhost:8080/metrics | jq
Here is my Emacs function to retrieve Spring Actuator Json from endpoints:
(defvar my/spring-actuator-server-history nil)
(defvar my/spring-actuator-last-server "http://localhost:8080")
(defvar my/spring-actuator-path-history nil)
(defvar my/spring-actuator-path-completion
'("actuator" "auditevents" "autoconfig" "beans" "configprops" "dump" "env" "flyway" "health" "heapdump"
"info" "jolokia" "liquibase" "logfile" "loggers" "mappings" "metrics" "shutdown" "trace")))
(defun my/spring-actuator (server path)
(interactive (list (read-string "Server: " my/spring-actuator-last-server 'my/spring-actuator-server-history)
(completing-read "Path: " my/spring-actuator-path-completion nil nil "" 'my/spring-actuator-path-history)))
(setq my/spring-actuator-last-server server)
(let ( (bufname (format "actuator: %s" path)) )
(when (get-buffer bufname)
(kill-buffer bufname))
(switch-to-buffer (url-retrieve-synchronously (format "%s/%s" server path)))
(rename-buffer bufname)
(goto-char (point-min))
(re-search-forward "^$" nil 'move)
(forward-char)
(delete-region (point-min) (point))
(json-pretty-print-buffer)
(json-mode) ))
If you don't like dependency on external json-mode
library replace it with js-mode
.
Do the following:
@Configuration
public class JacksonConfig {
@Autowired
private ObjectMapper objectMapper; //reuse the pre-configured mapper
@PostConstruct
public void setup() {
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
//whatever else you need
}
}
This works because Spring Boot uses an ObjectMapper
bean to perform all the JSON related operations.
Note however that this configuration will pretty print all JSON outputs, not just the actuator related stuff.
UPDATE
The answer from @DaveSyer is obviously better! I hadn't found the HttpMapperProperties
object which is used to configure Jackson. This is it's Javadoc