showstats.php3 5.04 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# 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
26
27
28
29
30
31
32
# 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, "")) {
33
    $records = 100;
34
35
}

36
37
38
39
40
41
42
43
44
45
46
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
75
76
77
78
79
echo "<b>Show: <a class='static' href='showexpstats.php3'>
              Experiment Stats</a></b><br>\n";

# 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>.";
}
echo "</b><br><br>\n";

# 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;
    $wclause = "where s.creator='$which'";
80
    $records = 100;
81
82
83
84
85
86
87
88
89
90
}
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'";
91
    $records = 100;
92
}
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
elseif ($showby == "expt") {
    if (!$which) {
	USERERROR("Must supply an experiment to view!", 1);
    }

    #
    # 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.
    #
    if (!$isadmin) {
	$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];
	
	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'";
    $records = 100;
}
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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";
    }
144
    $records = 100;
145
146
147
148
}
else {
    USERERROR("Bad page arguments!", 1);
}
149
150

$query_result =
151
152
153
    DBQueryFatal("select s.*,t.*,r.*,t.idx as statno,t.tstamp as ttstamp ".
		 "  from testbed_stats as t ".
		 "left join experiment_stats as s on s.exptidx=t.exptidx ".
154
		 "left join experiment_resources as r on r.idx=t.rsrcidx ".
155
156
		 "$wclause ".
		 "order by t.tstamp desc,t.idx desc limit $records");
157
158
159
160
161

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

162
163
echo "<table align=center border=1>
      <tr>
164
        <th>#</th>
165
166
        <th>Pid</th>
        <th>Eid</th>
167
        <th>ExptIdx</th>
168
        <th>Time</th>
169
170
        <th>Action (Nodes)</th>
        <th>ECode</th>
171
      </tr>\n";
172
173

while ($row = mysql_fetch_assoc($query_result)) {
174
175
    $idx     = $row[statno];
    $exptidx = $row[exptidx];
176
177
    $pid     = $row[pid];
    $eid     = $row[eid];
178
    $when    = $row[ttstamp];
179
180
    $action  = $row[action];
    $ecode   = $row[exitcode];
181
    $pnodes  = $row[pnodes];
182
183
	
    echo "<tr>
184
            <td>$idx</td>
185
186
            <td>$pid</td>
            <td>$eid</td>
187
            <td><a href=showexpstats.php3?record=$exptidx>$exptidx</a></td>
188
189
190
191
192
193
194
195
196
            <td>$when</td>\n";
    if (!$ecode && (strcmp($action, "preload") &&
		    strcmp($action, "destroy"))) {
	echo "<td>$action ($pnodes)</td>\n";
    }
    else {
	echo "<td>$action</td>\n";
    }
    echo " <td>$ecode</td>
197
          </tr>\n";
198
199
200
201
202
203
204
205
}
echo "</table>\n";

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