source: branches/0.4/web/addons/job_monarch/graph.php @ 801

Last change on this file since 801 was 801, checked in by ramonb, 11 years ago
  • more fixes
  • added values in legend for network_report
  • Property svn:keywords set to Id
File size: 25.3 KB
Line 
1<?php
2/*
3 *
4 * This file is part of Jobmonarch
5 *
6 * Copyright (C) 2006  Ramon Bastiaans
7 *
8 * Jobmonarch is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * Jobmonarch is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 *
22 * SVN $Id: graph.php 801 2013-04-06 21:24:25Z ramonb $
23 */
24
25global $rrds, $start, $r, $conf, $m;
26
27include "./libtoga.php";
28
29# Graph specific variables
30$size = escapeshellcmd( rawurldecode( $_GET["z"] ));
31$graph = escapeshellcmd( rawurldecode( $_GET["g"] ));
32$grid = escapeshellcmd( rawurldecode( $_GET["G"] ));
33$self = escapeshellcmd( rawurldecode( $_GET["me"] ));
34$max = escapeshellcmd( rawurldecode( $_GET["x"] ));
35$min = escapeshellcmd( rawurldecode( $_GET["n"] ));
36$value = escapeshellcmd( rawurldecode( $_GET["v"] ));
37$load_color = escapeshellcmd( rawurldecode( $_GET["l"] ));
38$vlabel = escapeshellcmd( rawurldecode( $_GET["vl"] ));
39$j_title = escapeshellcmd( rawurldecode( $_GET["t"] ));
40$hostname = escapeshellcmd( rawurldecode( $_GET["h"] ));
41$range = escapeshellcmd( rawurldecode( $_GET["r"] ));
42
43if( strpos( $size, 'overview' ) )
44{
45    $my_dir = getcwd();
46
47    global $context;
48
49    $context = 'host';
50
51    chdir( $GANGLIA_PATH );
52
53    include "./ganglia.php";
54    include "./get_ganglia.php";
55
56    chdir( $my_dir );
57}
58
59if ( !empty( $_GET ) ) 
60{
61        extract( $_GET );
62}
63
64$sourcetime = $st;
65
66
67$cluster = $c;
68$metricname = ($g) ? $g : $m;
69
70# Assumes we have a $start variable (set in get_context.php).
71if ($size == "small") 
72{
73    $height = 40;
74    $width = 130;
75} 
76else if ($size == "medium") 
77{
78    $height = 75;
79    $width = 300;
80} 
81else if ($size == "overview-medium") 
82{
83    $height = 75;
84    $width = 300;
85} 
86else 
87{
88    $height = 100;
89    $width = 400;
90}
91
92// RB: Perform some formatting/spacing magic.. tinkered to fit
93//
94if ($size == 'small') {
95   $eol1 = '\\l';
96   $space1 = ' ';
97   $space2 = '         ';
98} else if ($size == 'medium') {
99   $eol1 = '';
100   $space1 = '';
101   $space2 = '';
102   $extras = ' --font LEGEND:7 ';
103} else if ($size == 'overview-medium') {
104   $eol1   = '';
105   $space1 = '';
106   $space2 = '';
107   $extras = ' --font LEGEND:7 ';
108} else if ($size == 'large') {
109   $eol1 = '';
110   $space1 = '       ';
111   $space2 = '       ';
112} else if ($size == 'xlarge') {
113   $eol1 = '';
114   $space1 = '             ';
115   $space2 = '             ';
116} else if ($size == 'mobile') {
117   $eol1 = '';
118   $space1 = ' ';
119   $space2 = '';
120}
121
122$jobstart_color = "3AE302";
123$jobstop_color = "F5164A";
124
125if($command) 
126{
127      $command = '';
128}
129
130$graph = $metricname;
131
132$rrd_dirs = Array();
133
134if (isset($graph)) 
135{
136    $series = '';
137    if( $size == 'overview-medium' )
138    {
139        $rrd_dirs[] = $conf['rrds'] . '/' . $cluster .'/'. $hostname;
140    }
141    else
142    {
143        $trd = new TarchRrdGraph( $cluster, $hostname );
144        $rrd_dirs = $trd->getRrdDirs( $period_start, $period_stop );
145
146    }
147
148    if($graph == "cpu_report") 
149    {
150
151        $style = "CPU";
152
153        $upper_limit = "--upper-limit 100 --rigid";
154        $lower_limit = "--lower-limit 0";
155
156        $vertical_label = "--vertical-label Percent ";
157
158        $def_nr = 0;
159
160        foreach( $rrd_dirs as $rrd_dir ) 
161        {
162
163            $series .= "DEF:'cpu_user${def_nr}'='${rrd_dir}/cpu_user.rrd':'sum':AVERAGE "
164                ."DEF:'cpu_nice${def_nr}'='${rrd_dir}/cpu_nice.rrd':'sum':AVERAGE "
165                ."DEF:'cpu_system${def_nr}'='${rrd_dir}/cpu_system.rrd':'sum':AVERAGE "
166                ."DEF:'cpu_idle${def_nr}'='${rrd_dir}/cpu_idle.rrd':'sum':AVERAGE "
167                ."DEF:'cpu_wio${def_nr}'='${rrd_dir}/cpu_wio.rrd':'sum':AVERAGE ";
168
169            if( $conf['graphreport_stats'] )
170            {
171                $series .= "CDEF:cpu_user${def_nr}_nonans=cpu_user${def_nr},UN,0,cpu_user${def_nr},IF ";
172                $series .= "CDEF:cpu_nice${def_nr}_nonans=cpu_nice${def_nr},UN,0,cpu_nice${def_nr},IF ";
173                $series .= "CDEF:cpu_system${def_nr}_nonans=cpu_system${def_nr},UN,0,cpu_system${def_nr},IF ";
174                $series .= "CDEF:cpu_wio${def_nr}_nonans=cpu_wio${def_nr},UN,0,cpu_wio${def_nr},IF ";
175                $series .= "CDEF:cpu_idle${def_nr}_nonans=cpu_idle${def_nr},UN,0,cpu_idle${def_nr},IF ";
176            }
177
178            $def_nr++;
179        }
180
181
182        if( $conf['graphreport_stats'] )
183        {
184            $s_last     = $def_nr - 1;
185            $user_sum   = "CDEF:cpu_user=cpu_user0_nonans";
186            $nice_sum   = "CDEF:cpu_nice=cpu_nice0_nonans";
187            $system_sum = "CDEF:cpu_system=cpu_system0_nonans";
188            $wio_sum    = "CDEF:cpu_wio=cpu_wio0_nonans";
189            $idle_sum   = "CDEF:cpu_idle=cpu_idle0_nonans";
190
191            if( $s_last > 1 )
192            {
193                foreach (range(1, ($s_last)) as $print_nr ) 
194                {
195                    $user_sum   .= ",cpu_user{$print_nr}_nonans,+";
196                    $nice_sum   .= ",cpu_nice{$print_nr}_nonans,+";
197                    $system_sum .= ",cpu_system{$print_nr}_nonans,+";
198                    $wio_sum    .= ",cpu_wio{$print_nr}_nonans,+";
199                    $idle_sum   .= ",cpu_idle{$print_nr}_nonans,+";
200                }
201            }
202
203            $user_sum .= " ";
204            $nice_sum .= " ";
205            $system_sum .= " ";
206            $wio_sum .= " ";
207            $idle_sum .= " ";
208
209            $series .= $user_sum . $nice_sum . $system_sum . $wio_sum . $idle_sum;
210
211            $report_names = array( "user", "nice", "system", "wio", "idle" );
212
213            $r_count = 0;
214
215            foreach( $report_names as $r )
216            {
217                $legend_str = ucfirst( $r );
218
219                if( $r_count == 0 )
220                {
221                    $graph_str = "AREA";
222                }
223                else
224                {
225                    $graph_str = "STACK";
226                }
227                foreach (range(0, ($s_last)) as $print_nr ) 
228                {
229
230                    $series .= "${graph_str}:'cpu_${r}${print_nr}'#".$conf['cpu_'.${r}.'_color'].":'${legend_str}\g' ";
231                    $legend_str = '';
232                }
233
234                $series .= "VDEF:'${r}_last'=cpu_${r},LAST ";
235                $series .= "VDEF:'${r}_min'=cpu_${r},MINIMUM ";
236                $series .= "VDEF:'${r}_avg'=cpu_${r},AVERAGE ";
237                $series .= "VDEF:'${r}_max'=cpu_${r},MAXIMUM ";
238
239                $spacefill = '';
240
241                $spacesize = 6-strlen($r);
242                foreach ( range( 0, $spacesize ) as $whatever )
243                {
244                    $spacefill .= ' ';
245                }
246
247                $series .= "GPRINT:'${r}_last':'${spacefill}Now\:%6.1lf%%' "
248                        . "GPRINT:'${r}_min':'${space1}Min\:%6.1lf%%${eol1}' "
249                        . "GPRINT:'${r}_avg':'${space2}Avg\:%6.1lf%%' "
250                        . "GPRINT:'${r}_max':'${space1}Max\:%6.1lf%%\\l' ";
251                       
252                $r_count = $r_count + 1;
253            }
254        }
255        else
256        {
257            $series .= "AREA:'cpu_user${def_nr}'#".$conf['cpu_user_color']."${user_str} "
258                    ."STACK:'cpu_nice${def_nr}'#".$conf['cpu_nice_color']."${nice_str} "
259                    ."STACK:'cpu_system${def_nr}'#".$conf['cpu_system_color']."${system_str} "
260                    ."STACK:'cpu_wio${def_nr}'#".$conf['cpu_wio_color']."${wio_str} "
261                    ."STACK:'cpu_idle${def_nr}'#".$conf['cpu_idle_color']."${idle_str} ";
262        }
263
264    } 
265    else if ($graph == "job_report") 
266    {
267        $style = "Jobs";
268
269        $lower_limit = "--lower-limit 0 --rigid";
270        $vertical_label = "--vertical-label Jobs";
271
272        $def_nr = 0;
273
274        $rrd_dir = $conf['rrds'] . "/$clustername/$hostname/";
275
276        $rj_rrd    = $rrd_dir . "zplugin_monarch_rj.rrd";
277        $qj_rrd    = $rrd_dir . "zplugin_monarch_qj.rrd";
278
279        $sorted_hosts    = array();
280        $sorted_hosts[]  = $rjqj_host;
281
282        $rj_str = ":'Running Jobs'";
283        $qj_str = ":'Queued Jobs'";
284
285        $series .= "DEF:'running_jobs'='${rj_rrd}':'sum':AVERAGE "
286            ."DEF:'queued_jobs'='${qj_rrd}':'sum':AVERAGE ";
287
288       
289        $series .= "LINE3:'running_jobs'#ff0000${rj_str} ";
290
291        if ( $conf['graphreport_stats'] ) 
292        {
293            $series .= "CDEF:running_pos=running_jobs,0,INF,LIMIT "
294                    . "VDEF:running_last=running_pos,LAST "
295                    . "VDEF:running_min=running_pos,MINIMUM "
296                    . "VDEF:running_avg=running_pos,AVERAGE "
297                    . "VDEF:running_max=running_pos,MAXIMUM "
298                    . "GPRINT:'running_last':' ${space1}Now\:%5.0lf' "
299                    . "GPRINT:'running_min':'${space1}Min\:%5.0lf${eol1}' "
300                    . "GPRINT:'running_avg':'${space2}Avg\:%5.0lf' "
301                    . "GPRINT:'running_max':'${space1}Max\:%5.0lf\\l' ";
302        }
303
304        $series .= "LINE3:'queued_jobs'#999999${qj_str} ";
305
306        if ( $conf['graphreport_stats'] ) 
307        {
308            $series .= "CDEF:queued_pos=queued_jobs,0,INF,LIMIT "
309                    . "VDEF:queued_last=queued_pos,LAST "
310                    . "VDEF:queued_min=queued_pos,MINIMUM "
311                    . "VDEF:queued_avg=queued_pos,AVERAGE "
312                    . "VDEF:queued_max=queued_pos,MAXIMUM "
313                    . "GPRINT:'queued_last':'  ${space1}Now\:%5.0lf' "
314                    . "GPRINT:'queued_min':'${space1}Min\:%5.0lf${eol1}' "
315                    . "GPRINT:'queued_avg':'${space2}Avg\:%5.0lf' "
316                    . "GPRINT:'queued_max':'${space1}Max\:%5.0lf\\l' ";
317        }
318    } 
319    else if ($graph == "mem_report") 
320    {
321        $style = "Memory";
322
323        $lower_limit = "--lower-limit 0 --rigid";
324        $extras .= "--base 1024";
325        $vertical_label = "--vertical-label Bytes";
326
327        $def_nr = 0;
328
329        foreach( $rrd_dirs as $rrd_dir ) 
330        {
331            $series .= "DEF:'mem_total${def_nr}'='${rrd_dir}/mem_total.rrd':'sum':AVERAGE "
332                ."CDEF:'bmem_total${def_nr}'=mem_total${def_nr},1024,* "
333                ."DEF:'mem_shared${def_nr}'='${rrd_dir}/mem_shared.rrd':'sum':AVERAGE "
334                ."CDEF:'bmem_shared${def_nr}'=mem_shared${def_nr},1024,* "
335                ."DEF:'mem_free${def_nr}'='${rrd_dir}/mem_free.rrd':'sum':AVERAGE "
336                ."CDEF:'bmem_free${def_nr}'=mem_free${def_nr},1024,* "
337                ."DEF:'mem_cached${def_nr}'='${rrd_dir}/mem_cached.rrd':'sum':AVERAGE "
338                ."CDEF:'bmem_cached${def_nr}'=mem_cached${def_nr},1024,* "
339                ."DEF:'mem_buffer${def_nr}'='${rrd_dir}/mem_buffers.rrd':'sum':AVERAGE "
340                ."CDEF:'bmem_buffer${def_nr}'=mem_buffer${def_nr},1024,* "
341                ."CDEF:'bmem_used${def_nr}'='bmem_total${def_nr}','bmem_shared${def_nr}',-,'bmem_free${def_nr}',-,'bmem_cached${def_nr}',-,'bmem_buffer${def_nr}',- "
342                ."DEF:'swap_total${def_nr}'='${rrd_dir}/swap_total.rrd':'sum':AVERAGE "
343                ."DEF:'swap_free${def_nr}'='${rrd_dir}/swap_free.rrd':'sum':AVERAGE "
344                ."CDEF:'bmem_swap${def_nr}'='swap_total${def_nr}','swap_free${def_nr}',-,1024,* ";
345
346            $report_names = array( "used", "shared", "cached", "buffer", "swap", "total" );
347
348            if( $conf['graphreport_stats'] )
349            {
350                foreach( $report_names as $r )
351                {
352                    $series .= "CDEF:bmem_${r}${def_nr}_nonans=bmem_${r}${def_nr},UN,0,bmem_${r}${def_nr},IF ";
353                }
354            }
355
356            $def_nr++;
357        }
358
359        if( $conf['graphreport_stats'] )
360        {
361            $s_last     = $def_nr - 1;
362
363            foreach( $report_names as $r )
364            {
365                $cdef_sum   = "CDEF:bmem_${r}=bmem_${r}0_nonans";
366
367                if( $s_last > 1 )
368                {
369                    foreach (range(1, ($s_last)) as $print_nr ) 
370                    {
371                        $user_sum   .= ",bmem_${r}{$print_nr}_nonans,+";
372                    }
373                }
374                $cdef_sum .= " ";
375
376                $series   .= $cdef_sum;
377            }
378
379            $r_count = 0;
380
381            $conf['mem_buffer_color'] = $conf['mem_buffered_color'];
382            $conf['mem_swap_color']   = $conf['mem_swapped_color'];
383            $conf['mem_total_color']  = $conf['cpu_num_color'];
384
385            foreach( $report_names as $r )
386            {
387                $legend_str = ucfirst( $r );
388
389                if( $r == "total" )
390                {
391                    $graph_str  = "LINE2";
392                }
393                else if( $r_count == 0 )
394                {
395                    $graph_str  = "AREA";
396                }
397                else
398                {
399                    $graph_str  = "STACK";
400                }
401                foreach (range(0, ($s_last)) as $print_nr ) 
402                {
403                    $series .= "${graph_str}:'bmem_${r}${print_nr}'#".$conf['mem_'.${r}.'_color'].":'${legend_str}\g' ";
404                    $legend_str = '';
405                }
406
407                $series .= "VDEF:'${r}_last'=bmem_${r},LAST ";
408                $series .= "VDEF:'${r}_min'=bmem_${r},MINIMUM ";
409                $series .= "VDEF:'${r}_avg'=bmem_${r},AVERAGE ";
410                $series .= "VDEF:'${r}_max'=bmem_${r},MAXIMUM ";
411
412                $spacefill = '';
413
414                $spacesize = 6-strlen($r); // max length 'swapped' = 7
415                foreach ( range( 0, $spacesize ) as $whatever )
416                {
417                    $spacefill .= ' ';
418                }
419                $series .= "GPRINT:'${r}_last':'${spacefill}Now\:%6.1lf%s' "
420                        . "GPRINT:'${r}_min':'${space1}Min\:%6.1lf%s${eol1}' "
421                        . "GPRINT:'${r}_avg':'${space2}Avg\:%6.1lf%s' "
422                        . "GPRINT:'${r}_max':'${space1}Max\:%6.1lf%s\\l' ";
423
424            }
425        }
426        $r_count = $r_count + 1;
427
428    } 
429    else if ($graph == "load_report") 
430    {
431        $style = "Load";
432
433        $lower_limit = "--lower-limit 0 --rigid";
434        $vertical_label = "--vertical-label 'Load/Procs'";
435
436        $def_nr = 0;
437
438        foreach( $rrd_dirs as $rrd_dir ) 
439        {
440
441            if( $def_nr == 0 ) 
442            {
443
444                $load_str = ":'1-min Load'";
445                $cpu_str = ":'CPUs'";
446                $run_str = ":'Running Processes'";
447            } 
448            else 
449            {
450                $load_str = "";
451                $cpu_str = "";
452                $run_str = "";
453            }
454
455            $series .= "DEF:'load_one${def_nr}'='${rrd_dir}/load_one.rrd':'sum':AVERAGE "
456                ."DEF:'proc_run${def_nr}'='${rrd_dir}/proc_run.rrd':'sum':AVERAGE "
457                ."DEF:'cpu_num${def_nr}'='${rrd_dir}/cpu_num.rrd':'sum':AVERAGE ";
458            $series .="AREA:'load_one${def_nr}'#".$conf['load_one_color']."${load_str} ";
459            $series .="LINE2:'cpu_num${def_nr}'#".$conf['cpu_num_color']."${cpu_str} ";
460            $series .="LINE2:'proc_run${def_nr}'#".$conf['proc_run_color']."${run_str} ";
461
462            $def_nr++;
463        }
464
465    } 
466    else if ($graph == "network_report") 
467    {
468        $style = "Network";
469
470        $lower_limit = "--lower-limit 0 --rigid";
471        $extras .= "--base 1024";
472        $vertical_label = "--vertical-label 'Bytes/sec'";
473
474        $def_nr = 0;
475
476        foreach( $rrd_dirs as $rrd_dir ) 
477        {
478            $series .= "DEF:'bytes_in${def_nr}'='${rrd_dir}/bytes_in.rrd':'sum':AVERAGE "
479                    ."DEF:'bytes_out${def_nr}'='${rrd_dir}/bytes_out.rrd':'sum':AVERAGE ";
480
481            $report_names = array( "in", "out" );
482
483            if( $conf['graphreport_stats'] )
484            {
485                foreach( $report_names as $r )
486                {
487                    $series .= "CDEF:bytes_${r}${def_nr}_nonans=bytes_${r}${def_nr},UN,0,bytes_${r}${def_nr},IF ";
488                }
489            }
490
491            $def_nr++;
492        }
493
494        if( $conf['graphreport_stats'] )
495        {
496            $s_last     = $def_nr - 1;
497
498            foreach( $report_names as $r )
499            {
500                $cdef_sum   = "CDEF:bytes_${r}=bytes_${r}0_nonans";
501
502                if( $s_last > 1 )
503                {
504                    foreach (range(1, ($s_last)) as $print_nr ) 
505                    {
506                        $user_sum   .= ",bytes_${r}{$print_nr}_nonans,+";
507                    }
508                }
509                $cdef_sum .= " ";
510
511                $series   .= $cdef_sum;
512            }
513
514            $r_count = 0;
515
516            $conf['bytes_out_color'] = $conf['mem_used_color'];
517            $conf['bytes_in_color']  = $conf['mem_cached_color'];
518
519            foreach( $report_names as $r )
520            {
521                $legend_str = ucfirst( $r );
522
523                $graph_str  = "LINE2";
524
525                foreach (range(0, ($s_last)) as $print_nr ) 
526                {
527                    $series .= "${graph_str}:'bytes_${r}${print_nr}'#".$conf['bytes_'.${r}.'_color'].":'${legend_str}\g' ";
528                    $legend_str = '';
529                }
530
531                $series .= "VDEF:'${r}_last'=bytes_${r},LAST ";
532                $series .= "VDEF:'${r}_min'=bytes_${r},MINIMUM ";
533                $series .= "VDEF:'${r}_avg'=bytes_${r},AVERAGE ";
534                $series .= "VDEF:'${r}_max'=bytes_${r},MAXIMUM ";
535
536                $spacefill = '';
537
538                $spacesize = 6-strlen($r); // max length 'swapped' = 7
539                foreach ( range( 0, $spacesize ) as $whatever )
540                {
541                    $spacefill .= ' ';
542                }
543                $series .= "GPRINT:'${r}_last':'${spacefill}Now\:%6.1lf%s' "
544                        . "GPRINT:'${r}_min':'${space1}Min\:%6.1lf%s${eol1}' "
545                        . "GPRINT:'${r}_avg':'${space2}Avg\:%6.1lf%s' "
546                        . "GPRINT:'${r}_max':'${space1}Max\:%6.1lf%s\\l' ";
547
548            }
549        }
550        else
551        {
552                $series .= "LINE2:'bytes_in${def_nr}'#".$conf['mem_cached_color']."'Bytes In' "
553                        ."LINE2:'bytes_out${def_nr}'#".$conf['mem_used_color']."'Bytes Out' ";
554        }
555
556    } 
557    else if ($graph == "packet_report") 
558    {
559        $style = "Packets";
560
561        $lower_limit = "--lower-limit 0 --rigid";
562        $extras .= "--base 1024";
563        $vertical_label = "--vertical-label 'Packets/sec'";
564
565        $def_nr = 0;
566
567        foreach( $rrd_dirs as $rrd_dir ) 
568        {
569
570            if( $def_nr == 0 ) 
571            {
572
573                $in_str = ":'In'";
574                $out_str = ":'Out'";
575            } 
576            else 
577            {
578
579                $in_str = "";
580                $out_str = "";
581            }
582
583            $series .= "DEF:'bytes_in${def_nr}'='${rrd_dir}/pkts_in.rrd':'sum':AVERAGE "
584                ."DEF:'bytes_out${def_nr}'='${rrd_dir}/pkts_out.rrd':'sum':AVERAGE "
585                ."LINE2:'bytes_in${def_nr}'#".$conf['mem_cached_color']."${in_str} "
586                ."LINE2:'bytes_out${def_nr}'#".$conf['mem_used_color']."${out_str} ";
587
588            $def_nr++;
589        }
590
591    } 
592    else 
593    {
594        /* Custom graph */
595        $style = "";
596
597        $subtitle = $metricname;
598        if($context == "host")
599        {
600            if ($size == "small")
601                $prefix = $metricname;
602            else
603                $prefix = $hostname;
604
605            $value = $value>1000 ? number_format($value) : number_format($value, 2);
606        }
607
608        if (is_numeric($max))
609            $upper_limit = "--upper-limit '$max' ";
610        if (is_numeric($min))
611            $lower_limit ="--lower-limit '$min' ";
612
613        if ($vlabel)
614        {
615            $vertical_label = "--vertical-label '$vlabel'";
616        }
617        else 
618        {
619            if ($upper_limit or $lower_limit) 
620            {
621                $max = $max>1000 ? number_format($max) : number_format($max, 2);
622                $min = $min>0 ? number_format($min,2) : $min;
623
624                $vertical_label ="--vertical-label '$min - $max' ";
625            }
626        }
627
628        $def_nr = 0;
629
630
631        foreach( $rrd_dirs as $rrd_dir ) 
632        {
633
634            if( $def_nr == 0 ) 
635            {
636                $title_str = ":'${subtitle}'";
637            } 
638            else 
639            {
640                $title_str = "";
641            }
642
643            $rrd_file = "$rrd_dir/$metricname.rrd";
644            $series .= "DEF:'sum${def_nr}'='$rrd_file':'sum':AVERAGE "
645                ."AREA:'sum${def_nr}'#".$conf['default_metric_color']."${title_str} ";
646
647            if( $conf['graphreport_stats'] )
648            {
649                $series .= "CDEF:sum${def_nr}_nonans=sum${def_nr},UN,0,sum${def_nr},IF ";
650            }
651
652            $def_nr++;
653        }
654
655        if( $conf['graphreport_stats'] )
656        {
657            $s_last         = $def_nr - 1;
658            $series_sum     = "CDEF:sum=sum0_nonans";
659
660            if( $def_nr > 1 )
661            {
662                foreach (range(1, ($s_last)) as $print_nr ) 
663                {
664                    $series_sum     .= ",sum{$print_nr}_nonans,+";
665                }
666            }
667
668            $series_sum .= " ";
669
670            $series_last    = "VDEF:'sum_last'=sum,LAST ";
671            $series_minimum = "VDEF:'sum_min'=sum,MINIMUM ";
672            $series_average = "VDEF:'sum_avg'=sum,AVERAGE ";
673            $series_maximum = "VDEF:'sum_max'=sum,MAXIMUM ";
674
675            $series .= $series_sum . $series_last . $series_minimum . $series_average . $series_maximum;
676
677            $series .= "COMMENT:\"\\n\" ";
678            $series .= "GPRINT:'sum_last':'${space1}Now\:%6.1lf%s' "
679                    . "GPRINT:'sum_min':'${space1}Min\:%6.1lf%s${eol1}' "
680                    . "GPRINT:'sum_avg':'${space2}Avg\:%6.1lf%s' "
681                    . "GPRINT:'sum_max':'${space1}Max\:%6.1lf%s\\l' ";
682        }
683    }
684}
685if( $series != '' ) 
686{
687    if ($job_start)
688    {
689        $series .= "VRULE:${job_start}#${jobstart_color}:'job start':dashes=4,2 ";
690    }
691    if ($job_stop)
692    {
693        $series .= "VRULE:${job_stop}#${jobstop_color}:'job stop':dashes=4,2 ";
694    }
695}
696
697if($graph == "job_report")
698{
699    if($range == 'job' )
700    {
701        $title = "Last: $j_title";
702    }
703    else
704    {
705        $title = "Last: $range";
706    }
707}
708else
709{
710    $title = "$hostname";
711}
712
713function determineXGrid( $p_start, $p_stop ) 
714{
715
716    $period = intval( $p_stop - $p_start );
717
718    // Syntax: <minor_grid_lines_time_declr>:<major_grid_lines_time_declr>:<labels_time_declr>:<offset>:<format>
719    //
720    // Where each <*time_declr*> = <time_type>:<time_interval>
721
722    //$my_lines1 = intval( $period / 3.0 );
723    //$my_lines2 = intval( $period / 6.0 );
724
725    //$my_grid = "SECOND:$my_lines2:SECOND:$my_lines1:SECOND:$my_lines1:0:%R";
726
727    //return "--x-grid $my_grid";
728
729    // Less than 1 minute
730    if( $period < 60 ) 
731    {
732
733        $tm_formt = "%X";
734        $my_grid = "SECOND:15:SECOND:30:SECOND:30:0:$tm_formt";
735
736    // Less than 10 minutes
737    } 
738    else if( $period < 600 ) 
739    {
740
741        $tm_formt = "%R";
742        $my_grid = "MINUTE:1:MINUTE:3:MINUTE:3:0:$tm_formt";
743
744    // Less than 1 hour
745    } 
746    else if( $period < 3600 ) 
747    {
748
749        $tm_formt = "%R";
750        $my_grid = "MINUTE:5:MINUTE:15:MINUTE:15:0:$tm_formt";
751
752    // Less than 15 hour
753    } 
754    else if( $period < 3600 ) 
755    {
756
757        $tm_formt = "%R";
758        $my_grid = "HOUR:1:HOUR:2:HOUR:2:0:$tm_formt";
759
760    // Less than 1 day
761    //
762    } 
763    else if( $period < 86400 ) 
764    {
765
766        $tm_formt = "%R";
767        $my_grid = "HOUR:2:HOUR:5:HOUR:5:0:$tm_formt";
768
769    // Less than 15 days
770    //
771    } 
772    else if( $period < 1296000 ) 
773    {
774
775        $tm_formt = "%e-%m";
776        $my_grid = "HOUR:1:DAY:3:DAY:3:0:'$tm_formt'";
777       
778    // Less than 30 days (a month)
779    //
780    } 
781    else if( $period < 2592000 ) 
782    {
783
784        $tm_formt = "%e-%m";
785        $my_grid = "DAY:5:DAY:10:DAY:10:0:'$tm_formt'";
786    }
787
788    if( isset( $my_grid ) ) 
789    {
790
791        $ret_str = "--x-grid $my_grid";
792        return array($ret_str,$tm_formt);
793
794    } 
795    else 
796    {
797        return array( "", "" );
798    }
799}
800
801$lower_limit = "--lower-limit 0";
802
803if( !isset( $load_color ) or ( $load_color == '') )
804{
805    $load_color = 'FFFFFF';
806}
807
808# Calculate time range.
809if ( isset($sourcetime) )
810{
811    $end = $sourcetime;
812    # Get_context makes start negative.
813    $start = $sourcetime + $start;
814
815    # Fix from Phil Radden, but step is not always 15 anymore.
816    if ($range=="month")
817    {
818        $end = floor($end / 672) * 672;
819    }
820        $command = $conf['rrdtool']. " graph - --start $start --end $end ".
821                "--width $width --height $height $lower_limit $vertical_label ".
822                "--title '$title' $extras $background ".
823                $series;
824}
825else
826{
827    $command = $conf['rrdtool'] . " graph - --start $period_start --end $period_stop ".
828               "--width $width --height $height $lower_limit --color BACK#$load_color $vertical_label ".
829               "--title '$title' $extras $background ".
830               $series;
831}
832
833$debug=0;
834
835
836# Did we generate a command?   Run it.
837if($command) 
838{
839    /*Make sure the image is not cached*/
840    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");   // Date in the past
841    header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
842    header ("Cache-Control: no-cache, must-revalidate");   // HTTP/1.1
843    header ("Pragma: no-cache");                     // HTTP/1.0
844    if ($debug) 
845    {
846        header ("Content-type: text/html");
847        print "$command\n\n\n\n\n";
848    } 
849    else 
850    {
851        header ("Content-type: image/gif");
852        passthru($command);
853    }
854}
855?>
Note: See TracBrowser for help on using the repository browser.