diff options
author | Mika Havela <mika.havela@gmail.com> | 2007-12-22 11:25:29 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2007-12-22 11:25:29 +0000 |
commit | e0b7bd24427cdc3b98a35c2105063d42a05dbab7 (patch) | |
tree | e35f5ee28c37f6d2f4d7e249817df9fd9728dd5c /health-model.lua | |
parent | d93688f0d12c5c7c9f35d4746eef58bac11a144a (diff) | |
download | acf-alpine-baselayout-e0b7bd24427cdc3b98a35c2105063d42a05dbab7.tar.bz2 acf-alpine-baselayout-e0b7bd24427cdc3b98a35c2105063d42a05dbab7.tar.xz |
Added graphic-bars to show usage/free on some values
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@448 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'health-model.lua')
-rw-r--r-- | health-model.lua | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/health-model.lua b/health-model.lua index e0e2cf3..0594738 100644 --- a/health-model.lua +++ b/health-model.lua @@ -3,6 +3,7 @@ module (..., package.seeall) require("fs") require("date") +require("format") -- ############################################################### -- Private functions @@ -21,6 +22,13 @@ local function diskfree ( media ) return cmd_result end +local function getpercentage ( data,grep,field1,field2 ) + local debugoutput = "" + local grepline = format.string_to_table("%s+" ,string.match(data,grep .. ".*")) + local val1percentage = math.floor(((grepline[field1] / (grepline[field1]+grepline[field2]))*100)+0.5) + return val1percentage +end + -- ############################################################### -- Public functions get_system = function (self) @@ -29,14 +37,21 @@ get_system = function (self) system.date = querycmd("/bin/date") system.timezone = date.what_tz() system.uname = querycmd("/bin/uname -a") - system.memory = querycmd("/usr/bin/free") + local used, useddebug = getpercentage(querycmd("/usr/bin/free"), "Total:", 3, 4) + system.memory = {value=querycmd("/usr/bin/free"), + used=used, + used_label="Total:"} return system end get_storage = function (self) local storage = {} - storage.floppycapacity = diskfree("/media/floppy") - storage.hdcapacity = diskfree() + storage.floppycapacity = {value=diskfree("/media/floppy"), + used=string.match(diskfree(),"/dev/fd0%s*%S*%s*%S*%s*%S*%s*(%S*)%%"), + used_label="/dev/fd0"} + storage.hdcapacity = {value=diskfree(), + used=string.match(diskfree(),"/dev/none%s*%S*%s*%S*%s*%S*%s*(%S*)%%"), + used_label="/dev/none"} storage.partitions = fs.read_file("/proc/partitions") return storage end |