sumstats.ajax 4.1 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2018 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file 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 Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
#
chdir("..");
chdir("apt");
include_once("instance_defs.php");

#
# Server side of getting summary info
#
function Do_GetDurationInfo()
{
    $duration_info = array();
    
    #
    # Gather up info about experiment duration for graphing.
    #
    $durations = array();
    $average   = 0;
    $stddev    = 0;
    
    $query_result =
        DBQueryFatal("select count(*) as count, ".
                     "  ceil((UNIX_TIMESTAMP(destroyed) - ".
45
                     "    UNIX_TIMESTAMP(started)) / (3600)) as duration ".
46 47
                     "from apt_instance_history ".
                     "where ceil((UNIX_TIMESTAMP(destroyed) - ".
48
                     "    UNIX_TIMESTAMP(started)) / (3600)) <= 36 " .
49 50 51 52 53 54 55 56 57
                     "group by duration order by duration desc");
    while ($row = mysql_fetch_array($query_result)) {
        $count     = $row["count"];
        $duration  = $row["duration"];

        $durations[] = array("x" => $duration, "y" => intval($count));
    }
    $query_result =
        DBQueryFatal("select avg(ceil((UNIX_TIMESTAMP(destroyed) - ".
58
                     "    UNIX_TIMESTAMP(started)) / (3600))), ".
59
                     "  std(ceil((UNIX_TIMESTAMP(destroyed) - ".
60
                     "    UNIX_TIMESTAMP(started)) / (3600))) ".
61 62
                     "from apt_instance_history ".
                     "where ceil((UNIX_TIMESTAMP(destroyed) - ".
63
                     "    UNIX_TIMESTAMP(started)) / (3600)) <= 36");
64 65 66 67 68 69 70 71 72 73 74 75 76
    $row = mysql_fetch_array($query_result);
    $average = $row[0];
    $stddev  = $row[1];
    
    $duration_info["oneday"] = array("durations" => $durations,
                                     "average"   => $average,
                                     "stddev"    => $stddev);

    $durations = array();
    
    $query_result =
        DBQueryFatal("select count(*) as count, ".
                     "  ceil((UNIX_TIMESTAMP(destroyed) - ".
77
                     "    UNIX_TIMESTAMP(started)) / (3600 * 24)) as duration ".
78 79
                     "from apt_instance_history ".
                     "where ceil((UNIX_TIMESTAMP(destroyed) - ".
80
                     "    UNIX_TIMESTAMP(started)) / (3600 * 24)) <= 30 " .
81 82 83 84 85 86 87 88 89 90 91
                     "group by duration order by duration asc");
    # Throw away day one.
    $row = mysql_fetch_array($query_result);
    while ($row = mysql_fetch_array($query_result)) {
        $count     = $row["count"];
        $duration  = $row["duration"];

        $durations[] = array("x" => $duration, "y" => intval($count));
    }
    $query_result =
        DBQueryFatal("select avg(ceil((UNIX_TIMESTAMP(destroyed) - ".
92
                     "    UNIX_TIMESTAMP(started)) / (3600 * 24))), ".
93
                     "  std(ceil((UNIX_TIMESTAMP(destroyed) - ".
94
                     "    UNIX_TIMESTAMP(started)) / (3600 * 24))) ".
95 96
                     "from apt_instance_history ".
                     "where ceil((UNIX_TIMESTAMP(destroyed) - ".
97
                     "    UNIX_TIMESTAMP(started)) / (3600 * 24)) <= 30");
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
    $row = mysql_fetch_array($query_result);
    $average = $row[0];
    $stddev  = $row[1];
    
    $duration_info["month"] = array("durations" => $durations,
                                    "average"   => $average,
                                    "stddev"    => $stddev);

    SPITAJAX_RESPONSE($duration_info);
}

# Local Variables:
# mode:php
# End:
?>