mylisp/spring-actuator.el
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sat, 02 Jan 2021 20:37:29 +0200
changeset 1682 32e95bb034b6
parent 1666 06937ff1ec5f
permissions -rw-r--r--
Disable population of `file-name-history', it causes calls to abbreviate-file-name => file-name-case-insensitive-p => tramp-autoload-file-name-handler taking 40% of startup time. `ido-switch-buffer' doesn't depends on `file-name-history', nothing to lose. Profiling data for startup: - eval-buffer 4340 99% - recentf-mode 1684 38% - recentf-load-list 1684 38% - mapcar 1684 38% - abbreviate-file-name 1684 38% - file-name-case-insensitive-p 1250 28% + tramp-autoload-file-name-handler 1172 26% + tramp-file-name-handler 78 1%


(require 'json)
(require 'js)

(defvar spring-actuator-server-history nil)
(defvar spring-actuator-last-server "http://localhost:8080")
(defvar spring-actuator-path-history nil)
(defvar spring-actuator-path-completion
  '("actuator" "auditevents" "autoconfig" "beans" "configprops" "dump" "env" "features" "flyway" "health" "heapdump"
    "info" "jolokia" "liquibase" "logfile" "loggers" "mappings" "metrics" "trace"))

;;;###autoload
(defun spring-actuator (server path)
  (interactive (list (read-string "Server: " spring-actuator-last-server 'spring-actuator-server-history)
                     (completing-read "Path: " spring-actuator-path-completion nil nil "" 'spring-actuator-path-history)))
  (setq 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)
    (goto-char (point-min))
    (if (fboundp 'json-mode)
        (json-mode)
      (js-mode))
    (setq-local js-indent-level 2)))

(provide 'spring-actuator)