From 744be4171f3386d3c45864007f9958ed80429fc2 Mon Sep 17 00:00:00 2001 From: adamch Date: Sun, 9 Dec 2007 21:21:02 +0000 Subject: [PATCH] Disk quota comparison --- quotas.mlt | 4 ++-- stats.sig | 5 ++--- stats.sml | 58 +++++++++++++++--------------------------------------- 3 files changed, 20 insertions(+), 47 deletions(-) diff --git a/quotas.mlt b/quotas.mlt index 9f6a04c..5f841bf 100644 --- a/quotas.mlt +++ b/quotas.mlt @@ -1,7 +1,7 @@ <% @header [("title", ["Disk usage stats"])] %> - + <% foreach du in Stats.getDiskUsage () do %> @@ -14,7 +14,7 @@ switch id of SOME id => %><% end -%> +%> <% end %>
User Blocks Files
User kB used
 
<% #blocks du %> <% #files du %>
<% #kbs du %>
diff --git a/stats.sig b/stats.sig index d0056be..cbca44b 100644 --- a/stats.sig +++ b/stats.sig @@ -12,9 +12,8 @@ sig * vhosts to kilobytes, and a mapping from usernames to their vhosts and bandwidth * totals. *) - type disk = {uname : string, (* UNIX username *) - blocks : int, (* Number of disk blocks used *) - files : int} (* Number of files used *) + type disk = {uname : string, (* UNIX username *) + kbs : int} (* Number of kilobytes space used *) val getDiskUsage : unit -> disk list (* Get /home disk usage statistics, in descending blocks order. *) diff --git a/stats.sml b/stats.sml index f1cb50a..12cf470 100644 --- a/stats.sml +++ b/stats.sml @@ -90,55 +90,29 @@ struct end type disk = {uname : string, - blocks : int, - files : int} + kbs : int} fun getDiskUsage () = let - val proc = Unix.execute ("/usr/bin/sudo", ["/usr/sbin/repquota", "-g", "/home"]) + val proc = Unix.execute ("/bin/sh", ["-c", "/usr/bin/sudo /usr/local/sbin/portal_quotas"]) val inf = Unix.textInstreamOf proc - fun skipUntilLine () = - 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 ignoreThis s = + String.isPrefix "Kerberos " s - 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 + fun loop acc = + case TextIO.inputLine inf of + NONE => acc + | SOME line => + case String.tokens Char.isSpace line of + [uname, kbs] => loop ({uname = uname, kbs = valOf (Int.fromString kbs)} :: acc) + | _ => + if ignoreThis line then + loop acc + else + raise Fail ("Bad quotas output: " ^ line) in - skipUntilLine (); - readData [] + loop [] before ignore (Unix.reap proc) end -- 2.20.1