summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--health-model.lua21
-rw-r--r--health-storage-html.lsp41
-rw-r--r--health-system-html.lsp20
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 @@
<h2>Storage</h2>
<h3>Floppy capacity</h3>
-<pre><?= view.storage.floppycapacity ?></pre>
+<pre><?= view.storage.floppycapacity.value ?></pre>
-<h3>HD capacity</h3>
-<pre><?= view.storage.hdcapacity ?></pre>
+<? if (view.storage.floppycapacity.used) then ?>
+<TABLE STYLE="margin:0px;padding:0px;border:0px">
+ <TR>
+ <TD>0%</TD><TD WIDTH="<?= view.storage.floppycapacity.used ?>%" STYLE="background:red;"><CENTER><?= view.storage.floppycapacity.used ?>%</CENTER></TD><TD WIDTH="<?= (100-view.storage.floppycapacity.used) ?>%" STYLE="background:green;"><CENTER><?= (100-view.storage.floppycapacity.used) ?>%</CENTER></TD><TD>100%</TD>
+ </TR>
+</TABLE>
+<TABLE STYLE="margin:0px;padding:0px;border:0px">
+ <TR>
+ <TD WIDTH="100px"><B><?= view.storage.floppycapacity.used_label ?></B></TD><TD STYLE="background:red;" WIDTH="20px"></TD><TD WIDTH="70px"><B>=Used</B></TD><TD STYLE="background:green;" WIDTH="20px"></TD><TD><B>=Free</B></TD>
+ </TR>
+</TABLE>
+<? end ?>
-<h3>HD Partitions</h3>
+<h3>Disk capacity</h3>
+<pre><?= view.storage.hdcapacity.value ?></pre>
+
+<? if (view.storage.hdcapacity.used) then ?>
+<TABLE STYLE="margin:0px;padding:0px;border:0px">
+ <TR>
+ <TD>0%</TD><TD WIDTH="<?= view.storage.hdcapacity.used ?>%" STYLE="background:red;"><CENTER><?= view.storage.hdcapacity.used ?>%</CENTER></TD><TD WIDTH="<?= (100-view.storage.hdcapacity.used) ?>%" STYLE="background:green;"><CENTER><?= (100-view.storage.hdcapacity.used) ?>%</CENTER></TD><TD>100%</TD>
+ </TR>
+</TABLE>
+<TABLE STYLE="margin:0px;padding:0px;border:0px">
+ <TR>
+ <TD WIDTH="100px"><B><?= view.storage.hdcapacity.used_label ?></B></TD><TD STYLE="background:red;" WIDTH="20px"></TD><TD WIDTH="70px"><B>=Used</B></TD><TD STYLE="background:green;" WIDTH="20px"></TD><TD><B>=Free</B></TD>
+ </TR>
+</TABLE>
+<? end ?>
+
+<h3>Disk partitions</h3>
<pre><?= view.storage.partitions ?></pre>
+
+<?
+--[[ DEBUG INFORMATION
+require("debugs")
+io.write(debugs.variables(view))
+--]]
+?>
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 @@
<h3>Name</h3>
<pre><?= view.system.uname ?></pre>
<h3>Memory</h3>
-<pre><?= view.system.memory ?></pre>
+<pre><?= view.system.memory.value ?></pre>
+
+<TABLE STYLE="margin:0px;padding:0px;border:0px">
+ <TR>
+ <TD>0%</TD><TD WIDTH="<?= view.system.memory.used ?>%" STYLE="background:red;"><CENTER><?= view.system.memory.used ?>%</CENTER></TD><TD WIDTH="<?= (100-view.system.memory.used) ?>%" STYLE="background:green;"><CENTER><?= (100-view.system.memory.used) ?>%</CENTER></TD><TD>100%</TD>
+ </TR>
+</TABLE>
+<TABLE STYLE="margin:0px;padding:0px;border:0px">
+ <TR>
+ <TD WIDTH="100px"><B><?= view.system.memory.used_label ?></B></TD><TD STYLE="background:red;" WIDTH="20px"></TD><TD WIDTH="70px"><B>=Used</B></TD><TD STYLE="background:green;" WIDTH="20px"></TD><TD><B>=Free</B></TD>
+ </TR>
+</TABLE>
+
+<?
+--[[ DEBUG INFORMATION
+require("debugs")
+io.write(debugs.variables(view))
+--]]
+?>