Commit 0d764ad9 authored by David Byers's avatar David Byers
Browse files

Show server statistics in kom-status-server.

Detailed changes:
> 	* commands2.el (kom-status-server): Show statistics about the
> 	server.
>
> 	* lyskom-rest.el (lyskom-format-aux-help): Added support for
> 	formatting floats.
> 	(lyskom-format-aux): Support setting fraction length for floats.
> 	(lyskom-format-units): New function.
>
parent 5929f556
2003-08-03 David Byers <byers@lysator.liu.se>
* commands2.el (kom-status-server): Show statistics about the
server.
* lyskom-rest.el (lyskom-format-aux-help): Added support for
formatting floats.
(lyskom-format-aux): Support setting fraction length for floats.
(lyskom-format-units): New function.
Support get-stats server call:
* utilities.el (lyskom-get-server-stats): New function.
......
......@@ -3096,6 +3096,34 @@ properly in the client."
(lyskom-aux-item-terminating-button item 'server))
))
;; ----------------------------------------
;; Print statistics
(let* ((stats (lyskom-get-server-stats))
(what (server-stats->what stats))
(maxlen (and stats (apply 'max (mapcar 'length what))))
(fmt (and maxlen (format "%%=%d#1s " maxlen))))
(when stats
(lyskom-format-insert 'status-server-stats)
(lyskom-insert (lyskom-format fmt ""))
(lyskom-traverse period (server-stats->when stats)
(lyskom-format-insert " %=8#1s"
(if (eq 0 period)
(lyskom-get-string 'current-average)
(lyskom-format-units period
'((604800 . "w")
(86400 . "d")
(3600 . "h")
(60 . "m"))
"s"))))
(lyskom-insert "\n")
(lyskom-traverse item (server-stats->values stats)
(lyskom-format-insert fmt (car item))
(lyskom-traverse val (cdr item)
(lyskom-format-insert " %=8.2.7#1f" (stats->average val)))
(lyskom-format-insert "\n"))))
;; ----------------------------------------
;; Print MOTD (if there is one)
(when (not (zerop (server-info->motd-of-lyskom server-info)))
......
......@@ -1948,7 +1948,11 @@ about who you are, and this contributes to the sense of community in
written a presentation.%]
========================================================================
") ))
")
(status-server-stats . "Server statistics:\n\n")
(current-average . "current")
))
(lyskom-language-var local lyskom-month-names en
......
......@@ -1254,7 +1254,7 @@ Args: FORMAT-STRING &rest ARGS"
(defvar lyskom-format-format
"%\\(=\\)?\\(-?[0-9]+\\)?\\(:.\\)?\\(#\\([0-9]+\\)\\)?\\(_\\)?\\(:\\)?\\(&\\)?\\([][$@MmPpnrtsdoxlcCSDF%?]\\)"
"%\\(=\\)?\\(-?[0-9]+\\|-?[0-9]+\\.[0-9]+\\|-?[0-9]+\\.[0-9]+\\.[0-9]+\\)?\\(:.\\)?\\(#\\([0-9]+\\)\\)?\\(_\\)?\\(:\\)?\\(&\\)?\\([][$@MmPpnrtsdoxlcfgCSDF%?]\\)"
"regexp matching format string parts.")
(defun lyskom-insert-string (atom)
......@@ -1397,6 +1397,8 @@ Deferred insertions are not supported."
(let ((format-length (length (format-state->format-string format-state)))
(arg-no nil)
(pad-length nil)
(frac-min nil)
(frac-max nil)
(pad-string nil)
(format-letter nil)
(colon-flag nil)
......@@ -1445,12 +1447,17 @@ Deferred insertions are not supported."
(set-format-state->start format-state
(match-end 0))
(when (match-beginning 2)
(save-match-data
(let* ((s (match-string 2 (format-state->format-string format-state))))
(cond ((or (string-match "\\(-?[0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)" s)
(string-match "\\(-?[0-9]+\\)\\.\\([0-9]+\\)" s))
(setq pad-length (string-to-int (match-string 1 s)))
(setq frac-min (string-to-int (match-string 2 s)))
(setq frac-max (string-to-int (or (match-string 3 s) (match-string 2 s)))))
(t (setq pad-length (string-to-int s)))))))
(setq equals-flag (match-beginning 1)
pad-length (if (match-beginning 2)
(string-to-int (match-string
2 (format-state->format-string
format-state)))
nil)
arg-no (if (match-beginning 5)
(string-to-int (match-string
5 (format-state->format-string
......@@ -1487,6 +1494,8 @@ Deferred insertions are not supported."
(lyskom-format-aux-help
format-state
pad-length
frac-min
frac-max
arg-no
format-letter
equals-flag
......@@ -1509,6 +1518,8 @@ Deferred insertions are not supported."
(defun lyskom-format-aux-help (format-state
pad-length
frac-min
frac-max
arg-no
format-letter
equals-flag
......@@ -1576,6 +1587,45 @@ Deferred insertions are not supported."
(t (signal 'lyskom-internal-error
(list 'lyskom-format
": argument error (expected int)"))))))
((or (= format-letter ?g)
(= format-letter ?f)
(= format-letter ?e))
(setq result (cond ((numberp arg)
(format (if frac-max
(format "%%.%d%c"
frac-max
format-letter)
(format "%%%c" format-letter))
arg))
(t (signal 'lyskom-internal-error
(list 'lyskom-format
": argument error (expected number)")))))
(save-match-data
(when (and (string-match "\\." result)
(string-match "\\.?0+$" result))
(setq result (substring result 0 (match-beginning 0))))
(when (and frac-min (> frac-min 0))
(if (string-match "\\.\\([0-9]*\\)$" result)
(setq result
(concat result
(make-string
(max 0
(- frac-min
(length (match-string 1 result))))
?0)))
(setq result
(concat result
"."
(make-string frac-min ?0)))))))
((= format-letter ?f)
(setq result (cond ((numberp arg) (format "%f" arg))
(t (signal 'lyskom-internal-error
(list 'lyskom-format
": argument error (expected number)"))))))
;;
;; Format a character by converting it to a string and inserting
;; it into the result list
......
......@@ -1979,6 +1979,9 @@ att upprepas d
========================================================================
")
(status-server-stats . "Statistik om servern:\n\n")
(current-average . "nu")
))
(lyskom-language-var local lyskom-month-names sv
......
......@@ -2009,3 +2009,29 @@ Any whitespace and newlines in TEXT will be ignored."
(set-server-stats->values result
(nreverse (collector->value collector)))
result))))
(defun lyskom-format-units (val units base-unit)
"Format VAL using units. UNITS is an alist (COUNT . NAME), where
NAME is the name of a unit and COUNT is the number of base units for
that name. For example, if the base unit is seconds, then minutes
could be defined with \(60 . \"min\"). BASE-UNIT is the name of the
base unit \(which implicitly has a count of 1)."
(mapconcat
(lambda (el)
(format "%d%s"
(car el)
(cond ((stringp (cdr el)) (cdr el))
((symbolp (cdr el)) (lyskom-get-string (cdr el))))))
(nreverse
(let ((result nil))
(lyskom-traverse unit units
(when (>= val (car unit))
(let ((a (/ val (car unit))))
(when (> a 0) (setq result (cons (cons a (cdr unit)) result)))
(setq val (% val (car unit))))))
(if (> val 0)
(cons (cons val base-unit) result)
result)))
""))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment