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