]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/index.php
bacula-web: Improved countJobs() function in bweb class
[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.inc.php' );
20
21 $dbSql                          = new Bweb();
22 $days_stored_bytes      = array();
23
24 // Stored files number 
25 $dbSql->tpl->assign('stored_files', $dbSql->GetStoredFiles( ALL ) );
26   
27 // Database size
28 $dbSql->tpl->assign('database_size', $dbSql->GetDbSize());
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 stored bytes since last 24 hours
35 $bytes_last = CUtils::Get_Human_Size( $dbSql->getStoredBytes( LAST_DAY, NOW ) );
36 $dbSql->tpl->assign('bytes_last', $bytes_last );
37
38 // Total stored files since last 24 hours
39 $files_last = $dbSql->GetStoredFiles( LAST_DAY );
40 $dbSql->tpl->assign('files_last', $files_last );
41
42
43 // Number of clients
44 $nb_clients = $dbSql->Get_Nb_Clients();
45 $dbSql->tpl->assign('clientes_totales',$nb_clients["nb_client"] );
46
47 // Backup Job list for report.tpl and last_run_report.tpl
48 $dbSql->tpl->assign( 'jobs_list', $dbSql->Get_BackupJob_Names() );
49
50 // Last 24 hours status (completed, failed and waiting jobs)
51 $dbSql->tpl->assign( 'completed_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'completed' ) );
52 $dbSql->tpl->assign( 'failed_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'failed' ) );
53 $dbSql->tpl->assign( 'waiting_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'waiting' ) );
54
55 // Last 24 hours jobs Level
56 $dbSql->tpl->assign( 'incr_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'ALL', J_INCR) );
57 $dbSql->tpl->assign( 'diff_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'ALL', J_DIFF) );
58 $dbSql->tpl->assign( 'full_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'ALL', J_FULL) );
59
60 // Last 24 hours Job status graph
61 $data   = array();  
62 $status = array( 'completed', 'terminated_errors', 'failed', 'waiting', 'created', 'running', 'error' );
63
64 foreach( $status as $job_status ) {
65         array_push( $data, $dbSql->GetJobsStatistics( $job_status ) );
66 }
67
68 $graph = new CGraph( "graph.png" );
69 $graph->SetData( $data, 'pie', 'text-data-single' );
70 $graph->SetGraphSize( 400, 230 );
71
72 $graph->Render();
73 $dbSql->tpl->assign('graph_jobs', $graph->Get_Image_file() );
74 unset($graph);
75
76 // Pool and volumes graph
77 $data = array();
78 $graph = new CGraph( "graph1.png" );
79
80 $pools = $dbSql->Get_Pools_List();
81 while( $pool = $pools->fetchRow( ) ) {
82         array_push( $data, $dbSql->CountVolumesByPool( $pool['poolid']) );
83 }
84
85 $graph->SetData( $data, 'pie', 'text-data-single' );
86 $graph->SetGraphSize( 400, 230 );
87
88 $graph->Render();
89 $dbSql->tpl->assign('graph_pools', $graph->Get_Image_file() );
90
91 // Last 7 days stored Bytes graph
92 $days   = array();
93
94 for( $c = 6 ; $c >= 0 ; $c-- ) {
95         $today  = NOW - ($c * DAY);
96         $days[] = CTimeUtils::get_Day_Intervals($today);
97 }
98
99 foreach( $days as $day ) {
100         $stored_bytes            = $dbSql->getStoredBytes( $day['start'], $day['end']);
101         $stored_bytes            = CUtils::Get_Human_Size( $stored_bytes, 1, 'GB', false );
102         $days_stored_bytes[] = array( date("m-d", $day['start']), $stored_bytes );  
103 }
104
105 $graph = new CGraph( "graph2.png" );
106 $graph->SetData( $days_stored_bytes, 'bars', 'text-data' );
107 $graph->SetGraphSize( 400, 230 );
108 $graph->SetYTitle( "GB" );
109
110 $graph->Render();
111 $dbSql->tpl->assign('graph_stored_bytes', $graph->Get_Image_file() );
112
113
114 // Last 15 used volumes
115 $vol_list = array();
116
117 $query  = "SELECT DISTINCT Media.Volumename, Media.Lastwritten, Media.VolStatus, Job.JobId FROM Job ";
118 $query .= "LEFT JOIN JobMedia ON Job.JobId = JobMedia.JobId ";
119 $query .= "LEFT JOIN Media ON JobMedia.MediaId = Media.MediaId ";
120 $query .= "ORDER BY Job.JobId DESC ";
121 $query .= "LIMIT 10 ";
122
123 $result = $dbSql->db_link->query( $query );
124
125 if ( PEAR::isError( $result ) )
126         $this->TriggerDBError( 'Unable to get last used volumes from catalog' . $result );
127 else {
128         while ( $vol = $result->fetchRow() ) 
129                 array_push( $vol_list, $vol );
130 }
131 $dbSql->tpl->assign( 'volume_list', $vol_list );        
132
133 // Render template
134 $dbSql->tpl->display('index.tpl');
135 ?>