From 6c63347a6ae2f25de2bf8cf9aea93ea31a786418 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Sat, 24 May 2008 15:41:37 +0000 Subject: Modified health controller to use cfe's and added support for multiple floppy and hard drives. git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@1181 ab2d0c66-481e-0410-8bed-d214d4d58bed --- alpine-baselayout.roles | 2 +- health-controller.lua | 10 +++---- health-model.lua | 70 +++++++++++++++++++++++++++---------------- health-modules-html.lsp | 2 +- health-network-html.lsp | 4 +-- health-proc-html.lsp | 4 +-- health-storage-html.lsp | 80 ++++++++++++++++++++++++++++++++----------------- health-system-html.lsp | 17 ++++++----- 8 files changed, 117 insertions(+), 72 deletions(-) diff --git a/alpine-baselayout.roles b/alpine-baselayout.roles index f0647c6..22dd03f 100644 --- a/alpine-baselayout.roles +++ b/alpine-baselayout.roles @@ -2,4 +2,4 @@ CREATE=interfaces:create READ=health:storage,health:proc,health:network,health:modules,interfaces:read,logfiles:status,logfiles:view,logfiles:download,syslog:status,syslog:basicstatus UPDATE=interfaces:update,skins:update,skins:read,syslog:startstop,syslog:config,syslog:expert,interfaces:config DELETE=interfaces:delete,logfiles:delete -ALL=health:system, hostname:read +ALL=health:system,hostname:read diff --git a/health-controller.lua b/health-controller.lua index 72838e1..6ebc00e 100644 --- a/health-controller.lua +++ b/health-controller.lua @@ -5,21 +5,21 @@ default_action = "system" -- Public methods system = function (self ) - return ({system = self.model:get_system(), url = self.conf.script .. self.conf.prefix .. self.conf.controller} ) + return self.model:get_system() end storage = function (self ) - return ({storage = self.model:get_storage(), url = self.conf.script .. self.conf.prefix .. self.conf.controller} ) + return self.model:get_storage() end network = function (self ) - return ({network = self.model:get_network(), url = self.conf.script .. self.conf.prefix .. self.conf.controller} ) + return self.model:get_network() end modules = function (self ) - return ({modules = self.model:get_modules(), url = self.conf.script .. self.conf.prefix .. self.conf.controller} ) + return self.model:get_modules() end proc = function (self ) - return ({proc = self.model:get_proc(), url = self.conf.script .. self.conf.prefix .. self.conf.controller} ) + return self.model:get_proc() end diff --git a/health-model.lua b/health-model.lua index 638e0a0..0646f5e 100644 --- a/health-model.lua +++ b/health-model.lua @@ -33,46 +33,64 @@ end -- Public functions get_system = function (self) local system = {} - system.uptime = querycmd("/usr/bin/uptime") - system.date = querycmd("/bin/date") - system.version = fs.read_file("/etc/alpine-release") or "Unknown" - system.timezone = date.what_tz() - system.uname = querycmd("/bin/uname -a") - 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 + system.uptime = cfe({ value=querycmd("/usr/bin/uptime"), label="Uptime" }) + system.date = cfe({ value=querycmd("/bin/date"), label="Date" }) + system.version = cfe({ value=fs.read_file("/etc/alpine-release") or "Unknown", label="Version" }) + system.timezone = cfe({ value=date.what_tz(), label="Time Zone" }) + system.uname = cfe({ value=querycmd("/bin/uname -a"), label="UName" }) + system.memory = cfe({ value=querycmd("/usr/bin/free"), label="Memory usage" }) + system.memory.used = getpercentage(querycmd("/usr/bin/free"), "Total:", 3, 4) + return cfe({ type="group", value=system }) end get_storage = function (self) local storage = {} - 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 + local disk = diskfree() .. "\n" + local other = {} + for line in string.gmatch(disk, "([^\n]*)\n") do + if string.match(line, "^/dev/fd%d+") then + if not storage.floppy then + storage.floppy = cfe({ type="group", value={}, label="Floppy drives" }) + end + local name = string.match(line, "^(/dev/fd%d+)") + storage.floppy.value[name] = cfe({ value=string.match(disk, "[^\n]*\n")..line, label="Floppy Capacity" }) + storage.floppy.value[name].used = string.match(line, name.."%s*%S*%s*%S*%s*%S*%s*(%S*)%%") + elseif string.match(line, "^/dev/none") then + if not storage.ramdisk then + storage.ramdisk = cfe({ type="group", value={}, label="RAM disks" }) + end + local name = "/dev/none" + storage.ramdisk.value[name] = cfe({ value=string.match(disk, "[^\n]*\n")..line, label="RAM Disk Capacity" }) + storage.ramdisk.value[name].used = string.match(line, name.."%s*%S*%s*%S*%s*%S*%s*(%S*)%%") + elseif string.match(line, "^/dev/hd%a%d+") then + if not storage.hd then + storage.hd = cfe({ type="group", value={}, label="Hard drives" }) + end + local name = string.match(line, "^(/dev/hd%a%d+)") + storage.hd.value[name] = cfe({ value=string.match(disk, "[^\n]*\n")..line, label="Hard Drive Capacity" }) + storage.hd.value[name].used = string.match(line, name.."%s*%S*%s*%S*%s*%S*%s*(%S*)%%") + end + end + storage.partitions = cfe({ value=fs.read_file("/proc/partitions"), label="Partitions" }) + return cfe({ type="group", value=storage }) end get_network = function (self) local network = {} - network.interfaces = querycmd("/bin/ip addr") - network.routes = querycmd("/bin/ip route") - return network + network.interfaces = cfe({ value=querycmd("/bin/ip addr"), label="Interfaces" }) + network.routes = cfe({ value=querycmd("/bin/ip route"), label="Routes" }) + return cfe({ type="group", value=network }) end get_modules = function (self) local modules = {} - modules.list = querycmd("/sbin/lsmod") - return modules + modules.list = cfe({ value=querycmd("/sbin/lsmod"), label="Modules List" }) + return cfe({ type="group", value=modules }) end get_proc = function (self) local proc = {} - proc.processor = fs.read_file("/proc/cpuinfo") - proc.memory = fs.read_file("/proc/meminfo") - return proc + proc.processor = cfe({ value=fs.read_file("/proc/cpuinfo"), label="Processor" }) + proc.memory = cfe({ value=fs.read_file("/proc/meminfo"), label="Memory" }) + return cfe({ type="group", value=proc }) end diff --git a/health-modules-html.lsp b/health-modules-html.lsp index a1b92ca..d379d95 100644 --- a/health-modules-html.lsp +++ b/health-modules-html.lsp @@ -3,4 +3,4 @@

Modules

Installed modules

-
+
diff --git a/health-network-html.lsp b/health-network-html.lsp index 09760da..6533133 100644 --- a/health-network-html.lsp +++ b/health-network-html.lsp @@ -3,7 +3,7 @@

Network

Interface status

-
+

Routes

-
+
diff --git a/health-proc-html.lsp b/health-proc-html.lsp index 7d57ef5..299c605 100644 --- a/health-proc-html.lsp +++ b/health-proc-html.lsp @@ -3,7 +3,7 @@

Process information

Processor

-
+

Memory

-
+
diff --git a/health-storage-html.lsp b/health-storage-html.lsp index f8f5b73..4e9a0a8 100644 --- a/health-storage-html.lsp +++ b/health-storage-html.lsp @@ -1,39 +1,65 @@ +"..disk.value.."\n") +io.write('\n') +io.write(" \n") +io.write(" \n") +if tonumber(disk.used) > 0 then + io.write(' \n') +end +if tonumber(disk.used) < 100 then + io.write(' \n') +end +io.write(' \n') +io.write(" \n") +io.write("
0%
') + if ( tonumber(disk.used) > 10) then io.write(disk.used .. "%") end + io.write('
') + if ( 90 > tonumber(disk.used)) then io.write((100-disk.used) .. "%") end + io.write('
100%
\n") +io.write('\n') +io.write(" \n") +io.write(' \n') +io.write(" \n") +io.write("
'..name..'=Used=Free
\n") +end ?> +

Storage

Floppy capacity

-
- - - - - - -
0%
10) then io.write(view.storage.floppycapacity.used .. "%") end ?>
tonumber(view.storage.floppycapacity.used)) then io.write((100-view.storage.floppycapacity.used) .. "%") end ?>
100%
- - - - -
=Used=Free
+ +No Floppy mounted -

Disk capacity

-
+

Harddrive capacity

+ +No Harddrive mounted + - - - - - -
0%
10) then io.write(view.storage.hdcapacity.used .. "%") end ?>
tonumber(view.storage.hdcapacity.used)) then io.write((100-view.storage.hdcapacity.used) .. "%") end ?>
100%
- - - - -
=Used=Free
+

RAM Disk capacity

+ +No RAM Disk mounted +

Disk partitions

-
+
+ diff --git a/health-system-html.lsp b/health-system-html.lsp index ee7feb9..ec6ea12 100644 --- a/health-system-html.lsp +++ b/health-system-html.lsp @@ -3,27 +3,28 @@

System

Versions and names

-
-
+
+

Uptime

-
+

Time/TimeZone

-
-
+
+

Memory

-
+
- +
0%
10) then io.write(view.system.memory.used .. "%") end ?>
tonumber(view.system.memory.used)) then io.write((100-view.system.memory.used) .. "%") end ?>
100%0%
10) then io.write(view.value.memory.used .. "%") end ?>
tonumber(view.value.memory.used)) then io.write((100-view.value.memory.used) .. "%") end ?>
100%
- +
=Used=FreeTotal:=Used=Free
-- cgit v1.2.3