5 function redblue_img(red
, blue
)
6 wred
= red
*300/(red
+blue
)
7 wred
= string.format("%d", wred
)
9 return "<img src=images/red.gif width="..wred
.." height=10><img src=images/blue.gif width="..wblue
.." height=10>"
14 -------------------------- Hardware -------------
15 io
.input("/proc/meminfo")
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
)
22 then muse
= string.format("%.2fGB", (mem
-mfree
)/1024/1024)
23 else muse
= string.format("%.2fMB", (mem
-mfree
)/1024)
26 if (tonumber(mem
) > 1024*1024)
27 then mem
= string.format("%.2fGB", mem
/1024/1024)
28 else mem
= string.format("%.2fMB", mem
/1024)
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)
38 if (tonumber(swap
) > 1024*1024) then swap
= string.format("%.2fGB", swap
/1024/1024)
39 else swap
= string.format("%.2fMB", swap
/1024)
41 it
["k虚拟内存"] = _img
.."(已使用"..muse
.." / 共"..swap
..")"
43 io
.input("/proc/cpuinfo")
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
)
58 t
= myexec("ifconfig br0")
59 string.gsub(t
, "inet addr:(.-)%s+Bcast.-RX.-%((.-)%).-%((.-)%)", function(ip
,rx
, tx
)
61 it
["n网络流量"] = "流入:<strong> "..rx
.."</strong> / 流出:<strong> "..tx
.."</strong>"
64 -------------------------- Network -------------
65 -------------------------- Disks -------------
66 print([[<div class="sysinfo">
68 <tr class="boxheader">
69 <td class="boxheader">系统信息</td>
73 <table border="0" width="100%" align="center">
76 for n
in pairs(it
) do table.insert(a
, n
) end
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>")