-- -- Convenient functions for HTML output -- function td(content) return "" .. content .. "" end function th(style, content) if style then return ""..content.."" else return ""..content.."" end end function tr(style,...) if style then ret = "" else ret = "" end for i,s in ipairs(arg) do ret = ret .. s end ret = ret .. "\n" return ret end function h2(str) return "

"..str.."

\n" end -- Formats sensor information to HTML 'tr' function sensor_to_tr(id,sensor) return tr(nil, td(sensor["name"]), td(sensor["measure_last"]), td(sensor["measure_min"]), td(sensor["measure_max"])) end -- Formats number of bytes to string function format_mem_size(bytes) if (bytes == 0) then return "0" end if (bytes < 1024) then return bytes .. " o"; end mo_bytes = 1024 * 1024; if (bytes < mo_bytes) then return math.ceil(bytes / 1024) .. " Ko" end go_bytes = 1024 * mo_bytes; if (bytes < go_bytes) then return math.ceil(bytes / mo_bytes) .. " Mo" end return math.ceil(bytes / go_bytes) .. " Go" end -- Formats uptime to string function format_uptime(uptime) uptime_s = sysinfo["uptime"]%60 uptime_mn = math.floor( (sysinfo["uptime"] / 60) % 60) uptime_h = math.floor( (sysinfo["uptime"] / (60*60)) % 24) uptime_d = math.floor(sysinfo["uptime"] / (60*60*24)) return uptime_d .. "d " .. uptime_h .. "h " .. string.format("%02.d",uptime_mn) .. "mn " .. string.format("%02d",uptime_s) .. "s" end str = "

Psensor Monitoring Server

" if sysinfo then -- -- Uptime -- str = str .. "

Uptime: " .. format_uptime(sysinfo["uptime"]) .. "

" -- -- CPU -- str = str .. h2("CPU") str = str .. "" .. tr("title", th(nil,"Current usage"), th(nil,"Load 1mn"), th(nil,"Load 5mn"), th(nil,"Load 15mn")) str = str .. "" if sysinfo["load"] then str = str .. td(math.ceil(100*sysinfo["load"]) .. "%") else str = str .. td("N/A") end str = str .. td(string.format("%.2f",sysinfo["load_1mn"])) .. td(string.format("%.2f",sysinfo["load_5mn"])) .. td(string.format("%.2f",sysinfo["load_15mn"])) .. "" .. "
" -- -- Memory -- totalram = format_mem_size(sysinfo["totalram"] * sysinfo["mem_unit"]) freeram = format_mem_size(sysinfo["freeram"] * sysinfo["mem_unit"]) sharedram = format_mem_size(sysinfo["sharedram"] * sysinfo["mem_unit"]) bufferram = format_mem_size(sysinfo["bufferram"] * sysinfo["mem_unit"]) usedram = format_mem_size(sysinfo["totalram"] - sysinfo["freeram"]) totalswap = format_mem_size(sysinfo["totalswap"] * sysinfo["mem_unit"]) freeswap = format_mem_size(sysinfo["freeswap"] * sysinfo["mem_unit"]) usedswap = format_mem_size(sysinfo["totalswap"] - sysinfo["freeswap"]) str = str .. h2("Memory") .. "" .. tr("title", th(nil,""), th(nil,"Total"), th(nil,"Used"), th(nil,"Free"), th(nil,"Shared"), th(nil,"Buffer")) .. tr(nil, th(nil,"Memory"), td(totalram), td(usedram), td(freeram), td(sharedram), td(bufferram)) .. tr(nil, th(nil,"Swap"), td(totalswap), td(usedswap), td(freeswap)) .. "
" end -- -- Sensors -- if sensors then str = str .. "

Sensors

" .. "" .. "" for i,sensor in ipairs(sensors) do str = str .. sensor_to_tr(i,sensor) end str = str .. "
NameValueMinMax

psensor-server" end return str