forked from bacula-web/bacula-web
/
index.php
277 lines (214 loc) · 10.6 KB
/
index.php
1
2
3
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
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
80
81
82
83
84
85
86
87
88
89
90
91
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004 Juan Luis Frances Jimenez |
| Copyright 2010-2015, Davide Franco |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| 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 General Public License for more details. |
+-------------------------------------------------------------------------+
*/
session_start();
include_once( 'core/global.inc.php' );
// Initialise view and model
$view = new CView();
$dbSql = null;
try {
$dbSql = new Bweb($view);
require_once('core/const.inc.php');
// Custom period for dashboard
$no_period = array(FIRST_DAY, NOW);
$last_day = array(LAST_DAY, NOW);
// Default period (last day)
$custom_period = $last_day;
$selected_period = 'last_day';
if (isset($_POST['period_selector'])) {
$selected_period = CHttpRequest::get_Value('period_selector');
$view->assign('custom_period_list_selected', $selected_period);
switch($selected_period) {
case 'last_day':
$custom_period = array( LAST_DAY, NOW);
break;
case 'last_week':
$custom_period = array( LAST_WEEK, NOW);
break;
case 'last_month':
$custom_period = array( LAST_MONTH, NOW);
break;
case 'since_bot':
$custom_period = $no_period;
break;
} // end switch
} else {
$view->assign('custom_period_list_selected', $selected_period);
}
$custom_period_list = array( 'last_day' => 'Last 24 hours',
'last_week' => 'Last week',
'last_month' => 'Last month',
'since_bot' => 'Since BOT');
$view->assign('custom_period_list', $custom_period_list);
// Set period start - end for widget header
$view->assign('literal_period', strftime("%a %e %b %Y", $custom_period[0]).' to ' . strftime("%a %e %b %Y", $custom_period[1]));
// Running, completed, failed, waiting and canceled jobs status over last 24 hours
$view->assign('running_jobs', Jobs_Model::count_Jobs($dbSql->db_link, $custom_period, 'running'));
$view->assign('completed_jobs', Jobs_Model::count_Jobs($dbSql->db_link, $custom_period, 'completed'));
$view->assign('failed_jobs', Jobs_Model::count_Jobs($dbSql->db_link, $custom_period, 'failed'));
$view->assign('waiting_jobs', Jobs_Model::count_Jobs($dbSql->db_link, $custom_period, 'waiting'));
$view->assign('canceled_jobs', Jobs_Model::count_Jobs($dbSql->db_link, $custom_period, 'canceled'));
// Stored files number
$view->assign('stored_files', CUtils::format_Number(Jobs_Model::getStoredFiles($dbSql->db_link, $no_period)));
// Overall stored bytes
$view->assign('stored_bytes', CUtils::Get_Human_Size(Jobs_Model::getStoredBytes($dbSql->db_link, $no_period)));
// Database size
$view->assign('database_size', Database_Model::get_Size($dbSql->db_link, $dbSql->catalog_current_id));
// Total bytes and files stored over the last 24 hours
$view->assign('bytes_last', CUtils::Get_Human_Size(Jobs_Model::getStoredBytes($dbSql->db_link, $custom_period)));
$view->assign('files_last', CUtils::format_Number(Jobs_Model::getStoredFiles($dbSql->db_link, $custom_period)));
// Number of clients
$view->assign('clients', Clients_Model::count($dbSql->db_link));
// Defined Jobs and Filesets
$view->assign('defined_filesets', FileSets_Model::count($dbSql->db_link));
$view->assign('defined_jobs', Jobs_Model::count_Job_Names($dbSql->db_link));
// Incremental, Differential and Full jobs over the last 24 hours
$view->assign('incr_jobs', Jobs_Model::count_Jobs($dbSql->db_link, $custom_period, null, J_INCR));
$view->assign('diff_jobs', Jobs_Model::count_Jobs($dbSql->db_link, $custom_period, null, J_DIFF));
$view->assign('full_jobs', Jobs_Model::count_Jobs($dbSql->db_link, $custom_period, null, J_FULL));
// Volumes disk usage
$volumes_size = Volumes_Model::getDiskUsage($dbSql->db_link);
$view->assign('volumes_size', CUtils::Get_Human_Size($volumes_size));
// Pools count
$view->assign('pools_nb', Pools_Model::count($dbSql->db_link));
// Backup Job list
$view->assign('jobs_list', Jobs_Model::get_Jobs_List($dbSql->db_link));
// Clients list
$view->assign('clients_list', Clients_Model::getClients($dbSql->db_link));
// Count volumes
$view->assign('volumes_nb', Volumes_Model::count($dbSql->db_link));
// ==============================================================
// Last period <Job status graph>
// ==============================================================
$jobs_status = array('Running', 'Completed', 'Waiting', 'Failed', 'Canceled');
$jobs_status_data = array();
foreach ($jobs_status as $status) {
$jobs_count = Jobs_Model::count_Jobs($dbSql->db_link, $custom_period, strtolower($status));
$jobs_status_data[] = array($status, $jobs_count );
}
$graph = new CGraph("dashboard-graph01.jpg");
$graph->SetData($jobs_status_data, 'pie');
$graph->setPieLegendColors(array( 'gray', 'green','blue', 'red', 'orange'));
// Graph rendering
$view->assign('graph_jobs', $graph->Render());
unset($graph);
// ==============================================================
// Volumes per pool widget
// ==============================================================
$vols_by_pool = array();
$graph = new CGraph("dashboard-graph02.jpg");
$max_pools = '9';
$table_pool = 'Pool';
$limit = '';
$sum_vols = '';
// Count defined pools in catalog
$pools_count = Pools_Model::count($dbSql->db_link);
// Display 9 biggest pools and rest of volumes in 10th one display as Other
if ($pools_count > $max_pools) {
if (CDB::getDriverName() == 'pgsql') {
$limit = $max_pools . 'OFFSET ' . ($pools_count - $max_pools);
} else {
$limit = $max_pools . ',' . ($pools_count - $max_pools);
}
$query = array( 'table' => $table_pool,
'fields' => array('SUM(numvols) AS sum_vols'),
'limit' => $limit,
'groupby' => 'name');
$result = CDBUtils::runQuery(CDBQuery::get_Select($query), $dbSql->db_link);
$sum_vols = $result->fetch();
} else {
$limit = $pools_count;
}
// Check database driver for pool table name
if (CDB::getDriverName() == 'pgsql') {
$table_pool = strtolower($table_pool);
}
$query = array('table' => $table_pool, 'fields' => array('poolid,name,numvols'), 'orderby' => 'numvols DESC', 'limit' => $max_pools);
$result = CDBUtils::runQuery(CDBQuery::get_Select($query), $dbSql->db_link);
foreach ($result as $pool) {
$vols_by_pool[] = array($pool['name'], $pool['numvols']);
}
if ($pools_count > $max_pools) {
$vols_by_pool[] = array('Others', $sum_vols['sum_vols']);
}
$graph->SetData($vols_by_pool, 'pie');
// Graph rendering
$view->assign('graph_pools', $graph->Render());
unset($graph);
// ==============================================================
// Last 7 days stored Bytes widget
// ==============================================================
$days_stored_bytes = array();
$days = DateTimeUtil::getLastDaysIntervals(7);
foreach ($days as $day) {
$days_stored_bytes[] = array( date("m-d", $day['start']), Jobs_Model::getStoredBytes($dbSql->db_link, array($day['start'], $day['end'])));
}
$graph = new CGraph("dashboard-graph03.jpg");
$graph->SetData($days_stored_bytes, 'bars', true);
// Graph rendering
$view->assign('graph_stored_bytes', $graph->Render());
// ==============================================================
// Last 7 days Stored Files widget
// ==============================================================
$days_stored_files = array();
$days = DateTimeUtil::getLastDaysIntervals(7);
foreach ($days as $day) {
$days_stored_files[] = array( date("m-d", $day['start']), Jobs_Model::getStoredFiles($dbSql->db_link, array($day['start'], $day['end'])));
}
unset($graph);
$graph = new CGraph("dashboard-graph04.jpg");
$graph->SetData($days_stored_files, 'bars');
// Graph rendering
$view->assign('graph_stored_files', $graph->Render());
unset($graph);
// ==============================================================
// Last used volumes widget
// ==============================================================
$last_volumes = array();
// Building SQL statment
$where = array();
$tmp = "(Media.Volstatus != 'Disabled') ";
switch (CDB::getDriverName()) {
case 'mysql':
case 'pgsql':
$tmp .= "AND (Media.LastWritten IS NOT NULL)";
break;
case 'sqlite':
$tmp .= "AND (Media.Lastwritten != 0)";
break;
}
$where[] = $tmp;
$statment = array( 'table' => 'Media',
'fields' => array('Media.MediaId', 'Media.Volumename', 'Media.Lastwritten', 'Media.VolStatus', 'Media.VolJobs', 'Pool.Name AS poolname'),
'join' => array('table' => 'Pool', 'condition' => 'Media.PoolId = Pool.poolid'),
'where' => $where,
'orderby' => 'Media.Lastwritten DESC',
'limit' => '10');
// Run the query
$result = CDBUtils::runQuery(CDBQuery::get_Select($statment), $dbSql->db_link);
foreach ($result as $volume) {
$last_volumes[] = $volume;
}
$view->assign('volumes_list', $last_volumes);
} catch (Exception $e) {
CErrorHandler::displayError($e);
}
// Set page name
$current_page = 'Dashboard';
$view->assign('page_name', $current_page);
// Render template
$view->render('index.tpl');