Skip to content

Commit

Permalink
Fix mem-usage and clarify parameters. Fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Mar 23, 2020
1 parent 739eb6c commit 112057c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions documentation.lisp
Expand Up @@ -75,6 +75,9 @@ See VALUE-GENERATOR")
You may specify whether you're interested in swap and cache
by using the :SWAP and :CACHE initargs respectively.
When :CACHE is T, memory used by the cache is counted as
occupied. When :SWAP is T, swap memory and usage are added
to the total.
This value-generator supplies the following three values:
0. usage-percentage
Expand Down
19 changes: 10 additions & 9 deletions generators/mem-usage.lisp
Expand Up @@ -27,15 +27,16 @@

(defmethod compute-value ((generator mem-usage))
(let* ((meminfo (parse-meminfo))
(total (+ (gethash "MemTotal" meminfo)
(if (include-swap generator) (gethash "SwapTotal" meminfo) 0)))
(free (gethash "MemFree" meminfo)
(gethash "Buffers" meminfo)
(if (include-cache generator) 0 (gethash "Cached" meminfo))
(if (include-swap generator)
(+ (gethash "SwapFree" meminfo)
(if (include-cache generator) 0 (gethash "SwapCached" meminfo)))
0)))
(total (gethash "MemTotal" meminfo))
(free (+ (gethash "MemFree" meminfo)
(gethash "Buffers" meminfo))))
(unless (include-cache generator)
(incf free (gethash "Cached" meminfo)))
(when (include-swap generator)
(incf total (gethash "SwapTotal" meminfo))
(incf free (gethash "SwapFree" meminfo))
(unless (include-cache generator)
(incf free (gethash "SwapCached" meminfo))))
(list (float (* 100 (/ (- total free) total)))
(float (/ total 1024))
(float (/ free 1024)))))

0 comments on commit 112057c

Please sign in to comment.