]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/index.php
bacula-web: Improved sql statment for last used volumes in main dashboard
[bacula/bacula] / gui / bacula-web / index.php
1 <?php
2 /* 
3 +-------------------------------------------------------------------------+
4 | Copyright (C) 2004 Juan Luis Francés Jiménez                                                    |
5 | Copyright 2010-2011, Davide Franco                                              |
6 |                                                                         |
7 | This program is free software; you can redistribute it and/or           |
8 | modify it under the terms of the GNU General Public License             |
9 | as published by the Free Software Foundation; either version 2          |
10 | of the License, or (at your option) any later version.                  |
11 |                                                                         |
12 | This program is distributed in the hope that it will be useful,         |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
15 | GNU General Public License for more details.                            |
16 +-------------------------------------------------------------------------+ 
17 */
18         session_start();
19         include_once( 'config/global.inc.php' );
20
21         $dbSql                          = new Bweb();
22         
23
24         // Stored files number 
25         $dbSql->tpl->assign('stored_files', number_format($dbSql->getStoredFiles( FIRST_DAY, NOW ), 0, '.', "'" ) );
26           
27         // Database size
28         $dbSql->tpl->assign('database_size', $dbSql->getDatabaseSize());
29
30         // Overall stored bytes
31         $stored_bytes = CUtils::Get_Human_Size( $dbSql->getStoredBytes( FIRST_DAY, NOW ) );
32         $dbSql->tpl->assign('stored_bytes', $stored_bytes);
33
34         // Total bytes and files for last 24 hours
35         $dbSql->tpl->assign('bytes_last', CUtils::Get_Human_Size( $dbSql->getStoredBytes( LAST_DAY, NOW ) ) );
36         $dbSql->tpl->assign('files_last', number_format($dbSql->getStoredFiles( LAST_DAY, NOW ), 0, '.', "'" ) );
37
38         // Number of clients
39         $nb_clients = $dbSql->Get_Nb_Clients();
40         $dbSql->tpl->assign('clientes_totales',$nb_clients["nb_client"] );
41
42         // Backup Job list
43         $dbSql->tpl->assign( 'jobs_list', $dbSql->Get_BackupJob_Names() );
44         
45         // Clients list
46
47         $dbSql->tpl->assign( 'clients_list', $dbSql->getClients() );
48
49         // Last 24 hours status (completed, failed and waiting jobs)
50         $dbSql->tpl->assign( 'completed_jobs', $dbSql->countJobs( LAST_DAY, NOW, 'completed' ) );
51         $dbSql->tpl->assign( 'failed_jobs', $dbSql->countJobs( LAST_DAY, NOW, 'failed' ) );
52         $dbSql->tpl->assign( 'waiting_jobs', $dbSql->countJobs( LAST_DAY, NOW, 'waiting' ) );
53
54         // Last 24 hours jobs Level
55         $dbSql->tpl->assign( 'incr_jobs', $dbSql->countJobs( LAST_DAY, NOW, 'ALL', J_INCR) );
56         $dbSql->tpl->assign( 'diff_jobs', $dbSql->countJobs( LAST_DAY, NOW, 'ALL', J_DIFF) );
57         $dbSql->tpl->assign( 'full_jobs', $dbSql->countJobs( LAST_DAY, NOW, 'ALL', J_FULL) );
58
59         // Last 24 hours Job status graph
60         $jobs_status_data = array();
61         $jobs_status      = array( 'Running', 'Completed', 'Failed', 'Canceled', 'Waiting' );
62
63         foreach( $jobs_status as $status )
64                 $jobs_status_data[] = array( $status, $dbSql->countJobs(LAST_DAY, NOW, $status) );
65
66         $graph = new CGraph( "graph.png" );
67         $graph->SetData( $jobs_status_data, 'pie', 'text-data-single' );
68         $graph->SetGraphSize( 400, 230 );
69
70         $graph->Render();
71         $dbSql->tpl->assign('graph_jobs', $graph->Get_Image_file() );
72         unset($graph);
73
74         // Volumes by pools graph
75         $vols_by_pool = array();
76         $graph        = new CGraph( "graph1.png" );
77
78         foreach( $dbSql->getPools() as $pool )
79                 $vols_by_pool[] = array( $pool['name'], $dbSql->countVolumes( $pool['poolid'] ) );
80
81         $graph->SetData( $vols_by_pool, 'pie', 'text-data-single' );
82         $graph->SetGraphSize( 400, 230 );
83
84         $graph->Render();
85         $dbSql->tpl->assign('graph_pools', $graph->Get_Image_file() );
86
87         // Last 7 days stored Bytes graph
88         $days_stored_bytes      = array();
89         $days = CTimeUtils::getLastDaysIntervals( 7 );
90         
91         foreach( $days as $day ) {
92                 $stored_bytes            = $dbSql->getStoredBytes( $day['start'], $day['end']);
93                 $stored_bytes            = CUtils::Get_Human_Size( $stored_bytes, 1, 'GB', false );
94                 $days_stored_bytes[] = array( date("m-d", $day['start']), $stored_bytes );  
95         }
96
97         $graph = new CGraph( "graph2.png" );
98         $graph->SetData( $days_stored_bytes, 'bars', 'text-data' );
99         $graph->SetGraphSize( 400, 230 );
100         $graph->SetYTitle( "GB" );
101
102         $graph->Render();
103         $dbSql->tpl->assign('graph_stored_bytes', $graph->Get_Image_file() );
104
105
106         // Last 15 used volumes
107         $last_volumes = array();
108         
109         try{
110                 $query  = "SELECT Media.MediaId, Media.Volumename, Media.Lastwritten, Media.VolStatus FROM Media ";
111                 $query .= "WHERE Media.Volstatus != 'Disabled' ";
112                 $query .= "ORDER BY Media.Lastwritten DESC ";           
113                 $query .= "LIMIT 10";
114                 $result = $dbSql->db_link->runQuery( $query );
115                         
116                 foreach( $result->fetchAll() as $volume ) {
117                         $query                            = "SELECT COUNT(*) as jobs_count FROM JobMedia WHERE JobMedia.MediaId = '" . $volume['mediaid'] . "'";
118                         $jobs_by_vol              = $dbSql->db_link->runQuery($query);
119                         $jobs_by_vol              = $jobs_by_vol->fetchAll();
120                         $volume['jobs_count'] = $jobs_by_vol[0]['jobs_count'];
121                         $last_volumes[]           = $volume;
122                 }
123         }catch(PDOException $e) {
124                 CDBError::raiseError($e);
125         }
126
127         $dbSql->tpl->assign( 'volumes_list', $last_volumes );   
128
129         // Render template
130         $dbSql->tpl->display('index.tpl');
131 ?>