diff options
Diffstat (limited to 'emacs')
-rw-r--r-- | emacs/custom/my-ui.el | 2 | ||||
-rw-r--r-- | emacs/elisp/my-uptime.el | 55 | ||||
-rw-r--r-- | emacs/init.el | 1 |
3 files changed, 57 insertions, 1 deletions
diff --git a/emacs/custom/my-ui.el b/emacs/custom/my-ui.el index 59d0b46..1dabcea 100644 --- a/emacs/custom/my-ui.el +++ b/emacs/custom/my-ui.el @@ -106,7 +106,7 @@ (window-width . 0.4) (side . left) (slot . 0)) - ("\\*\\(wclock\\).*" + ("\\*\\(wclock\\|slo-calculator\\).*" (display-buffer-in-side-window) (window-width . 0.35) (side . left) diff --git a/emacs/elisp/my-uptime.el b/emacs/elisp/my-uptime.el new file mode 100644 index 0000000..3522f91 --- /dev/null +++ b/emacs/elisp/my-uptime.el @@ -0,0 +1,55 @@ +;;; my-uptime.el --- calculates uptime for SLOs + +;;; Commentary: + +;; Calculate how much downtime is allowed for different period of time +;; based on a given SLO. + +;;; Code: + +(defconst my-uptime/buffer-name "*slo-calculator*") + +(defconst my-uptime/seconds-per-hour 3600 + "Number of seconds in an hour.") +(defconst my-uptime/seconds-per-day (* my-uptime/seconds-per-hour 24) + "Number of seconds in a day.") +(defconst my-uptime/seconds-per-week (* my-uptime/seconds-per-day 7) + "Number of seconds in a week.") +(defconst my-uptime/seconds-per-month (* my-uptime/seconds-per-day 30) + "Number of seconds in a month.") +(defconst my-uptime/seconds-per-quarter (* my-uptime/seconds-per-month 3) + "Number of seconds in a quarter.") +(defconst my-uptime/seconds-per-year (* my-uptime/seconds-per-month 12) + "Number of seconds in a year.") + +(defun my-uptime/is (slo) + "Return the amount of allowed downtime for a given SLO." + (interactive "nSLO:") + (let* ((slo (cond ((< slo 0) 0) + ((> slo 100) 100) + (t slo))) + (allowed (/ (- (* 100 100) (* slo 100.0)) (* 100 100)))) + (my-uptime/message allowed slo))) + +(defun my-uptime/message (seconds slo) + "Insert buffer text with allowed downtime based on SECONDS (derived from SLO)." + (let ((inhibit-read-only t) + (buffer-undo-list t)) + (pop-to-buffer my-uptime/buffer-name) + (erase-buffer) + (insert (format "calculated allowed downtime for %s%% availability.\n" slo)) + (insert + (format "daily: %s\n" (format-seconds "%H %M %S" (seconds-to-time (* my-uptime/seconds-per-day seconds))))) + (insert + (format "weekly: %s\n" (format-seconds "%H %M %S" (seconds-to-time (* my-uptime/seconds-per-week seconds))))) + (insert + (format "monthly: %s\n" (format-seconds "%D %H %M %S" (seconds-to-time (* my-uptime/seconds-per-month seconds))))) + (insert + (format "quarterly: %s\n" (format-seconds "%D %H %M %S" (seconds-to-time (* my-uptime/seconds-per-quarter seconds))))) + (insert + (format "yearly: %s\n" (format-seconds "%D %H %M %S" (seconds-to-time (* my-uptime/seconds-per-year seconds)))))) + (special-mode)) + +(provide 'my-uptime) + +;;; my-uptime.el ends here diff --git a/emacs/init.el b/emacs/init.el index 46d7e3e..399aab1 100644 --- a/emacs/init.el +++ b/emacs/init.el @@ -100,6 +100,7 @@ Missing packages are installed automatically." (require 'my-strings) (require 'my-web) (require 'my-work) +(require 'my-uptime) (require 'my-packages-extra) ;;; init.el ends here |