Disk quota comparison
authorAdam Chlipala <adamc@hcoop.net>
Sun, 9 Dec 2007 21:21:02 +0000 (21:21 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Sun, 9 Dec 2007 21:21:02 +0000 (21:21 +0000)
quotas.mlt
stats.sig
stats.sml

index 9f6a04c..5f841bf 100644 (file)
@@ -1,7 +1,7 @@
 <% @header [("title", ["Disk usage stats"])] %>
 
 <table>
-<tr> <td align="right"><b>User</b></td> <td><b>Blocks</b></td> <td><b>Files</b></td> </tr>
+<tr> <td align="right"><b>User</b></td> <td><b>kB used</b></td> </tr>
 <tr><td>&nbsp;</td></tr>
 
 <% foreach du in Stats.getDiskUsage () do %>
@@ -14,7 +14,7 @@
        switch id of
                  SOME id => %></a><%
        end
-%></td> <td><% #blocks du %></td> <td><% #files du %></td> </tr>
+%></td> <td><% #kbs du %></td> </tr>
 <% end %>
 
 </table>
index d0056be..cbca44b 100644 (file)
--- 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. *)
index f1cb50a..12cf470 100644 (file)
--- 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