Skip to content

Commit

Permalink
Dashboard: Job Totals Widget
Browse files Browse the repository at this point in the history
Adds a widget to the dashboard which shows
the number of files and jobs available as
well as the stored bytes.
  • Loading branch information
fbergkemper committed May 24, 2017
1 parent 927b04d commit b32494d
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 0 deletions.
1 change: 1 addition & 0 deletions module/Dashboard/config/module.config.php
Expand Up @@ -62,6 +62,7 @@
'JobsLastStatus' => __DIR__ . '/../view/partial/JobsLastStatus.phtml',
'LastDirectorMessages' => __DIR__ . '/../view/partial/LastDirectorMessages.phtml',
'RunningJobs' => __DIR__ . '/../view/partial/RunningJobs.phtml',
'JobTotals' => __DIR__ . '/../view/partial/JobTotals.phtml',
),
),
'translator' => array(
Expand Down
38 changes: 38 additions & 0 deletions module/Dashboard/src/Dashboard/Controller/DashboardController.php
Expand Up @@ -31,6 +31,9 @@

class DashboardController extends AbstractActionController
{
/**
* Variables
*/
protected $directorModel = null;
protected $jobModel = null;
protected $dashboardModel = null;
Expand All @@ -42,6 +45,11 @@ class DashboardController extends AbstractActionController
"llist"
);

/**
* Index Action
*
* @return object
*/
public function indexAction()
{
$this->RequestURIPlugin()->setRequestURI();
Expand All @@ -63,6 +71,11 @@ public function indexAction()
return new ViewModel();
}

/**
* Get Data Action
*
* @return object
*/
public function getDataAction()
{
$this->RequestURIPlugin()->setRequestURI();
Expand Down Expand Up @@ -155,6 +168,16 @@ public function getDataAction()
echo $e->getMessage();
}
}
elseif($data == "jobtotals") {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getJobModel()->getJobTotals($this->bsock);
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
}
}
elseif($data == "dirdmsg") {
try {
$this->bsock = $this->getServiceLocator()->get('director');
Expand All @@ -177,6 +200,11 @@ public function getDataAction()

}

/**
* Get Director Model
*
* @return object
*/
public function getDirectorModel()
{
if(!$this->directorModel) {
Expand All @@ -186,6 +214,11 @@ public function getDirectorModel()
return $this->directorModel;
}

/**
* Get Job Model
*
* @return object
*/
public function getJobModel()
{
if(!$this->jobModel) {
Expand All @@ -195,6 +228,11 @@ public function getJobModel()
return $this->jobModel;
}

/**
* Get Dashboard Model
*
* @return object
*/
public function getDashboardModel()
{
if(!$this->dashboardModel) {
Expand Down
33 changes: 33 additions & 0 deletions module/Dashboard/view/dashboard/dashboard/index.phtml
Expand Up @@ -38,6 +38,7 @@ $this->headTitle($title);
</div>

<div class="col-md-4">
<?php echo $this->partial('JobTotals'); ?>
<?php echo $this->partial('RunningJobs'); ?>
</div>

Expand Down Expand Up @@ -109,6 +110,34 @@ $this->headTitle($title);
});
}

function getJobTotals() {
$.ajax({
url : '<?php echo $this->url('dashboard', array('action' => 'getData'), null) . '?data=jobtotals'; ?>',
dataType: 'json',
timeout: 10000,
success: function(data) {
$('.job-totals-container').empty();
$('.job-totals-container').append(
'<div class="row"><div class="col-xs-1"><strong><?php echo $this->translate("Jobs"); ?></strong></div><div class="col-xs-3"><span class="text-muted">'+data.jobs+'</span></div></div>' +
'<div class="row"><div class="col-xs-1"><strong><?php echo $this->translate("Files"); ?></strong></div><div class="col-xs-3"><span class="text-muted">'+data.files+'</span></div></div>' +
'<div class="row"><div class="col-xs-1"><strong><?php echo $this->translate("Bytes"); ?></strong></div><div class="col-xs-3"><span class="text-muted">'+formatBytes(data.bytes)+'</span></div></div>'
);
},
error: function() {
$('.job-totals-container').empty();
$('.job-totals-container').append('Error fetching data.');
},
timeout: function() {
$('.job-totals-container').empty();
$('.job-totals-container').append('Timeout fetching data.');
},
parsererror: function() {
$('.job-totals-container').empty();
$('.job-totals-container').append('Parsererror');
}
});
}

function getJobsLastStatus() {
table_jobs_last_status = $('#jobs-last-status').DataTable({
"ajax": {
Expand Down Expand Up @@ -230,6 +259,7 @@ $this->headTitle($title);
function refreshPartials() {
getRunningJobs();
getJobsPast24h();
getJobTotals();
table_jobs_last_status.ajax.reload( null, false );
}

Expand All @@ -244,6 +274,9 @@ $this->headTitle($title);
getJobsPast24h();
setInterval('getJobsPast24h()', <?php echo $_SESSION['bareos']['dashboard_autorefresh_interval']; ?>);

getJobTotals();
setInterval('getJobTotals()', <?php echo $_SESSION['bareos']['dashboard_autorefresh_interval']; ?>);

getJobsLastStatus();
setInterval( function () { table_jobs_last_status.ajax.reload( null, false ); }, <?php echo $_SESSION['bareos']['dashboard_autorefresh_interval']; ?>);
}
Expand Down
40 changes: 40 additions & 0 deletions module/Dashboard/view/partial/JobTotals.phtml
@@ -0,0 +1,40 @@
<?php

/**
*
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2017 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/

?>

<div class="panel panel-default">

<div class="panel-heading">
<h3 class="panel-title"><?php echo $this->translate('Job Totals'); ?>
<a href="#" onClick="refreshPartials();return false;" title="Refresh"><span class="glyphicon glyphicon-refresh pull-right" aria-hidden="true"></span></a>
</h3>
</div>

<div class="panel-body">
<div class="job-totals-container"></div>
</div>

</div>

0 comments on commit b32494d

Please sign in to comment.