From e0b7bd24427cdc3b98a35c2105063d42a05dbab7 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Sat, 22 Dec 2007 11:25:29 +0000 Subject: 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 --- health-model.lua | 21 ++++++++++++++++++--- health-storage-html.lsp | 41 +++++++++++++++++++++++++++++++++++++---- health-system-html.lsp | 20 +++++++++++++++++++- 3 files changed, 74 insertions(+), 8 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 diff --git a/health-storage-html.lsp b/health-storage-html.lsp index ed20c64..693822a 100644 --- a/health-storage-html.lsp +++ b/health-storage-html.lsp @@ -5,10 +5,43 @@

Storage

Floppy capacity

-
+
-

HD capacity

-
+ + + + + +
0%
%
%
100%
+ + + + +
=Used=Free
+ -

HD Partitions

+

Disk capacity

+
+ + + + + + +
0%
%
%
100%
+ + + + +
=Used=Free
+ + +

Disk partitions

+ + diff --git a/health-system-html.lsp b/health-system-html.lsp index 6bb0887..62d366c 100644 --- a/health-system-html.lsp +++ b/health-system-html.lsp @@ -14,4 +14,22 @@

Name

Memory

-
+
+ + + + + +
0%
%
%
100%
+ + + + +
=Used=Free
+ + -- cgit v1.2.3