[ UP ] cgi
[archserver.git] / cgi / status.lua
blobf363f20a9417ff5a171901ce1df37be56a6e7ac2
1 #!/usr/bin/lua
3 dofile "libutil.lua"
5 -- infotable
6 it = {}
8 -------------------------- Hardware -------------
9 io.input("/proc/meminfo")
10 t = io.read("*all")
11 string.gsub(t, "MemTotal.-(%d+).-MemFree.-(%d+).-SwapTotal.-(%d+).-SwapFree.-(%d+)",
12 function(mem,mfree,swap,swapfree)
13 local _img=ui_redblue_img(mem-mfree, mfree)
14 muse = mem - mfree
15 if (muse > 1024*1024)
16 then muse = string.format("%.2fGB", (mem-mfree)/1024/1024)
17 else muse = string.format("%.2fMB", (mem-mfree)/1024)
18 end
20 if (tonumber(mem) > 1024*1024)
21 then mem = string.format("%.2fGB", mem/1024/1024)
22 else mem = string.format("%.2fMB", mem/1024)
23 end
24 it["j物理内存"] = _img.."(已使用"..muse.." / 共"..mem..")"
25 ---------------- Swap -----------
26 local _img=ui_redblue_img(swap-swapfree, swapfree)
27 muse = swap - swapfree
28 if (muse > 1024*1024) then muse = string.format("%.2fGB", (swap-swapfree)/1024/1024)
29 else muse = string.format("%.2fMB", (swap-swapfree)/1024)
30 end
32 if (tonumber(swap) > 1024*1024) then swap = string.format("%.2fGB", swap/1024/1024)
33 else swap = string.format("%.2fMB", swap/1024)
34 end
35 it["k虚拟内存"] = _img.."(已使用"..muse.." / 共"..swap..")"
36 end)
37 io.input("/proc/cpuinfo")
38 t = io.read("*all")
39 string.gsub(t, "model name.-: (.-)\n", function(v) it["f处理器"] = v end)
40 string.gsub(t, "cache size.-: (.-)\n", function(v) it["g处理器缓存"] = v end)
43 -------------------------- System -------------
44 it["a系统型号"] = "AS100 Version 0.01"
45 it["b系统名称"] = myexec("hostname")
46 t = myread("/proc/uptime")
47 string.gsub(t, "(%d+)%.%d+ ", function(s)
48 it["d目前系统时间"] = "<strong>"..time2date(os.date("*t",os.date(os.time()))).."</strong>".." (启动时间: <strong>"..time2date(os.date("*t", os.time()-s)).."</strong>)"
49 it["e已开机时间"]=sec2string(s)
50 end)
52 t = myexec("ifconfig eth0")
53 string.gsub(t, "inet addr:(.-)%s+Bcast.-RX.-%((.-)%).-%((.-)%)", function(ip,rx, tx)
54 it["cIP地址"] = ip
55 it["n网络流量"] = "流入:<strong> "..rx.."</strong> / 流出:<strong> "..tx.."</strong>"
56 end)
58 -------------------------- Network -------------
59 -------------------------- Disks -------------
60 print([[<div class="sysinfo">
61 <table class="box">
62 <tr class="boxheader">
63 <td class="boxheader">系统信息</td>
64 </tr>
65 <tr class="boxbody">
66 <td class="boxbody">
67 <table border="0" width="100%" align="center">
68 ]])
69 a = {}
70 for n in pairs(it) do table.insert(a, n) end
71 table.sort(a)
72 for _,v in ipairs(a)
73 do print([[<tr valign="top"><td><strong>]]..string.sub(v,2,-1).."</strong></td><td>"..it[v].."</td></tr>") end
75 print("</table></td></tr></table>")