/* ************************************************************************ */ /* */ /* Tora - Neko Application Server */ /* Copyright (c)2008 Motion-Twin */ /* */ /* This library is free software; you can redistribute it and/or */ /* modify it under the terms of the GNU Lesser General Public */ /* License as published by the Free Software Foundation; either */ /* version 2.1 of the License, or (at your option) any later version. */ /* */ /* This library is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ /* Lesser General Public License or the LICENSE file for more details. */ /* */ /* ************************************************************************ */ import Infos; class Admin { static function w(str) { neko.Lib.println(str); } static function fmt( v : Float ) { return Math.round(v * 10) / 10; } static function list( a : Iterable ) { w(""); } static function title( s : String ) { w("

"+s+"

"); } static function table( headers : Array, list : Iterable, f : T -> Array ) { w(''); w(""); for( h in headers ) w(""); w(""); for( i in list ) { w(""); for( x in f(i) ) w(""); w(""); } w("
"+h+"
"+Std.string(x)+"
"); } static var TABID = 0; static var TABS = new Array(); static function tab( s : String, f ) { var id = TABID++; w(''+s+''); TABS.push(function() { w(''); }); } static function displayTabs() { for( t in TABS ) t(); w(''); } static function main() { w(""); w(""); w("Tora Admin"); w(''); w(''); w(""); w(""); title("Tora Admin"); var command : String -> String -> Void = neko.Lib.load("mod_neko","tora_command",2); var params = neko.Web.getParams(); var cmd = params.get("command"); if( cmd != null ) { var t = neko.Sys.time(); command(cmd,params.get("p")); w("

Command "+cmd+" took "+fmt(neko.Sys.time() - t)+"s to execute

"); } var mem = neko.vm.Gc.stats(); var infos : Infos = neko.Lib.load("mod_neko","tora_infos",0)(); var busy = 0; var cacheHits = 0; for( t in infos.threads ) if( t.file != null ) busy++; for( f in infos.files ) cacheHits += f.cacheHits; list([ "Uptime : "+fmt(infos.upTime)+"s", "Threads : "+busy+" / "+infos.threads.length, "Queue size : "+infos.queue, "Memory : "+Std.int((mem.heap - mem.free)/1024)+" / "+Std.int(mem.heap/1024)+" KB", "Total hits : "+infos.hits+" ("+fmt(infos.hits/infos.upTime)+"/sec)", "Cache hits : "+cacheHits+" ("+fmt(cacheHits*100/infos.hits)+"%)", ]); tab("Files",function() { infos.files.sort(function(f1,f2) return (f2.loads + f2.cacheHits) - (f1.loads + f1.cacheHits)); table( ["File","Loads","Cache Hits","Instances","KB/hit","ms/hit"], infos.files, function(f:FileInfos) { var tot = f.loads + f.cacheHits; return [f.file,f.loads,f.cacheHits,f.cacheCount,fmt(f.bytes/(1024.0 * tot)),fmt(f.time*1000/tot)]; } ); }); tab("Threads",function() { var count = 1; table( ["TID","Hits","E","Status","Time"], infos.threads, function(t:ThreadInfos) return [count++,t.hits,t.errors,if( t.file == null ) "idle" else t.url,fmt(t.time)+"s"] ); }); displayTabs(); w(''); w(''); } }