X-Git-Url: http://git.hcoop.net/hcoop/portal.git/blobdiff_plain/b13a9a3757552fdefb98f58035790a685b464b6d..2cce576765e93c1f2b34397adbdae6c0e57509a2:/stats.sml diff --git a/stats.sml b/stats.sml index f1cb50a..51f23f8 100644 --- a/stats.sml +++ b/stats.sml @@ -89,57 +89,63 @@ struct before TextIO.closeIn inf end - type disk = {uname : string, - blocks : int, - files : int} + fun getWebbwUser {user, last} = + let + val {vhosts, users, ...} = getWebbw last + in + case List.find (fn {user = u, ...} => u = user) users of + NONE => {total = 0, vhosts = []} + | SOME {hosts, size, ...} => + {total = size, vhosts = List.filter (fn {host, ...} => List.exists (fn host' => host' = host) hosts) vhosts} + end + + + type disk = {uname : string, + kbs : int} + + structure StringKey = struct + type ord_key = string + val compare = String.compare + end + + structure SM = BinaryMapFn(StringKey) fun getDiskUsage () = let - val proc = Unix.execute ("/usr/bin/sudo", ["/usr/sbin/repquota", "-g", "/home"]) + val proc = Unix.execute ("/bin/sh", ["-c", "/usr/bin/vos listvol deleuze"]) val inf = Unix.textInstreamOf proc - fun skipUntilLine () = + fun loop acc = case TextIO.inputLine inf of - NONE => raise Fail "No dividing line found in repquota output" - | SOME s => - if String.sub (s, 0) = #"-" then - () - else - skipUntilLine () - - fun readData acc = - let - fun done () = - ListMergeSort.sort (fn (d1, d2) => - #blocks d1 < #blocks d2) acc - in - case TextIO.inputLine inf of - NONE => done () - | SOME s => - case String.tokens Char.isSpace s of - [uname, "--", blocks, bsoft, bhard, files, fsoft, fhard] => - readData ({uname = uname, - blocks = valOf (Int.fromString blocks), - files = valOf (Int.fromString files)} :: acc) - | [uname, "+-", blocks, bsoft, bhard, _, files, fsoft, fhard] => - readData ({uname = uname, - blocks = valOf (Int.fromString blocks), - files = valOf (Int.fromString files)} :: acc) - | [uname, "-+", blocks, bsoft, bhard, files, fsoft, fhard, _] => - readData ({uname = uname, - blocks = valOf (Int.fromString blocks), - files = valOf (Int.fromString files)} :: acc) - | [uname, "++", blocks, bsoft, bhard, _, files, fsoft, fhard, _] => - readData ({uname = uname, - blocks = valOf (Int.fromString blocks), - files = valOf (Int.fromString files)} :: acc) - | [] => done () - | _ => raise Fail ("Bad repquota line: " ^ s) - end + NONE => acc + | SOME line => + case String.tokens Char.isSpace line of + [vol, _, _, kbs, _, _] => + let + val kbsOld = case SM.find (acc, vol) of + NONE => 0 + | SOME n => n + + val uname = case String.tokens (fn ch => ch = #".") vol of + [_, uname] => + ((Posix.SysDB.getpwnam uname; + SOME uname) + handle OS.SysErr _ => NONE) + | _ => NONE + + val acc = case uname of + NONE => acc + | SOME uname => SM.insert (acc, uname, valOf (Int.fromString kbs) + kbsOld) + in + loop acc + end + | _ => acc + + val _ = TextIO.inputLine inf + val users = map (fn (uname, kbs) => {uname = uname, kbs = kbs}) (SM.listItemsi (loop SM.empty)) in - skipUntilLine (); - readData [] - before ignore (Unix.reap proc) + ignore (Unix.reap proc); + ListMergeSort.sort (fn ({kbs = kbs1, ...}, {kbs = kbs2, ...}) => kbs1 < kbs2) users end end