From: Adam Chlipala Date: Sun, 9 Dec 2007 19:26:16 +0000 (+0000) Subject: webbw is back X-Git-Url: http://git.hcoop.net/bpt/portal.git/commitdiff_plain/b13a9a3757552fdefb98f58035790a685b464b6d webbw is back --- diff --git a/header.mlt.in b/header.mlt.in index fb97c49..9ea5714 100644 --- a/header.mlt.in +++ b/header.mlt.in @@ -38,11 +38,11 @@ Support requests
  • Other support request
  • - + +
    Public pages
    diff --git a/stats.sig b/stats.sig index 8bf823c..d0056be 100644 --- a/stats.sig +++ b/stats.sig @@ -4,7 +4,9 @@ sig hostname : string, (* Internet hostname *) id : string} (* Name of stats directory *) - val getWebbw : int -> int * (host * int) list * (string * host list * int) list + val getWebbw : int -> {total : int, + vhosts: {host : host, size : int} list, + users : {user : string, hosts : host list, size : int} list} (* Get web bandwidth usage stats. The argument tells how many months ago * to look for the data. The return gives the total b/w usage, a mapping from * vhosts to kilobytes, and a mapping from usernames to their vhosts and bandwidth diff --git a/stats.sml b/stats.sml index db719b3..f1cb50a 100644 --- a/stats.sml +++ b/stats.sml @@ -8,14 +8,24 @@ struct hostname : string, id : string} - fun checkSsl host = - case String.fields (fn ch => ch = #".") host of - first::rest => - (case String.fields (fn ch => ch = #"_") first of - [first, "ssl"] => {ssl = true, hostname = String.concatWith "." (first::rest), - id = host} - | _ => {ssl = false, hostname = host, id = host}) - | _ => {ssl = false, hostname = host, id = host} + fun checkSsl (node, host) = + let + val id = case String.tokens (fn ch => ch = #".") host of + [] => node ^ "/" ^ host + | first :: rest => + case rev (String.tokens (fn ch => ch = #"_") first) of + "ssl" :: rest' => node ^ "/" ^ String.concatWith "_" (rev rest') + ^ "." ^ String.concatWith "." rest ^ ".ssl" + | _ => node ^ "/" ^ host + in + case String.fields (fn ch => ch = #".") host of + first::rest => + (case String.fields (fn ch => ch = #"_") first of + [first, "ssl"] => {ssl = true, hostname = String.concatWith "." (first::rest), + id = id} + | _ => {ssl = false, hostname = host, id = id}) + | _ => {ssl = false, hostname = host, id = id} + end fun getWebbw last = let @@ -41,8 +51,11 @@ struct (NONE | SOME "\n") => List.rev L | SOME l => case String.tokens (fn ch => Char.isSpace ch orelse ch = #":") l of - [d, n] => readEm ((checkSsl d, valOf (Int.fromString n)) :: L) - | _ => raise Fail "Bad row in webbw" + [d, n] => + (case String.tokens (fn ch => ch = #"@") d of + [d, node] => readEm ({host = checkSsl (node, d), size = valOf (Int.fromString n)} :: L) + | _ => raise Fail ("Bad row in webbw [2]: " ^ l)) + | _ => raise Fail ("Bad row in webbw [1]: " ^ l) fun splitLast [] = raise Fail "Not enough items for splitLast" | splitLast [x] = ([], x) @@ -61,13 +74,18 @@ struct d :: rest => let val (l, x) = splitLast rest + + fun split s = + case String.tokens (fn ch => ch = #"@") s of + [host, node] => (node, host) + | _ => raise Fail ("Bad row in webbw [3]: " ^ s) in - readGroups ((d, map checkSsl l, valOf (Int.fromString x)) :: L) + readGroups ({user = d, hosts = map (checkSsl o split) l, size = valOf (Int.fromString x)} :: L) end - | _ => raise Fail "Bad row in webbw, part 2" + | _ => raise Fail ("Bad row in webbw [4]: " ^ l) in TextIO.inputLine inf; - (sum, readEm [], readGroups []) + {total = sum, vhosts = readEm [], users = readGroups []} before TextIO.closeIn inf end diff --git a/webbw.mlt b/webbw.mlt index 95a8591..272a281 100644 --- a/webbw.mlt +++ b/webbw.mlt @@ -1,6 +1,6 @@ <% @header [("title", ["Web usage stats"])] %> -Web virtual host bandwidth (bandwidth usage of Apache sites in this calendar month)
    +Web virtual host bandwidth (bandwidth usage of Apache sites <% case $"last" of "1" => "last month" | "2" => "two months ago" | _ => "this calendar month" %>)
    <% if $"last" = "1" then %> [Previous] | [Current] <% elseif $"last" = "2" then %> @@ -10,18 +10,18 @@ <% end %>

    -<% val (sum, doms, groups) = iff $"last" = "" then +<% val stats = iff $"last" = "" then Stats.getWebbw 0 else Stats.getWebbw (Web.stoi ($"last")) %> - + -<% foreach (d, n) in doms do %> - +<% foreach dom in #vhosts stats do %> + <% end %>
    Bandwidth (kB)
    Total Apache bandwidth <% sum %>
    Total Apache bandwidth <% #total stats %>
     
    <% #hostname d %> [detail]<% n %>
    <% #hostname (#host dom) %><% if #ssl (#host dom) then %> (SSL)<% end %> [detail]<% #size dom %>
    @@ -34,12 +34,12 @@ Bandwidth (kB)   -<% foreach (gr, ds, n) in groups do %> - <% gr %> - <% foreach dom in ds do %> - [<% #hostname dom %> (S)] +<% foreach group in #users stats do %> + <% #user group %> + <% foreach dom in #hosts group do %> + [<% #hostname dom %><% if #ssl dom then %> (SSL)<% end %> (S)] <% end %> - <% n %> + <% #size group %> <% end %>