Commit 0859dba7 authored by Leigh Stoller's avatar Leigh Stoller

Add admin/foreign_admin dashboard page.

parent 8e9ea331
<?php
#
# Copyright (c) 2000-2015 University of Utah and the Flux Group.
#
# {{{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");
#
# Number of experiments started over range of time periods.
#
$scales = array("Day" => (24 * 3600),
"Week" => (24 * 3600 * 7),
"Month" => (24 * 3600 * 30),
"Year" => (24 * 3600 * 365),
"Epoch" => time());
#
# Server side of getting dashboard stats.
#
function Do_GetStats()
{
global $scales;
$started = array();
foreach ($scales as $key => $age) {
$query_result =
DBQueryFatal("select ".
"(select count(uuid) from apt_instances ".
" where created > DATE_SUB(now(),interval $age second)),".
"(select count(uuid) from apt_instance_history ".
" where created > DATE_SUB(now(),interval $age second))");
$row = mysql_fetch_array($query_result);
$started[$key] = $row[0] + $row[1];
}
$dashboard = array("started" => $started,
"errors" => array("Day" => "n/a",
"Week" => "n/a",
"Month" => "n/a",
"Year" => "n/a",
"Epoch" => "n/a"));
#
# What are most recent swapins
#
$latest = array();
$query_result =
DBQueryFatal("select name,uuid,creator,creator_idx,".
" physnode_count,created ".
"from apt_instances ".
"order by created desc limit 5");
while ($row = mysql_fetch_array($query_result)) {
$name = $row["name"];
$uuid = $row["uuid"];
$creator = $row["creator"];
$creator_idx = $row["creator_idx"];
$pcount = $row["physnode_count"];
$created = $row["created"];
$latest[$name] = array("uuid" => $uuid,
"creator_idx" => $creator_idx,
"creator" => $creator,
"physnode_count" => $pcount,
"created" => $created);
}
$dashboard["latest"] = $latest;
#
# Who are the heaviest users
#
$users = array();
$query_result =
DBQueryFatal("select creator,creator_idx,count(creator) as ecount, ".
" sum(physnode_count) as pcount ".
"from apt_instances group by creator ".
"order by pcount desc limit 10");
while ($row = mysql_fetch_array($query_result)) {
$creator = $row["creator"];
$creator_idx = $row["creator_idx"];
$pcount = $row["pcount"];
$ecount = $row["ecount"];
$users[$creator] = array("creator_idx" => $creator_idx,
"physnode_count" => $pcount,
"experiment_count" => $ecount);
}
$dashboard["heaviest_users"] = $users;
#
# Who are the heaviest projects
#
$projects = array();
$query_result =
DBQueryFatal("select pid,count(pid) as ecount, ".
" sum(physnode_count) as pcount ".
"from apt_instances group by pid ".
"order by pcount desc limit 10");
while ($row = mysql_fetch_array($query_result)) {
$pid = $row["pid"];
$pcount = $row["pcount"];
$ecount = $row["ecount"];
$projects[$pid] = array("pid" => $pid,
"physnode_count" => $pcount,
"experiment_count" => $ecount);
}
$dashboard["heaviest_projects"] = $projects;
#
# Most popular profiles (since the Epoch).
#
$profiles = array();
$query_result =
DBQueryFatal("select p.uuid,p.name,count(h.profile_id) as count ".
" from apt_instance_history as h ".
"left join apt_profiles as p on p.profileid=h.profile_id ".
"group by profile_id order by count desc limit 10");
while ($row = mysql_fetch_array($query_result)) {
$name = $row["name"];
$count = $row["count"];
$uuid = $row["uuid"];
$profiles[$name] = array("name" => $name,
"uuid" => $uuid,
"count" => $count);
}
$dashboard["heaviest_profiles"] = $profiles;
SPITAJAX_RESPONSE($dashboard);
}
# Local Variables:
# mode:php
# End:
?>
<?php
#
# Copyright (c) 2000-2015 University of Utah and the Flux Group.
#
# {{{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("..");
include("defs.php3");
include_once("geni_defs.php");
chdir("apt");
include("quickvm_sup.php");
include_once("instance_defs.php");
$page_title = "Dash Board";
#
# Get current user.
#
RedirectSecure();
$this_user = CheckLoginOrRedirect();
$isadmin = (ISADMIN() ? 1 : 0);
if (! (ISADMIN() || ISFOREIGN_ADMIN())) {
SPITUSERERROR("You do not have permission to view the dashboard");
}
SPITHEADER(1);
# Place to hang the toplevel template.
echo "<div id='page-body'></div>\n";
echo "<script type='text/javascript'>\n";
echo " window.ISADMIN = $isadmin;\n";
echo "</script>\n";
echo "<script src='js/lib/bootstrap.js'></script>\n";
echo "<script src='js/lib/require.js' data-main='js/dashboard'></script>\n";
SPITFOOTER();
?>
require(window.APT_OPTIONS.configObject,
['underscore', 'js/quickvm_sup', 'moment',
'js/lib/text!template/dashboard.html'],
function (_, sup, moment, dashboardString)
{
'use strict';
var isadmin = 0;
var dashboardTemplate = _.template(dashboardString);
function initialize()
{
window.APT_OPTIONS.initialize(sup);
isadmin = window.ISADMIN;
DashboardLoop();
}
function DashboardLoop()
{
var callback = function(json) {
console.log(json);
var dashboard_html = dashboardTemplate({"dashboard": json.value,
"isadmin": isadmin});
$('#page-body').html(dashboard_html);
// Format dates with moment before display.
$('.format-date').each(function() {
var date = $.trim($(this).html());
if (date != "") {
$(this).html(moment($(this).html())
.format("ddd h:mm A"));
}
});
setTimeout(function f() { DashboardLoop() }, 5000);
}
var xmlthing = sup.CallServerMethod(null, "dashboard",
"GetStats", null);
xmlthing.done(callback);
}
$(document).ready(initialize);
});
......@@ -298,6 +298,7 @@ $PAGEHEADER_FUNCTION = function($thinheader = 0, $ignore1 = NULL,
My History</a></li>\n";
if (ISADMIN() || ISFOREIGN_ADMIN()) {
echo " <li class='divider'></li>\n";
echo " <li><a href='dashboard.php'>DashBoard</a></li>";
$then = time() - (30 * 3600 * 24);
echo " <li><a href='activity.php?min=$then'>
History Data</a></li>
......
......@@ -45,6 +45,11 @@ $routing = array("myprofiles" =>
"Do_CreateSecret",
"VerifySpeaksfor" =>
"Do_VerifySpeaksfor")),
"dashboard" =>
array("file" => "dashboard.ajax",
"guest" => true,
"methods" => array("GetStats" =>
"Do_GetStats")),
"instantiate" =>
array("file" => "instantiate.ajax",
"guest" => true,
......
<style>
.panel-body-dashboard {
padding: 5px;
}
</style>
<div class='row'>
<div class='col-sm-6'>
<div class='panel panel-default' id='experiments-started-panel'>
<div class="panel-heading">
<h5><center>Experiment Activity</center></h5>
</div>
<div class='panel-body panel-body-dashboard'>
<table class="table table-condensed table-bordered"
id='experiments-started-table'>
<thead>
<tr>
<td></td>
<% _.each(dashboard.started, function(value, key) { %>
<th><%- key %></th>
<% }); %>
</tr>
</thead>
<tbody>
<tr>
<td>Started</td>
<% _.each(dashboard.started, function(value, key) { %>
<td><%- value %></td>
<% }); %>
</tr>
<tr class="hidden">
<td>Errors</td>
<% _.each(dashboard.errors, function(value, key) { %>
<td><%- value %></td>
<% }); %>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class='col-sm-6'>
<div class='panel panel-default' id='experiments-latest-panel'>
<div class="panel-heading">
<h5><center>Latest Experiments</center></h5>
</div>
<div class='panel-body panel-body-dashboard'>
<table class="table table-condensed table-bordered"
id='experiments-latest-table'>
<thead>
<tr>
<th>Name</th>
<th>Creator</th>
<th>Nodes</th>
<th>Created</th>
</tr>
</thead>
<tbody>
<% _.each(dashboard.latest, function(value, key) { %>
<tr>
<% if (!isadmin) { %>
<td><%- key %></td>
<td><%- value.creator %></td>
<% } %>
<% if (isadmin) { %>
<td><a href="status.php?uuid=<%- value.uuid %>">
<%- key %></a></td>
<td><a href="https://www.emulab.net/showuser.php3?user=<%- value.creator_idx %>"><%- value.creator %></a></td>
<% } %>
<td><%- value.physnode_count %></td>
<td class="format-date"><%- value.created %></td>
</tr>
<% }); %>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class='row'>
<div class='col-sm-4'>
<div class='panel panel-default' id='experiments-users-panel'>
<div class="panel-heading">
<h5><center>Heaviest Users (Current)</center></h5>
</div>
<div class='panel-body panel-body-dashboard'>
<table class="table table-condensed table-bordered"
id='experiments-latest-table'>
<thead>
<tr>
<th>Name</th>
<th>Nodes</th>
<th>Expts</th>
</tr>
</thead>
<tbody>
<% _.each(dashboard.heaviest_users, function(value, key) { %>
<tr>
<% if (!isadmin) { %>
<td><%- key %></td>
<% } %>
<% if (isadmin) { %>
<td><a href="https://www.emulab.net/showuser.php3?user=<%- value.creator_idx %>"><%- key %></a></td>
<% } %>
<td><%- value.physnode_count %></td>
<td><%- value.experiment_count %></td>
</tr>
<% }); %>
</tbody>
</table>
</div>
</div>
</div>
<div class='col-sm-4'>
<div class='panel panel-default' id='experiments-projects-panel'>
<div class="panel-heading">
<h5><center>Heaviest Projects (Current)</center></h5>
</div>
<div class='panel-body panel-body-dashboard'>
<table class="table table-condensed table-bordered"
id='experiments-latest-table'>
<thead>
<tr>
<th>Name</th>
<th>Nodes</th>
<th>Expts</th>
</tr>
</thead>
<tbody>
<% _.each(dashboard.heaviest_projects, function(value, key) { %>
<tr>
<% if (!isadmin) { %>
<td><%- key %></td>
<% } %>
<% if (isadmin) { %>
<td><a href="https://www.emulab.net/showproject.php3?pid=<%- key %>"><%- key %></a></td>
<% } %>
<td><%- value.physnode_count %></td>
<td><%- value.experiment_count %></td>
</tr>
<% }); %>
</tbody>
</table>
</div>
</div>
</div>
<div class='col-sm-4'>
<div class='panel panel-default' id='profiles-panel'>
<div class="panel-heading">
<h5><center>Popular Profiles (Epoch)</center></h5>
</div>
<div class='panel-body panel-body-dashboard'>
<table class="table table-condensed table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<% _.each(dashboard.heaviest_profiles, function(value, key) { %>
<tr>
<td><a href="show-profile.php?uuid=<%- value.uuid %>">
<%- value.name %></a></td>
<td><%- value.count %></td>
</tr>
<% }); %>
</tbody>
</table>
</div>
</div>
</div>
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment