diff options
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 |