Pretty print JSON output of Spring Boot Actuator endpoints

前端 未结 14 1002
终归单人心
终归单人心 2020-12-24 12:30

Spring Boot Actuator provides several endpoints to monitor an application as:

/metrics
/b         


        
14条回答
  •  情话喂你
    2020-12-24 13:09

    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.

提交回复
热议问题