diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-05-24 15:41:37 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-05-24 15:41:37 +0000 |
commit | 6c63347a6ae2f25de2bf8cf9aea93ea31a786418 (patch) | |
tree | 5937cfeacf14ee8ea7d7f805e5bb6c7c6e721cfb /health-model.lua | |
parent | fca6053366b3728ec57874478868ca0e0b9120cf (diff) | |
download | acf-alpine-baselayout-6c63347a6ae2f25de2bf8cf9aea93ea31a786418.tar.bz2 acf-alpine-baselayout-6c63347a6ae2f25de2bf8cf9aea93ea31a786418.tar.xz |
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
Diffstat (limited to 'health-model.lua')
-rw-r--r-- | health-model.lua | 70 |
1 files changed, 44 insertions, 26 deletions
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 |