showstats.php3 7.35 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2006 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# All rights reserved.
#
include("defs.php3");
include("showstuff.php3");

#
# Standard Testbed Header
#
PAGEHEADER("Testbed Wide Stats");

#
# Only known and logged in users can end experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);

22 23 24 25
if (!isset($verbose)) {
     $verbose = 0;
}

26 27 28 29 30 31 32 33 34 35 36
# Page args,
if (! isset($showby)) {
    if ($isadmin) 
	$showby = "all";
    else
	$showby = "user";
}
if (! isset($which))
    $which = 0;
# Show just the last N records unless request is different.
if (!isset($records) || !strcmp($records, "")) {
37
    $records = 100;
38 39
}

40
echo "<b>Show: <a class='static' href='showexpstats.php3'>
Leigh Stoller's avatar
Leigh Stoller committed
41 42 43 44 45 46
                  Experiment Stats</a>";

if ($isadmin) {
    echo "<a class='static' href='showsumstats.php3'>, Summary Stats</a>\n";
}
echo "</b><br>\n";
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

# Set up where clause and menu.
$wclause = "";

echo "<b>Show by: ";

# By User. A specific user, or the current uid.
if ($showby != "user") {
    echo "<a class='static' href='showstats.php3?showby=user'>User</a>, ";
}
else {
    echo "User, ";
}
# Or All. For mere users, "all" would be confusing, so change the tag
# to "projects" to indicate its really just projects they are members of.
if ($showby != "all") {
    echo "<a class='static' href='showstats.php3?showby=all'>";
    if ($isadmin)
	echo "All</a>.";
    else
	echo "Project</a>.";
}
else {
    if ($isadmin)
	echo "All</a>.";
    else
	echo "Project</a>.";
}
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
echo "</b><br>\n";

# Refresh option
if ($isadmin) {
    echo "<b>Refresh every: ";
    echo "<a class='static' ".
	     "href='showstats.php3?showby=$showby&refreshrate=30'>30</a>, ";
    echo "<a class='static' ".
	     "href='showstats.php3?showby=$showby&refreshrate=60'>60</a>, ";
    echo "<a class='static' ".
	     "href='showstats.php3?showby=$showby&refreshrate=120'>120</a> ";
    echo "seconds.\n";
    echo "</b><br>\n";
}
echo "<br>\n";
90 91 92 93 94 95 96 97 98 99 100 101

# Determine what to do.
if ($showby == "user") {
    if ($which) {
	if ($which != $uid &&
	    ! TBUserInfoAccessCheck($uid, $which, $TB_USERINFO_READINFO)) {
	    USERERROR("You do not have permission to view stats for ".
		      "user $which!", 1);
	}
    }
    else
	$which = $uid;
102
    $wclause = "where t.uid='$which'";
103 104 105 106 107 108 109 110 111 112 113
}
elseif ($showby == "project") {
    if (! $which) {
	USERERROR("Must supply a project to view!", 1);
    }
    if (! TBProjAccessCheck($uid, $which, $which, $TB_PROJECT_READINFO)) {
	    USERERROR("You do not have permission to view stats for ".
		      "project $which!", 1);
    }
    $wclause = "where s.pid='$which'";
}
114 115 116 117
elseif ($showby == "expt") {
    if (!$which) {
	USERERROR("Must supply an experiment to view!", 1);
    }
118 119 120
    if (!TBvalid_integer($which)) {
	USERERROR("Invalid characters in $which!", 1);
    }
121 122 123 124 125 126 127

    #
    # We get an index. Must map that to a pid/eid to do the permission
    # check, and note that it might not be an current experiment. Not
    # sure I like this so I am not going to permit it for mere users
    # just yet.
    #
128 129 130 131 132 133 134 135 136
    $query_result =
	DBQueryFatal("select pid,eid from experiments where idx='$which'");
    if (mysql_num_rows($query_result) == 0) {
	USERERROR("No such experiment index $which!", 1);
    }
    $row   = mysql_fetch_array($query_result);
    $pid   = $row[pid];
    $eid   = $row[eid];

137 138 139 140 141 142 143
    if (!$isadmin) {
	if (! TBExptAccessCheck($uid, $pid, $eid, $TB_EXPT_READINFO)) {
	    USERERROR("You do not have permission to view stats for ".
		      "experiment $which!", 1);
	}
    }
    $wclause = "where t.exptidx='$which'";
144 145 146 147 148 149 150 151 152 153 154 155 156

    #
    # When showing a single experiment, put uid,pid,eid,idx in a header.
    # Less crap to look at.
    #
    echo "<center><font size=+1>".
	 "Experiment <b>".
         "<a href='showproject.php3?pid=$pid'>$pid</a>/".
	 "<a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a> ".
	 "(<a href='showexpstats.php3?record=$which'>$which</a>) ".
	 "</b></font>\n";
         "</center><br>";
    echo "<br>\n";
157
}
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
elseif ($showby == "all") {
    if ($which) {
	if (! TBProjAccessCheck($uid, $which, $which, $TB_PROJECT_READINFO)) {
	    USERERROR("You do not have permission to view stats for ".
		      "project $which!", 1);
	}
	$wclause = "where s.pid='$which'";
    }
    elseif (!$isadmin) {
        #
        # Get a project list for which the user has read permission.
        #
        $projlist = TBProjList($uid, $TB_PROJECT_READINFO);
	if (! count($projlist)) {
	    USERERROR("You do not have permission to view stats for any ".
		      "project!", 1);
	}
	while (list($project, $grouplist) = each($projlist)) {
	    $wclause .= "s.pid='$project' or ";
	}
	$wclause = "where $wclause 0";
    }
}
else {
    USERERROR("Bad page arguments!", 1);
}
184 185

$query_result =
186
    DBQueryFatal("select t.exptidx,s.pid,s.eid,t.action,t.exitcode,t.uid, ".
187 188
                 "       r.pnodes,t.idx as statno,t.start_time,t.end_time, ".
		 "       s.archive_idx,r.archive_tag ".
189 190
		 "  from testbed_stats as t ".
		 "left join experiment_stats as s on s.exptidx=t.exptidx ".
191
		 "left join experiment_resources as r on r.idx=t.rsrcidx ".
192
		 "$wclause ".
193
		 "order by t.end_time desc,t.idx desc limit $records");
194 195 196 197

if (mysql_num_rows($query_result) == 0) {
    USERERROR("No testbed stats records in the system!", 1);
}
198

199
echo "<table align=center border=1>
200 201 202 203 204 205 206 207 208 209 210 211 212 213
      <tr>";
if ($verbose) {
    echo "<th>#</th>";
}
if ($EXPOSEARCHIVE) {
    echo "  <th>Run</th>";
}
if ($verbose || $showby != "expt") {
    echo "  <th>Uid</th>
            <th>Pid</th>
            <th>Eid</th>
            <th>ExptIdx</th>";
}
echo "  <th>Start</th>
214
        <th>End</th>
215
        <th>Action (Nodes)</th>
216 217 218 219 220
        <th>ECode</th>";
if ($EXPOSEARCHIVE) {
        echo "<th>Archive</th>";
}
echo " </tr>\n";
221 222

while ($row = mysql_fetch_assoc($query_result)) {
223 224
    $idx     = $row[statno];
    $exptidx = $row[exptidx];
225 226
    $pid     = $row[pid];
    $eid     = $row[eid];
227
    $uid     = $row[uid];
228 229
    $start   = $row[start_time];
    $end     = $row[end_time];
230 231
    $action  = $row[action];
    $ecode   = $row[exitcode];
232
    $pnodes  = $row[pnodes];
233 234
    $archive_idx = $row[archive_idx];
    $archive_tag = $row[archive_tag];
235 236 237

    if (!isset($end))
	$end = "&nbsp";
238
	
239 240 241 242 243
    echo "<tr>";
    if ($verbose)
	echo "<td>$idx</td>";
    if ($EXPOSEARCHIVE) {
	if ($archive_idx && $archive_tag &&
244
	    ($action == "swapout" || $action == "swapmod")) {
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
	    echo "  <td align=center>
                       <a href=beginexp_html.php3?copyid=$exptidx:$archive_tag>
                       <img border=0 alt=Run src=greenball.gif></a></td>";
	}
	else {
	    echo "<td>&nbsp</td>\n";
	}
    }
    if ($verbose || $showby != "expt") {
	echo "<td>$uid</td>
              <td>$pid</td>
              <td>$eid</td>
              <td><a href=showexpstats.php3?record=$exptidx>$exptidx</a></td>";
    }
    echo "  <td>$start</td>
260
            <td>$end</td>\n";
261 262 263 264 265 266 267
    if (!$ecode && (strcmp($action, "preload") &&
		    strcmp($action, "destroy"))) {
	echo "<td>$action ($pnodes)</td>\n";
    }
    else {
	echo "<td>$action</td>\n";
    }
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
    echo " <td>$ecode</td>\n";
    if ($EXPOSEARCHIVE) {
	if ($archive_idx && $archive_tag &&
	    (strcmp($action, "swapout") == 0 ||
	     strcmp($action, "swapmod") == 0)) {
	    echo "<td>".
		 "<a href='cvsweb/cvswebwrap.php3/$exptidx/history/".
		          "$archive_tag/?exptidx=$exptidx'>$archive_tag</a>".
		 "</td>\n";
	}
	else {
	    echo "<td>&nbsp</td>\n";
	}
    }
    echo "</tr>\n";
283 284 285 286 287 288 289 290
}
echo "</table>\n";

#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>