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

Last change on this file since 797 was 797, checked in by ramonb, 11 years ago
  • give single metric graphs: Now/Min/Avg/Max? values for current and archive RRDS
  • Property svn:keywords set to Id
File size: 19.2 KB
RevLine 
[143]1<?php
[225]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 *
[231]22 * SVN $Id: graph.php 797 2013-04-06 15:25:58Z ramonb $
[225]23 */
24
[761]25global $rrds, $start, $r, $conf, $m;
[143]26
[409]27include "./libtoga.php";
28
[761]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"] ));
[751]42
[761]43if( strpos( $size, 'overview' ) )
44{
45    $my_dir = getcwd();
[751]46
[761]47    global $context;
[751]48
[761]49    $context = 'host';
[751]50
[761]51    chdir( $GANGLIA_PATH );
[751]52
[761]53    include "./ganglia.php";
54    include "./get_ganglia.php";
[751]55
[761]56    chdir( $my_dir );
57}
58
[717]59if ( !empty( $_GET ) ) 
60{
[143]61        extract( $_GET );
62}
63
[409]64$sourcetime = $st;
65
[143]66
[145]67$cluster = $c;
68$metricname = ($g) ? $g : $m;
69
[143]70# Assumes we have a $start variable (set in get_context.php).
[717]71if ($size == "small") 
72{
73    $height = 40;
74    $width = 130;
75} 
76else if ($size == "medium") 
77{
78    $height = 75;
79    $width = 300;
80} 
[731]81else if ($size == "overview-medium") 
82{
83    $height = 75;
84    $width = 300;
85} 
[717]86else 
87{
88    $height = 100;
89    $width = 400;
[145]90}
[143]91
[796]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 = '';
[797]102   $extras = ' --font LEGEND:7 ';
[796]103} else if ($size == 'overview-medium') {
104   $eol1   = '';
105   $space1 = '';
106   $space2 = '';
[797]107   $extras = ' --font LEGEND:7 ';
[796]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
[795]122$jobstart_color = "3AE302";
123$jobstop_color = "F5164A";
[731]124
[717]125if($command) 
126{
[145]127      $command = '';
128}
[143]129
[145]130$graph = $metricname;
[143]131
[731]132$rrd_dirs = Array();
133
[717]134if (isset($graph)) 
135{
136    $series = '';
[739]137    if( $size == 'overview-medium' )
[717]138    {
[739]139        $rrd_dirs[] = $conf['rrds'] . '/' . $cluster .'/'. $hostname;
[717]140    }
[739]141    else
142    {
143        $trd = new TarchRrdGraph( $cluster, $hostname );
144        $rrd_dirs = $trd->getRrdDirs( $period_start, $period_stop );
[779]145
[739]146    }
[143]147
[717]148    if($graph == "cpu_report") 
149    {
[433]150
[717]151        $style = "CPU";
[143]152
[717]153        $upper_limit = "--upper-limit 100 --rigid";
154        $lower_limit = "--lower-limit 0";
[143]155
[717]156        $vertical_label = "--vertical-label Percent ";
[143]157
[717]158        $def_nr = 0;
[143]159
[717]160        foreach( $rrd_dirs as $rrd_dir ) 
161        {
[143]162
[717]163            if( $def_nr == 0 ) 
164            {
[143]165
[717]166                $user_str = ":'User CPU'";
167                $nice_str = ":'Nice CPU'";
168                $system_str = ":'System CPU'";
169                $wio_str = ":'WAIT CPU'";
170                $idle_str = ":'Idle CPU'";
171            } 
172            else 
173            {
[143]174
[717]175                $user_str = "";
176                $nice_str = "";
177                $system_str = "";
178                $wio_str = "";
179                $idle_str = "";
180            }
[143]181
[717]182            $series .= "DEF:'cpu_user${def_nr}'='${rrd_dir}/cpu_user.rrd':'sum':AVERAGE "
183                ."DEF:'cpu_nice${def_nr}'='${rrd_dir}/cpu_nice.rrd':'sum':AVERAGE "
184                ."DEF:'cpu_system${def_nr}'='${rrd_dir}/cpu_system.rrd':'sum':AVERAGE "
185                ."DEF:'cpu_idle${def_nr}'='${rrd_dir}/cpu_idle.rrd':'sum':AVERAGE "
[731]186                ."AREA:'cpu_user${def_nr}'#".$conf['cpu_user_color']."${user_str} "
187                ."STACK:'cpu_nice${def_nr}'#".$conf['cpu_nice_color']."${nice_str} "
188                ."STACK:'cpu_system${def_nr}'#".$conf['cpu_system_color']."${system_str} ";
[143]189
[717]190            if (file_exists("$rrd_dir/cpu_wio.rrd")) 
191            {
192                $series .= "DEF:'cpu_wio${def_nr}'='${rrd_dir}/cpu_wio.rrd':'sum':AVERAGE "
[731]193                    ."STACK:'cpu_wio${def_nr}'#".$conf['cpu_wio_color']."${wio_str} ";
[717]194            }
[143]195
[731]196            $series .= "STACK:'cpu_idle${def_nr}'#".$conf['cpu_idle_color']."${idle_str} ";
[143]197
[717]198            $def_nr++;
199        }
[143]200
[717]201    } 
202    else if ($graph == "job_report") 
203    {
204        $style = "Jobs";
[409]205
[717]206        $lower_limit = "--lower-limit 0 --rigid";
207        $vertical_label = "--vertical-label Jobs";
[409]208
[717]209        $def_nr = 0;
[409]210
[761]211        $rrd_dir = $conf['rrds'] . "/$clustername/$hostname/";
[409]212
[726]213        $rj_rrd    = $rrd_dir . "zplugin_monarch_rj.rrd";
214        $qj_rrd    = $rrd_dir . "zplugin_monarch_qj.rrd";
[409]215
[717]216        $sorted_hosts    = array();
[738]217        $sorted_hosts[]  = $rjqj_host;
[409]218
[717]219        $rj_str = ":'Running Jobs'";
220        $qj_str = ":'Queued Jobs'";
[409]221
[717]222        $series .= "DEF:'running_jobs'='${rj_rrd}':'sum':AVERAGE "
[796]223            ."DEF:'queued_jobs'='${qj_rrd}':'sum':AVERAGE ";
[409]224
[717]225       
[796]226        $series .= "LINE3:'running_jobs'#ff0000${rj_str} ";
[409]227
[796]228        if ( $conf['graphreport_stats'] ) 
229        {
230            $series .= "CDEF:running_pos=running_jobs,0,INF,LIMIT "
231                    . "VDEF:running_last=running_pos,LAST "
232                    . "VDEF:running_min=running_pos,MINIMUM "
233                    . "VDEF:running_avg=running_pos,AVERAGE "
234                    . "VDEF:running_max=running_pos,MAXIMUM "
235                    . "GPRINT:'running_last':' ${space1}Now\:%5.0lf' "
236                    . "GPRINT:'running_min':'${space1}Min\:%5.0lf${eol1}' "
237                    . "GPRINT:'running_avg':'${space2}Avg\:%5.0lf' "
238                    . "GPRINT:'running_max':'${space1}Max\:%5.0lf\\l' ";
239        }
240
241        $series .= "LINE3:'queued_jobs'#999999${qj_str} ";
242
243        if ( $conf['graphreport_stats'] ) 
244        {
245            $series .= "CDEF:queued_pos=queued_jobs,0,INF,LIMIT "
246                    . "VDEF:queued_last=queued_pos,LAST "
247                    . "VDEF:queued_min=queued_pos,MINIMUM "
248                    . "VDEF:queued_avg=queued_pos,AVERAGE "
249                    . "VDEF:queued_max=queued_pos,MAXIMUM "
250                    . "GPRINT:'queued_last':'  ${space1}Now\:%5.0lf' "
251                    . "GPRINT:'queued_min':'${space1}Min\:%5.0lf${eol1}' "
252                    . "GPRINT:'queued_avg':'${space2}Avg\:%5.0lf' "
253                    . "GPRINT:'queued_max':'${space1}Max\:%5.0lf\\l' ";
254        }
[717]255    } 
256    else if ($graph == "mem_report") 
257    {
258        $style = "Memory";
[143]259
[717]260        $lower_limit = "--lower-limit 0 --rigid";
[796]261        $extras .= "--base 1024";
[717]262        $vertical_label = "--vertical-label Bytes";
[143]263
[717]264        $def_nr = 0;
[143]265
[717]266        foreach( $rrd_dirs as $rrd_dir ) 
267        {
[143]268
[717]269            if( $def_nr == 0 ) 
270            {
[143]271
[717]272                $memuse_str = ":'Memory Used'";
273                $memshared_str = ":'Memory Shared'";
274                $memcached_str = ":'Memory Cached'";
275                $membuff_str = ":'Memory Buffered'";
276                $memswap_str = ":'Memory Swapped'";
277                $total_str = ":'Total In-Core Memory'";
278            } 
279            else 
280            {
[143]281
[717]282                $memuse_str = "";
283                $memshared_str = "";
284                $memcached_str = "";
285                $membuff_str = "";
286                $memswap_str = "";
287                $total_str = "";
288            }
[143]289
[717]290            $series .= "DEF:'mem_total${def_nr}'='${rrd_dir}/mem_total.rrd':'sum':AVERAGE "
291                ."CDEF:'bmem_total${def_nr}'=mem_total${def_nr},1024,* "
292                ."DEF:'mem_shared${def_nr}'='${rrd_dir}/mem_shared.rrd':'sum':AVERAGE "
293                ."CDEF:'bmem_shared${def_nr}'=mem_shared${def_nr},1024,* "
294                ."DEF:'mem_free${def_nr}'='${rrd_dir}/mem_free.rrd':'sum':AVERAGE "
295                ."CDEF:'bmem_free${def_nr}'=mem_free${def_nr},1024,* "
296                ."DEF:'mem_cached${def_nr}'='${rrd_dir}/mem_cached.rrd':'sum':AVERAGE "
297                ."CDEF:'bmem_cached${def_nr}'=mem_cached${def_nr},1024,* "
298                ."DEF:'mem_buffers${def_nr}'='${rrd_dir}/mem_buffers.rrd':'sum':AVERAGE "
299                ."CDEF:'bmem_buffers${def_nr}'=mem_buffers${def_nr},1024,* "
300                ."CDEF:'bmem_used${def_nr}'='bmem_total${def_nr}','bmem_shared${def_nr}',-,'bmem_free${def_nr}',-,'bmem_cached${def_nr}',-,'bmem_buffers${def_nr}',- "
[731]301                ."AREA:'bmem_used${def_nr}'#".$conf['mem_used_color']."${memuse_str} "
302                ."STACK:'bmem_shared${def_nr}'#".$conf['mem_shared_color']."${memshared_str} "
303                ."STACK:'bmem_cached${def_nr}'#".$conf['mem_cached_color']."${memcached_str} "
304                ."STACK:'bmem_buffers${def_nr}'#".$conf['mem_buffered_color']."${membuff_str} ";
[145]305
[717]306            if (file_exists("$rrd_dir/swap_total.rrd")) 
307            {
308                $series .= "DEF:'swap_total${def_nr}'='${rrd_dir}/swap_total.rrd':'sum':AVERAGE "
309                    ."DEF:'swap_free${def_nr}'='${rrd_dir}/swap_free.rrd':'sum':AVERAGE "
310                    ."CDEF:'bmem_swapped${def_nr}'='swap_total${def_nr}','swap_free${def_nr}',-,1024,* "
[731]311                    ."STACK:'bmem_swapped${def_nr}'#".$conf['mem_swapped_color']."${memswap_str} ";
[717]312            }
[145]313
[731]314            $series .= "LINE2:'bmem_total${def_nr}'#".$conf['cpu_num_color']."${total_str} ";
[145]315
[717]316            $def_nr++;
317        }
[145]318
[717]319    } 
320    else if ($graph == "load_report") 
321    {
322        $style = "Load";
[145]323
[717]324        $lower_limit = "--lower-limit 0 --rigid";
325        $vertical_label = "--vertical-label 'Load/Procs'";
[145]326
[717]327        $def_nr = 0;
[145]328
[717]329        foreach( $rrd_dirs as $rrd_dir ) 
330        {
[145]331
[717]332            if( $def_nr == 0 ) 
333            {
[145]334
[717]335                $load_str = ":'1-min Load'";
336                $cpu_str = ":'CPUs'";
337                $run_str = ":'Running Processes'";
338            } 
339            else 
340            {
341                $load_str = "";
342                $cpu_str = "";
343                $run_str = "";
344            }
[145]345
[717]346            $series .= "DEF:'load_one${def_nr}'='${rrd_dir}/load_one.rrd':'sum':AVERAGE "
347                ."DEF:'proc_run${def_nr}'='${rrd_dir}/proc_run.rrd':'sum':AVERAGE "
348                ."DEF:'cpu_num${def_nr}'='${rrd_dir}/cpu_num.rrd':'sum':AVERAGE ";
[731]349            $series .="AREA:'load_one${def_nr}'#".$conf['load_one_color']."${load_str} ";
350            $series .="LINE2:'cpu_num${def_nr}'#".$conf['cpu_num_color']."${cpu_str} ";
351            $series .="LINE2:'proc_run${def_nr}'#".$conf['proc_run_color']."${run_str} ";
[145]352
[717]353            $def_nr++;
354        }
[145]355
[717]356    } 
357    else if ($graph == "network_report") 
358    {
359        $style = "Network";
[145]360
[717]361        $lower_limit = "--lower-limit 0 --rigid";
[796]362        $extras .= "--base 1024";
[717]363        $vertical_label = "--vertical-label 'Bytes/sec'";
[145]364
[717]365        $def_nr = 0;
[145]366
[717]367        foreach( $rrd_dirs as $rrd_dir ) 
368        {
[145]369
[717]370            if( $def_nr == 0 ) 
371            {
[145]372
[717]373                $in_str = ":'In'";
374                $out_str = ":'Out'";
375            } 
376            else 
377            {
[145]378
[717]379                $in_str = "";
380                $out_str = "";
381            }
[145]382
[717]383            $series .= "DEF:'bytes_in${def_nr}'='${rrd_dir}/bytes_in.rrd':'sum':AVERAGE "
384                ."DEF:'bytes_out${def_nr}'='${rrd_dir}/bytes_out.rrd':'sum':AVERAGE "
[731]385                ."LINE2:'bytes_in${def_nr}'#".$conf['mem_cached_color']."${in_str} "
386                ."LINE2:'bytes_out${def_nr}'#".$conf['mem_used_color']."${out_str} ";
[145]387
[717]388            $def_nr++;
389        }
[145]390
[717]391    } 
392    else if ($graph == "packet_report") 
393    {
394        $style = "Packets";
[145]395
[717]396        $lower_limit = "--lower-limit 0 --rigid";
[796]397        $extras .= "--base 1024";
[717]398        $vertical_label = "--vertical-label 'Packets/sec'";
[145]399
[717]400        $def_nr = 0;
[145]401
[717]402        foreach( $rrd_dirs as $rrd_dir ) 
403        {
[145]404
[717]405            if( $def_nr == 0 ) 
406            {
[145]407
[717]408                $in_str = ":'In'";
409                $out_str = ":'Out'";
410            } 
411            else 
412            {
[145]413
[717]414                $in_str = "";
415                $out_str = "";
416            }
[145]417
[717]418            $series .= "DEF:'bytes_in${def_nr}'='${rrd_dir}/pkts_in.rrd':'sum':AVERAGE "
419                ."DEF:'bytes_out${def_nr}'='${rrd_dir}/pkts_out.rrd':'sum':AVERAGE "
[731]420                ."LINE2:'bytes_in${def_nr}'#".$conf['mem_cached_color']."${in_str} "
421                ."LINE2:'bytes_out${def_nr}'#".$conf['mem_used_color']."${out_str} ";
[145]422
[717]423            $def_nr++;
424        }
[145]425
[717]426    } 
427    else 
428    {
429        /* Custom graph */
430        $style = "";
[145]431
[717]432        $subtitle = $metricname;
[736]433        if($context == "host")
[717]434        {
435            if ($size == "small")
436                $prefix = $metricname;
437            else
438                $prefix = $hostname;
[145]439
[717]440            $value = $value>1000 ? number_format($value) : number_format($value, 2);
441        }
[145]442
[717]443        if (is_numeric($max))
444            $upper_limit = "--upper-limit '$max' ";
445        if (is_numeric($min))
446            $lower_limit ="--lower-limit '$min' ";
[145]447
[717]448        if ($vlabel)
449        {
450            $vertical_label = "--vertical-label '$vlabel'";
451        }
452        else 
453        {
454            if ($upper_limit or $lower_limit) 
455            {
456                $max = $max>1000 ? number_format($max) : number_format($max, 2);
457                $min = $min>0 ? number_format($min,2) : $min;
[145]458
[717]459                $vertical_label ="--vertical-label '$min - $max' ";
460            }
461        }
[145]462
[717]463        $def_nr = 0;
[145]464
[797]465
[717]466        foreach( $rrd_dirs as $rrd_dir ) 
467        {
[145]468
[717]469            if( $def_nr == 0 ) 
470            {
471                $title_str = ":'${subtitle}'";
472            } 
473            else 
474            {
475                $title_str = "";
476            }
[145]477
[717]478            $rrd_file = "$rrd_dir/$metricname.rrd";
479            $series .= "DEF:'sum${def_nr}'='$rrd_file':'sum':AVERAGE "
[731]480                ."AREA:'sum${def_nr}'#".$conf['default_metric_color']."${title_str} ";
[145]481
[797]482            if( $conf['graphreport_stats'] )
483            {
484                $series .= "CDEF:sum${def_nr}_nonans=sum${def_nr},UN,0,sum${def_nr},IF ";
485            }
486
[717]487            $def_nr++;
488        }
[145]489
[797]490        if( $conf['graphreport_stats'] )
491        {
492            $s_last         = $def_nr - 1;
493            $series_sum     = "CDEF:sum=sum0_nonans";
494
495            if( $def_nr > 1 )
496            {
497                foreach (range(1, ($s_last)) as $print_nr ) 
498                {
499                    $series_sum     .= ",sum{$print_nr}_nonans,+";
500                }
501            }
502
503            $series_sum .= " ";
504
505            $series_last    = "VDEF:'sum_last'=sum,LAST ";
506            $series_minimum = "VDEF:'sum_min'=sum,MINIMUM ";
507            $series_average = "VDEF:'sum_avg'=sum,AVERAGE ";
508            $series_maximum = "VDEF:'sum_max'=sum,MAXIMUM ";
509
510            $series .= $series_sum . $series_last . $series_minimum . $series_average . $series_maximum;
511
512            $series .= "COMMENT:\"\\n\" ";
513            $series .= "GPRINT:'sum_last':'${space1}Now\:%6.1lf%s' "
514                    . "GPRINT:'sum_min':'${space1}Min\:%6.1lf%s${eol1}' "
515                    . "GPRINT:'sum_avg':'${space2}Avg\:%6.1lf%s' "
516                    . "GPRINT:'sum_max':'${space1}Max\:%6.1lf%s\\l' ";
517        }
[717]518    }
[763]519}
520if( $series != '' ) 
521{
522    if ($job_start)
[717]523    {
[795]524        $series .= "VRULE:${job_start}#${jobstart_color}:'job start':dashes=4,2 ";
[717]525    }
[763]526    if ($job_stop)
527    {
[795]528        $series .= "VRULE:${job_stop}#${jobstop_color}:'job stop':dashes=4,2 ";
[763]529    }
[145]530}
531
[759]532if($graph == "job_report")
[758]533{
[759]534    if($range == 'job' )
535    {
536        $title = "Last: $j_title";
537    }
538    else
539    {
540        $title = "Last: $range";
541    }
[758]542}
543else
544{
545    $title = "$hostname";
546}
[145]547
[717]548function determineXGrid( $p_start, $p_stop ) 
549{
[152]550
[717]551    $period = intval( $p_stop - $p_start );
[152]552
[717]553    // Syntax: <minor_grid_lines_time_declr>:<major_grid_lines_time_declr>:<labels_time_declr>:<offset>:<format>
554    //
555    // Where each <*time_declr*> = <time_type>:<time_interval>
[152]556
[717]557    //$my_lines1 = intval( $period / 3.0 );
558    //$my_lines2 = intval( $period / 6.0 );
[159]559
[717]560    //$my_grid = "SECOND:$my_lines2:SECOND:$my_lines1:SECOND:$my_lines1:0:%R";
[159]561
[717]562    //return "--x-grid $my_grid";
[159]563
[717]564    // Less than 1 minute
565    if( $period < 60 ) 
566    {
[152]567
[717]568        $tm_formt = "%X";
569        $my_grid = "SECOND:15:SECOND:30:SECOND:30:0:$tm_formt";
[152]570
[717]571    // Less than 10 minutes
572    } 
573    else if( $period < 600 ) 
574    {
[152]575
[717]576        $tm_formt = "%R";
577        $my_grid = "MINUTE:1:MINUTE:3:MINUTE:3:0:$tm_formt";
[152]578
[717]579    // Less than 1 hour
580    } 
581    else if( $period < 3600 ) 
582    {
[152]583
[717]584        $tm_formt = "%R";
585        $my_grid = "MINUTE:5:MINUTE:15:MINUTE:15:0:$tm_formt";
[152]586
[717]587    // Less than 15 hour
588    } 
589    else if( $period < 3600 ) 
590    {
[159]591
[717]592        $tm_formt = "%R";
593        $my_grid = "HOUR:1:HOUR:2:HOUR:2:0:$tm_formt";
[159]594
[717]595    // Less than 1 day
596    //
597    } 
598    else if( $period < 86400 ) 
599    {
[152]600
[717]601        $tm_formt = "%R";
602        $my_grid = "HOUR:2:HOUR:5:HOUR:5:0:$tm_formt";
[152]603
[717]604    // Less than 15 days
605    //
606    } 
607    else if( $period < 1296000 ) 
608    {
[152]609
[717]610        $tm_formt = "%e-%m";
611        $my_grid = "HOUR:1:DAY:3:DAY:3:0:'$tm_formt'";
612       
613    // Less than 30 days (a month)
614    //
615    } 
616    else if( $period < 2592000 ) 
617    {
[152]618
[717]619        $tm_formt = "%e-%m";
620        $my_grid = "DAY:5:DAY:10:DAY:10:0:'$tm_formt'";
621    }
[152]622
[717]623    if( isset( $my_grid ) ) 
624    {
[152]625
[717]626        $ret_str = "--x-grid $my_grid";
627        return array($ret_str,$tm_formt);
[152]628
[717]629    } 
630    else 
631    {
632        return array( "", "" );
633    }
[152]634}
635
[193]636$lower_limit = "--lower-limit 0";
[159]637
[734]638if( !isset( $load_color ) or ( $load_color == '') )
639{
640    $load_color = 'FFFFFF';
641}
642
[409]643# Calculate time range.
[733]644if ( isset($sourcetime) )
[409]645{
[717]646    $end = $sourcetime;
647    # Get_context makes start negative.
648    $start = $sourcetime + $start;
[409]649
[717]650    # Fix from Phil Radden, but step is not always 15 anymore.
651    if ($range=="month")
[733]652    {
[717]653        $end = floor($end / 672) * 672;
[733]654    }
655        $command = $conf['rrdtool']. " graph - --start $start --end $end ".
656                "--width $width --height $height $lower_limit ".
657                "--title '$title' $extras $background ".
658                $series;
[409]659}
[733]660else
[717]661{
662    $command = $conf['rrdtool'] . " graph - --start $period_start --end $period_stop ".
[733]663               "--width $width --height $height $lower_limit --color BACK#$load_color ".
664               "--title '$title' $extras $background ".
665               $series;
[409]666}
667
[143]668$debug=0;
669
[733]670
[143]671# Did we generate a command?   Run it.
[717]672if($command) 
673{
674    /*Make sure the image is not cached*/
675    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");   // Date in the past
676    header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
677    header ("Cache-Control: no-cache, must-revalidate");   // HTTP/1.1
678    header ("Pragma: no-cache");                     // HTTP/1.0
679    if ($debug) 
680    {
681        header ("Content-type: text/html");
682        print "$command\n\n\n\n\n";
683    } 
684    else 
685    {
686        header ("Content-type: image/gif");
687        passthru($command);
688    }
[145]689}
[143]690?>
Note: See TracBrowser for help on using the repository browser.