~ubuntu-dev/ubuntu/lucid/zabbix/lucid-201002110857

« back to all changes in this revision

Viewing changes to frontends/php/include/classes/chart.inc.php

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Haas
  • Date: 2009-10-10 12:21:16 UTC
  • mfrom: (1.1.10 upstream) (8.2.6 sid)
  • Revision ID: james.westby@ubuntu.com-20091010122116-44k2zdq57rb40i6z
Tags: 1:1.6.6-2
* debian/po/ja.po updated (Closes: #548651)
* debian/po/cs.po updated (Closes: #548675)
* debian/po/sv.po updated (Closes: #548796)
* debian/po/de.po updated (Closes: #549248)
* debian/po/it.po updated (Closes: #549579)
* debian/po/pt.po updated (Closes: #550087)
* debian/po/ru.po updated (Closes: #550102)
* debian/po/es.po updated (Closes: #550173)
* debian/po/fr.po updated (Closes: #550315)
* Manpages for zabbix_server and zabbix_agent added (Closes: #496696)
* Added hint about the difference of the zabbix_agent.conf and
  zabbix_agentd.conf in each config file as a comment. (Closes: #548701)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
 
/* 
 
2
/*
3
3
** ZABBIX
4
4
** Copyright (C) 2000-2007 SIA Zabbix
5
5
**
25
25
 
26
26
        function Chart($type = GRAPH_TYPE_NORMAL){
27
27
                parent::Graph($type);
28
 
                
 
28
 
29
29
                $this->yaxismin = null;
30
30
                $this->yaxismax = null;
31
31
 
32
32
                $this->triggers = array();
33
 
                
 
33
 
34
34
                $this->yaxistype=GRAPH_YAXIS_TYPE_CALCULATED;
35
35
                $this->yaxisright=0;
36
36
                $this->yaxisleft=0;
37
 
                
 
37
 
38
38
                $this->percentile = array(
39
 
                                'left' => array(  
40
 
                                        'percent' => 0,         // draw percentage line 
 
39
                                'left' => array(
 
40
                                        'percent' => 0,         // draw percentage line
41
41
                                        'value' => 0            // calculated percentage value left y axis
42
42
                                ),
43
 
                                
 
43
 
44
44
                                'right' => array(
45
 
                                        'percent' => 0,         // draw percentage line 
 
45
                                        'percent' => 0,         // draw percentage line
46
46
                                        'value' => 0            // calculated percentage value right y axis
47
47
                                )
48
48
                        );
49
 
                
 
49
 
50
50
                $this->m_showWorkPeriod = 1;
51
51
                $this->m_showTriggers = 1;
52
 
                
 
52
 
53
53
                $this->zero = array();
54
54
                $this->graphorientation = '';
55
 
                
 
55
 
56
56
                $this->gridLinesCount = NULL;           // How many grids to draw
57
57
                $this->gridPixels = 40;         // optimal grid size
58
58
        }
104
104
                if($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT)
105
105
                        $this->yaxisright=1;
106
106
//              SDI($this->items);
107
 
                
 
107
 
108
108
                $this->num++;
109
109
        }
110
 
        
 
110
 
111
111
        function CheckGraphOrientation($value){
112
 
                
 
112
 
113
113
                if(!empty($this->graphorientation)){
114
114
                        if(($this->graphorientation == '+') && ($value<0)){
115
115
//                                      Error();
116
 
                        } 
 
116
                        }
117
117
                        else if(($this->graphorientation == '-') && ($value>0)){
118
118
//                                      Error();
119
119
                        }
120
 
                } 
 
120
                }
121
121
                else {
122
122
                        if($value < 0){
123
123
                                $this->graphorientation = '-';
139
139
        function setYAxisType($yaxistype){
140
140
                $this->yaxistype=$yaxistype;
141
141
        }
142
 
        
 
142
 
143
143
        function setLeftPercentage($percentile){
144
144
                $this->percentile['left']['percent'] = $percentile;
145
145
        }
146
 
        
 
146
 
147
147
        function setRightPercentage($percentile){
148
148
                $this->percentile['right']['percent'] = $percentile;
149
149
        }
160
160
                                        $this->GetColor('Gray')
161
161
                                );
162
162
                }
163
 
        
 
163
 
164
164
                $vline_count = round($this->sizeX / $this->gridPixels);
165
165
                for($i=1;$i<=$vline_count;$i++){
166
166
                        dashedline($this->im,
174
174
 
175
175
                $old_day=-1;
176
176
                for($i=0;$i<=($vline_count+1);$i++){
177
 
                        imagestringup($this->im, 
 
177
                        imagestringup($this->im,
178
178
                                                1,
179
 
                                                $i*($this->sizeX/($vline_count+1))+$this->shiftXleft-3, 
180
 
                                                $this->sizeY+$this->shiftY+57, 
181
 
                                                date('      H:i',$this->from_time+$i*($this->period/($vline_count+1))), 
 
179
                                                $i*($this->sizeX/($vline_count+1))+$this->shiftXleft-3,
 
180
                                                $this->sizeY+$this->shiftY+57,
 
181
                                                date('      H:i',$this->from_time+$i*($this->period/($vline_count+1))),
182
182
                                                $this->GetColor('Black No Alpha')
183
183
                                );
184
184
 
185
185
                        $new_day=date('d',$this->from_time+$i*($this->period/($vline_count+1)));
186
186
                        if(($old_day != $new_day) || ($i==($vline_count+1))){
187
187
                                $old_day=$new_day;
188
 
                                imagestringup($this->im, 
 
188
                                imagestringup($this->im,
189
189
                                                                        1,
190
 
                                                                        $i*($this->sizeX/($vline_count+1))+$this->shiftXleft-3, 
191
 
                                                                        $this->sizeY+$this->shiftY+57, 
192
 
                                                                        date('m.d H:i',$this->from_time+$i*($this->period/($vline_count+1))), 
 
190
                                                                        $i*($this->sizeX/($vline_count+1))+$this->shiftXleft-3,
 
191
                                                                        $this->sizeY+$this->shiftY+57,
 
192
                                                                        date('m.d H:i',$this->from_time+$i*($this->period/($vline_count+1))),
193
193
                                                                        $this->GetColor('Dark Red No Alpha')
194
194
                                                        );
195
195
 
236
236
 
237
237
                        $x1 = round((($start-$from)*$this->sizeX)/$this->period) + $this->shiftXleft;
238
238
                        $x2 = round((($end-$from)*$this->sizeX)/$this->period) + $this->shiftXleft;
239
 
                        
 
239
 
240
240
                        //draw rectangle
241
241
                        imagefilledrectangle(
242
242
                                $this->im,
249
249
                        $start = find_period_start($periods,$end);
250
250
                }
251
251
        }
252
 
        
 
252
 
253
253
        function calcTriggers(){
254
254
                $this->triggers = array();
255
255
                if($this->m_showTriggers != 1) return;
261
261
                $db_triggers = DBselect('SELECT distinct tr.triggerid,tr.expression,tr.priority '.
262
262
                                                ' FROM triggers tr,functions f,items i'.
263
263
                                                ' WHERE tr.triggerid=f.triggerid '.
264
 
                                                        " AND f.function IN ('last','min','max') ".
 
264
                                                        " AND f.function IN ('last','min','avg','max') ".
265
265
                                                        ' AND tr.status='.TRIGGER_STATUS_ENABLED.
266
266
                                                        ' AND i.itemid=f.itemid '.
267
267
                                                        ' AND f.itemid='.$this->items[0]['itemid'].
297
297
                                ));
298
298
                        ++$cnt;
299
299
                }
300
 
                
 
300
 
301
301
        }
302
302
        function drawTriggers(){
303
303
                if($this->m_showTriggers != 1) return;
312
312
                                $trigger['y'],
313
313
                                $this->GetColor($trigger['color']));
314
314
                }
315
 
                
 
315
 
316
316
        }
317
317
 
318
 
        
 
318
 
319
319
        function drawLegend(){
320
320
                $max_host_len=0;
321
321
                $max_desc_len=0;
324
324
                        if(strlen($this->items[$i]['description'])>$max_desc_len)       $max_desc_len=strlen($this->items[$i]['description']);
325
325
                }
326
326
 
327
 
                $units = array( 
328
 
                                        'left'=>0, 
 
327
                $units = array(
 
328
                                        'left'=>0,
329
329
                                        'right'=>0
330
330
                                );
331
 
                
 
331
 
332
332
                $i = ($this->type == GRAPH_TYPE_STACKED)?($this->num-1):0;
333
333
//              for($i=0;$i<$this->num;$i++){
334
334
                while(($i>=0) && ($i<$this->num)){
338
338
                                $color = $this->GetColor('HistoryMinMax');
339
339
                        }
340
340
                        else{
341
 
                                $color = $this->GetColor($this->items[$i]['color']);
 
341
                                $color = $this->GetColor($this->items[$i]['color'], GRAPH_STACKED_ALFA);
342
342
                                switch($this->items[$i]['calc_fnc']){
343
343
                                        case CALC_FNC_MIN:      $fnc_name = 'min';      break;
344
344
                                        case CALC_FNC_MAX:      $fnc_name = 'max';      break;
356
356
                                else{
357
357
                                        $units['right'] = $this->items[$i]['units'];
358
358
                                }
359
 
                                
 
359
 
360
360
                                $str=sprintf('%s: %s [%s] [min:%s max:%s last:%s]',
361
361
                                        str_pad($this->items[$i]['host'],$max_host_len,' '),
362
362
                                        str_pad($this->items[$i]['description'],$max_desc_len,' '),
387
387
                                                        $this->GetColor('Black No Alpha')
388
388
                                                );
389
389
 
390
 
                        imagestring($this->im, 
 
390
                        imagestring($this->im,
391
391
                                                        2,
392
392
                                                        $this->shiftXleft+9,
393
393
                                                        $this->sizeY+$this->shiftY+(62-5)+12*$i,
394
394
                                                        $str,
395
395
                                                        $this->GetColor('Black No Alpha')
396
396
                                                );
397
 
                                                
 
397
 
398
398
                        $i +=($this->type == GRAPH_TYPE_STACKED)?-1:1;
399
399
                }
400
400
 
416
416
                                $this->GetColor('Black No Alpha'));
417
417
 
418
418
                        imagestring(
419
 
                                $this->im, 
 
419
                                $this->im,
420
420
                                2,
421
421
                                $this->shiftXleft+9,
422
422
                                $this->sizeY+$this->shiftY+(62-5)+12*$i,
425
425
                        ++$i;
426
426
                }
427
427
 
428
 
// Draw percentile      
 
428
// Draw percentile
429
429
                if($this->type == GRAPH_TYPE_NORMAL){
430
430
                        $color = 'FF0000';
431
431
                        foreach($this->percentile as $side => $percentile){
447
447
                                                        3,
448
448
                                                        $this->GetColor($color)
449
449
                                                );
450
 
                                                
 
450
 
451
451
                                        imagepolygon($this->im,
452
452
                                                        array(
453
453
                                                                $this->shiftXleft+2,$this->sizeY+$this->shiftY+61+12*$i,
457
457
                                                        3,
458
458
                                                        $this->GetColor('Black No Alpha')
459
459
                                                );
460
 
                                                                
 
460
 
461
461
                                        imagestring(
462
 
                                                $this->im, 
 
462
                                                $this->im,
463
463
                                                2,
464
464
                                                $this->shiftXleft+9,
465
465
                                                $this->sizeY+$this->shiftY+(62-5)+12*$i,
466
466
                                                sprintf($str,$percentile['percent'],convert_units($percentile['value'],$units[$side])),
467
467
                                                $this->GetColor('Black No Alpha'));
468
 
                                                
 
468
 
469
469
                                        $i++;
470
470
                                        $color = '00AA00';
471
471
                                }
473
473
                }
474
474
        }
475
475
 
476
 
        function drawElement(&$data, $from, $to, $minX, $maxX, $minY, $maxY, $drawtype, $max_color, $avg_color, $min_color, $minmax_color,$calc_fnc, $axisside){        
 
476
        function drawElement(&$data, $from, $to, $minX, $maxX, $minY, $maxY, $drawtype, $max_color, $avg_color, $min_color, $minmax_color,$calc_fnc, $axisside){
477
477
                if(!isset($data->max[$from]) || !isset($data->max[$to])) return;
478
478
 
479
479
                $oxy = $this->oxy[$axisside];
514
514
 
515
515
                $y1avg = $zero - ($avg_from-$oxy)/$unit2px;
516
516
                $y2avg = $zero - ($avg_to-$oxy)/$unit2px;               //*/
517
 
                
 
517
 
518
518
                switch($calc_fnc){
519
519
                        case CALC_FNC_MAX:
520
520
                                $y1 = $y1max;
533
533
                                $a[2] = $x1;            $a[3] = $y1min;
534
534
                                $a[4] = $x2;            $a[5] = $y2min;
535
535
                                $a[6] = $x2;            $a[7] = $y2max;
536
 
                                
 
536
 
537
537
                                imagefilledpolygon($this->im,$a,4,$minmax_color);
538
538
                                imageline($this->im,$x1,$y1max,$x2,$y2max,$max_color);
539
539
                                imageline($this->im,$x1,$y1min,$x2,$y2min,$min_color);
540
 
                                
 
540
 
541
541
                                /* don't use break, avg must be drawed in this statement */
542
542
                                // break;
543
543
                        case CALC_FNC_AVG:
552
552
 
553
553
                $shift_from -= ($shift_from != 0)?($oxy):(0);
554
554
                $shift_to -= ($shift_to != 0)?($oxy):(0);
555
 
                
 
555
 
556
556
                $y1_shift       = $zero - $shift_from/$unit2px;
557
557
                $y2_shift       = $zero - $shift_to/$unit2px;//*/
558
 
                
559
 
                
 
558
 
560
559
// Fixes graph out of bounds problem
561
560
                if( (($y1 > ($this->sizeY+$this->shiftY)) && ($y2 > ($this->sizeY+$this->shiftY))) || (($y1 < $this->shiftY) && ($y2 < $this->shiftY)) ){
562
 
                        if($this->type != GRAPH_TYPE_STACKED) return true;
 
561
                        if($drawtype == GRAPH_ITEM_DRAWTYPE_FILLED_REGION){
 
562
                                if($y1 > ($this->sizeY+$this->shiftY)) $y1 = $this->sizeY+$this->shiftY;
 
563
                                if($y2 > ($this->sizeY+$this->shiftY)) $y2 = $this->sizeY+$this->shiftY;
 
564
                                
 
565
                                if($y1 < ($this->sizeY+$this->shiftY)) $y1 = $this->shiftY;
 
566
                                if($y2 < ($this->sizeY+$this->shiftY)) $y2 = $this->shiftY;
 
567
                        }
 
568
                        else{
 
569
                                return true;
 
570
                        }
563
571
                }
564
572
 
565
573
 
566
574
                $y_first = !(($y1 > ($this->sizeY+$this->shiftY)) || ($y1 < $this->shiftY));
567
575
                $y_second = !(($y2 > ($this->sizeY+$this->shiftY)) || ($y2 < $this->shiftY));
568
 
                
 
576
 
569
577
                if(!$y_first){
570
578
                        $y1 = ($y1 > ($this->sizeY+$this->shiftY))?($this->sizeY+$this->shiftY):$this->shiftY;
571
579
                }
572
 
                
 
580
 
573
581
                if(!$y_second){
574
582
                        $y2 = ($y2 > ($this->sizeY+$this->shiftY))?($this->sizeY+$this->shiftY):$this->shiftY;
575
583
                }
576
584
//--------
577
 
                        
 
585
 
578
586
                /* draw main line */
579
587
                switch($drawtype){
580
588
                        case GRAPH_ITEM_DRAWTYPE_BOLD_LINE:
589
597
                                $a[2] = $x1;            $a[3] = $y1_shift;
590
598
                                $a[4] = $x2;            $a[5] = $y2_shift;
591
599
                                $a[6] = $x2;            $a[7] = $y2;
592
 
                                
 
600
 
593
601
//                                      SDI($a);
594
 
                                
 
602
 
595
603
                                imagefilledpolygon($this->im,$a,4,$avg_color);
596
604
                                break;
597
605
                        case GRAPH_ITEM_DRAWTYPE_DOT:
599
607
                                imagefilledrectangle($this->im,$x2-1,$y2-1,$x2+1,$y2+1,$avg_color);
600
608
                                break;
601
609
                        case GRAPH_ITEM_DRAWTYPE_DASHED_LINE:
602
 
                                if( function_exists('imagesetstyle') ){ 
603
 
                                        
 
610
                                if( function_exists('imagesetstyle') ){
 
611
 
604
612
                                        /* Use imagesetstyle+imageline instead of bugged imagedashedline */
605
613
                                        $style = array($avg_color, $avg_color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT);
606
614
                                        imagesetstyle($this->im, $style);
618
626
                if($this->type != GRAPH_TYPE_NORMAL){
619
627
                        return ;
620
628
                }
621
 
                
 
629
 
622
630
                $values = array(
623
631
                        'left' => array(),
624
632
                        'right'=> array()
625
633
                );
626
 
                
 
634
 
627
635
                $maxX = $this->sizeX;
628
 
                
 
636
 
629
637
// For each metric
630
638
                for($item = 0; $item < $this->num; $item++){
631
639
                        $data = &$this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']];
632
 
                        
 
640
 
633
641
                        if(!isset($data))       continue;
634
642
// For each X
635
643
                        for($i = 0; $i < $maxX; $i++){  // new point
636
644
                                if(($data->count[$i] == 0) && ($i != ($maxX-1))) continue;
637
 
                                
 
645
 
638
646
                                $min = $data->min[$i];
639
647
                                $max = $data->max[$i];
640
648
                                $avg = $data->avg[$i];
641
 
                                
 
649
 
642
650
                                switch($this->items[$item]['calc_fnc']){
643
651
                                        case CALC_FNC_MAX:
644
652
                                                $value = $max;
672
680
//SDI($side.' : '.$this->percentile[$side]['value']);
673
681
                }
674
682
        }
675
 
        
 
683
 
676
684
// Calculation of minimum Y axis
677
685
        function calculateMinY($side){
678
686
                if($this->yaxistype==GRAPH_YAXIS_TYPE_FIXED){
679
687
                        return $this->yaxismin;
680
 
                } 
 
688
                }
681
689
                else if($this->yaxistype==GRAPH_YAXIS_TYPE_CALCULATED_0_MIN) {
682
690
                        return 0;
683
 
                } 
 
691
                }
684
692
                else{
685
693
                        unset($minY);
686
694
                        for($i=0;$i<$this->num;$i++){
687
 
                        
 
695
 
688
696
                                if($this->items[$i]['axisside'] != $side)
689
697
                                        continue;
690
698
 
691
699
                                foreach(array(GRAPH_ITEM_SIMPLE, GRAPH_ITEM_AGGREGATED) as $type){
692
 
                                
 
700
 
693
701
                                        if(!isset($this->data[$this->items[$i]['itemid']][$type]))
694
702
                                                continue;
695
703
 
705
713
                                        switch($calc_fnc){
706
714
                                                case CALC_FNC_ALL:      /* use min */
707
715
                                                case CALC_FNC_MIN:
708
 
                                                        $val = $data->min; 
709
 
                                                        $shift_val = $data->shift_min; 
 
716
                                                        $val = $data->min;
 
717
                                                        $shift_val = $data->shift_min;
710
718
                                                        break;
711
719
                                                case CALC_FNC_MAX:
712
 
                                                        $val = $data->max; 
713
 
                                                        $shift_val = $data->shift_max; 
 
720
                                                        $val = $data->max;
 
721
                                                        $shift_val = $data->shift_max;
714
722
                                                        break;
715
723
                                                case CALC_FNC_AVG:
716
724
                                                default:
717
 
                                                        $val = $data->avg; 
718
 
                                                        $shift_val = $data->shift_avg; 
 
725
                                                        $val = $data->avg;
 
726
                                                        $shift_val = $data->shift_avg;
719
727
                                        }
720
728
 
721
729
                                        if(!isset($val)) continue;
725
733
                                                for($ci=0; $ci < $min_val_shift; $ci++){
726
734
                                                        if($shift_val[$ci] < 0){
727
735
                                                                $val[$ci] += $shift_val[$ci];
728
 
                                                        } 
 
736
                                                        }
729
737
                                                }
730
738
 
731
739
                                        }
743
751
/*
744
752
                        if(isset($minY)&&($minY>0)){
745
753
                                $minY = $minY - ($minY * 0.1) - 0.05;
746
 
                        } 
 
754
                        }
747
755
                        else if(isset($minY)&&($minY<0)){
748
756
                                $minY = $minY + ($minY * 0.1) - 0.05;
749
 
                        } 
 
757
                        }
750
758
                        else {
751
759
                                $minY=0;
752
760
                        }
753
 
                        
 
761
 
754
762
                        $minY = round($minY,1);
755
763
//*/
756
764
                        return $minY;
784
792
 
785
793
                                        switch($calc_fnc){
786
794
                                                case CALC_FNC_ALL:      /* use max */
787
 
                                                case CALC_FNC_MAX:      
788
 
                                                        $val = $data->max; 
789
 
                                                        $shift_val = $data->shift_max; 
 
795
                                                case CALC_FNC_MAX:
 
796
                                                        $val = $data->max;
 
797
                                                        $shift_val = $data->shift_max;
790
798
                                                        break;
791
 
                                                case CALC_FNC_MIN:      
792
 
                                                        $val = $data->min; 
793
 
                                                        $shift_val = $data->shift_min; 
 
799
                                                case CALC_FNC_MIN:
 
800
                                                        $val = $data->min;
 
801
                                                        $shift_val = $data->shift_min;
794
802
                                                        break;
795
803
                                                case CALC_FNC_AVG:
796
 
                                                default:                
797
 
                                                        $val = $data->avg; 
 
804
                                                default:
 
805
                                                        $val = $data->avg;
798
806
                                                        $shift_val = $data->shift_avg;
799
807
                                        }
800
 
                                        
 
808
 
801
809
                                        if(!isset($val)) continue;
802
810
 
803
811
                                        for($ci=0; $ci < min(count($val),count($shift_val)); $ci++) $val[$ci] += $shift_val[$ci];
810
818
                                        else{
811
819
                                                $maxY = max($maxY, max($val));
812
820
                                        }
813
 
                                        
 
821
 
814
822
                                }
815
823
                        }
816
824
/*
817
825
                        if(isset($maxY)&&($maxY>0)){
818
 
                        
 
826
 
819
827
//                              $exp = round(log10($maxY));
820
828
//                              $mant = $maxY/pow(10,$exp);
821
 
                                
 
829
 
822
830
//                              $mant=((round(($mant*11)/6)-1)*6)/10;
823
831
//                              $maxY = $mant*pow(10,$exp);
824
832
 
825
833
                                $maxY = round($maxY,1);// + round($maxY,1)*0.2 + 0.05;
826
 
                        } 
 
834
                        }
827
835
                        else if(isset($maxY)&&($maxY<0)){
828
836
                                $maxY = round($maxY,1);// - round($maxY,1)*0.2 + 0.05;
829
 
                        } 
 
837
                        }
830
838
                        else {
831
839
                                $maxY=0.3;
832
840
                        }
845
853
                if($this->m_minY[$right]>0){
846
854
                        $this->zero[$right] = $this->sizeY+$this->shiftY;
847
855
                        $this->oxy[$right] = min($this->m_minY[$right],$this->m_maxY[$right]);
848
 
                } 
 
856
                }
849
857
                else if($this->m_maxY[$right]<0) {
850
858
                        $this->zero[$right] = $this->shiftY;
851
859
                        $this->oxy[$right] = max($this->m_minY[$right],$this->m_maxY[$right]);
853
861
                else{
854
862
                        $this->zero[$right] = $this->sizeY+$this->shiftY - (int)abs($this->m_minY[$right]/$this->unit2px[$right]);
855
863
                        $this->oxy[$right] = 0;
856
 
                }                       
 
864
                }
857
865
 
858
866
                if($this->m_minY[$left]>0){
859
867
                        $this->zero[$left] = $this->sizeY+$this->shiftY;
868
876
                        $this->oxy[$left] = 0;
869
877
                }
870
878
        }
871
 
        
 
879
 
872
880
        function correctMinMax(){
873
881
                $this->gridLinesCount = round($this->sizeY/$this->gridPixels) + 1;
874
 
                
 
882
 
875
883
                $sides = array(GRAPH_YAXIS_SIDE_LEFT,GRAPH_YAXIS_SIDE_RIGHT);
876
884
                foreach($sides as $side){
877
885
//SDI($side);
878
886
                        if(!isset($this->axis_valuetype[$side])) continue;
879
 
                        
 
887
 
880
888
                        if($this->axis_valuetype[$side] == ITEM_VALUE_TYPE_UINT64){
881
 
                        
 
889
 
882
890
                                $this->m_maxY[$side] = round($this->m_maxY[$side]);
883
891
                                $this->m_minY[$side] = floor($this->m_minY[$side]);
884
 
                
 
892
 
885
893
                                $value_delta = round($this->m_maxY[$side] - $this->m_minY[$side]);
886
 
                                
 
894
 
887
895
                                $step = floor((($value_delta/$this->gridLinesCount) + 1));      // round to top
888
896
                                $value_delta2 = $step * $this->gridLinesCount;
889
897
//SDI($value_delta.' <> '.$value_delta2);
902
910
                                                $second_delta += $first_delta - $this->m_maxY[$side];
903
911
                                                $first_delta = $this->m_maxY[$side];
904
912
                                        }
905
 
                                }                               
906
 
                                
 
913
                                }
 
914
 
907
915
                                $this->m_maxY[$side] += $first_delta;
908
916
                                $this->m_minY[$side] -= ($value_delta2-$value_delta) - $first_delta;
909
917
                        }
910
918
                        else if($this->axis_valuetype[$side] == ITEM_VALUE_TYPE_FLOAT){
911
919
//*
912
920
                                if($this->m_maxY[$side]>0){
913
 
                        
 
921
 
914
922
                                        $this->m_maxY[$side] = round($this->m_maxY[$side],1) + round($this->m_maxY[$side],1)*0.2 + 0.05;
915
 
                                } 
 
923
                                }
916
924
                                else if($this->m_maxY[$side]<0){
917
925
                                        $this->m_maxY[$side] = round($this->m_maxY[$side],1) - round($this->m_maxY[$side],1)*0.2 + 0.05;
918
 
                                }                               
919
 
                                
 
926
                                }
 
927
 
920
928
                                if($this->m_minY[$side]>0){
921
929
                                        $this->m_minY[$side] = $this->m_minY[$side] - ($this->m_minY[$side] * 0.2) - 0.05;
922
 
                                } 
 
930
                                }
923
931
                                else if($this->m_minY[$side]<0){
924
932
                                        $this->m_minY[$side] = $this->m_minY[$side] + ($this->m_minY[$side] * 0.2) - 0.05;
925
 
                                } 
926
 
                                
 
933
                                }
 
934
 
927
935
                                $this->m_minY[$side] = round($this->m_minY[$side],1);
928
936
//*/
929
937
                        }
930
 
                        
 
938
 
931
939
                        if($this->yaxistype==GRAPH_YAXIS_TYPE_FIXED){
932
940
                                $this->m_minY[$side] = $this->yaxismin;
933
941
                                $this->m_maxY[$side] = $this->yaxismax;
956
964
 
957
965
                $p = $this->to_time - $this->from_time;         // graph size in time
958
966
                $z = $p - $this->from_time % $p;                        // graphsize - mod(from_time,p) for Oracle...
959
 
                $x = $this->sizeX;                                                      // graph size in px     
 
967
                $x = $this->sizeX;                                                      // graph size in px
960
968
 
961
969
                for($i=0; $i < $this->num; $i++){
962
970
 
963
971
                        $real_item = get_item_by_itemid($this->items[$i]['itemid']);
964
 
                        
 
972
 
965
973
                        if(!isset($this->axis_valuetype[$this->items[$i]['axisside']])){
966
974
                                $this->axis_valuetype[$this->items[$i]['axisside']] = $real_item['value_type'];
967
975
                        }
968
976
                        else if($this->axis_valuetype[$this->items[$i]['axisside']] != $real_item['value_type']){
969
977
                                $this->axis_valuetype[$this->items[$i]['axisside']] = ITEM_VALUE_TYPE_FLOAT;
970
978
                        }
971
 
                        
 
979
 
972
980
                        $type = $this->items[$i]['calc_type'];
973
981
                        if($type == GRAPH_ITEM_AGGREGATED) {
974
982
                                /* skip current period */
975
983
                                $from_time      = $this->from_time - $this->period * $this->items[$i]['periods_cnt'];
976
984
                                $to_time        = $this->from_time;
977
 
                        } 
 
985
                        }
978
986
                        else {
979
987
                                $from_time      = $this->from_time;
980
988
                                $to_time        = $this->to_time;
981
989
                        }
982
 
                        
 
990
 
983
991
                        $calc_field = 'round('.$x.'*(mod('.zbx_dbcast_2bigint('clock').'+'.$z.','.$p.'))/('.$p.'),0)';  /* required for 'group by' support of Oracle */
984
 
                        
 
992
 
985
993
                        $sql_arr = array();
986
 
        
 
994
 
987
995
                        if((($real_item['history']*86400) > (time()-($this->from_time+$this->period/2))) &&                             // should pick data from history or trends
988
996
                                (($this->period / $this->sizeX) <= (ZBX_MAX_TREND_DIFF / ZBX_GRAPH_MAX_SKIP_CELL)))             // is reasonable to take data from history?
989
997
                        {
1042
1050
 
1043
1051
                        foreach($sql_arr as $sql){
1044
1052
                                $result=DBselect($sql);
1045
 
                                
 
1053
 
1046
1054
                                while($row=DBfetch($result)){
1047
1055
                                        $idx=$row['i']-1;
1048
 
                                        if($idx<0) continue; 
 
1056
                                        if($idx<0) continue;
1049
1057
/* --------------------------------------------------
1050
 
        We are taking graph on 1px more than we need, 
1051
 
        and here we are skiping first px, because of MOD (in SELECT), 
 
1058
        We are taking graph on 1px more than we need,
 
1059
        and here we are skiping first px, because of MOD (in SELECT),
1052
1060
        it combines prelast point (it would be last point if not that 1px in begining)
1053
 
        and first point, but we still losing prelast point :( 
 
1061
        and first point, but we still losing prelast point :(
1054
1062
        but now we've got the first point.
1055
1063
--------------------------------------------------*/
1056
 
                                        
 
1064
 
1057
1065
                                        $curr_data->count[$idx] = $row['count'];
1058
1066
                                        $curr_data->min[$idx]   = $row['min'];
1059
1067
                                        $curr_data->max[$idx]   = $row['max'];
1062
1070
                                        $curr_data->shift_min[$idx] = 0;
1063
1071
                                        $curr_data->shift_max[$idx] = 0;
1064
1072
                                        $curr_data->shift_avg[$idx] = 0;
1065
 
                                        
 
1073
 
1066
1074
                                        if($this->type == GRAPH_TYPE_STACKED){
1067
1075
                                                $this->CheckGraphOrientation($curr_data->min[$idx]);
1068
1076
                                        }
1071
1079
                        }
1072
1080
                        /* calculate missed points */
1073
1081
                        $first_idx = 0;
1074
 
                        /* 
1075
 
                                first_idx - last existed point 
 
1082
                        /*
 
1083
                                first_idx - last existed point
1076
1084
                                ci - current index
1077
1085
                                cj - count of missed in onetime
1078
1086
                                dx - offset to first value (count to last existed point)
1093
1101
 
1094
1102
                                        if($first_idx < 0)      $first_idx = $ci; // if no data FROM start of graph get current data as first data
1095
1103
 
1096
 
                                        for(;$cj > 0; $cj--){                                   
 
1104
                                        for(;$cj > 0; $cj--){
1097
1105
                                                if(($dx < ($this->sizeX/20)) && ($this->type == GRAPH_TYPE_STACKED)){
1098
1106
                                                        $curr_data->count[$ci - ($dx - $cj)] = 1;
1099
1107
                                                }
1100
 
                                                
 
1108
 
1101
1109
                                                foreach(array('clock','min','max','avg') as $var_name){
1102
1110
                                                        $var = &$curr_data->$var_name;
1103
1111
 
1105
1113
                                                                $var[$ci - ($dx - $cj)] = $var[$first_idx] - (($p / $this->sizeX) * ($dx - $cj));
1106
1114
                                                                continue;
1107
1115
                                                        }
1108
 
                                                        
 
1116
 
1109
1117
                                                        $dy = $var[$ci] - $var[$first_idx];
1110
1118
                                                        $var[$ci - ($dx - $cj)] = $var[$first_idx] + ($cj * $dy) / $dx;
1111
1119
                                                }
1112
1120
                                        }
1113
1121
                                }
1114
1122
                        }
1115
 
                        
 
1123
 
1116
1124
                        if($cj > 0 && $ci > $cj){
1117
1125
                                $dx = $cj + 1;
1118
1126
 
1120
1128
 
1121
1129
                                for(;$cj > 0; $cj--){
1122
1130
 
1123
 
//                                      if($dx < ($this->sizeX/20))                     //($this->type == GRAPH_TYPE_STACKED) 
 
1131
//                                      if($dx < ($this->sizeX/20))                     //($this->type == GRAPH_TYPE_STACKED)
1124
1132
//                                              $curr_data->count[$first_idx + ($dx - $cj)] = 1;
1125
 
                                                
 
1133
 
1126
1134
                                        foreach(array('clock','min','max','avg') as $var_name){
1127
1135
                                                $var = &$curr_data->$var_name;
1128
1136
 
1138
1146
                }
1139
1147
 
1140
1148
                /* calculte shift for stacked graphs */
1141
 
                
 
1149
 
1142
1150
                if($this->type == GRAPH_TYPE_STACKED){
1143
1151
                        for($i=1; $i<$this->num; $i++){
1144
1152
                                $curr_data = &$this->data[$this->items[$i]['itemid']][$this->items[$i]['calc_type']];
1180
1188
                                        break;
1181
1189
                                }
1182
1190
                        }
1183
 
                        
 
1191
 
1184
1192
                        $hstr_count = $this->gridLinesCount;
1185
1193
                        for($i=0;$i<=$hstr_count;$i++){
1186
1194
                                $str = str_pad(convert_units($this->sizeY*$i/$hstr_count*($maxY-$minY)/$this->sizeY+$minY,$units),10,' ', STR_PAD_LEFT);
1187
 
                                imagestring($this->im, 
1188
 
                                                        1, 
1189
 
                                                        5, 
1190
 
                                                        $this->sizeY-$this->sizeY*$i/$hstr_count-4+$this->shiftY, 
1191
 
                                                        $str, 
 
1195
                                imagestring($this->im,
 
1196
                                                        1,
 
1197
                                                        5,
 
1198
                                                        $this->sizeY-$this->sizeY*$i/$hstr_count-4+$this->shiftY,
 
1199
                                                        $str,
1192
1200
                                                        $this->GetColor('Dark Red No Alpha')
1193
1201
                                                );
1194
1202
                        }
1195
 
                        
1196
 
                        if(($this->zero[GRAPH_YAXIS_SIDE_LEFT] != $this->sizeY+$this->shiftY) && 
 
1203
 
 
1204
                        if(($this->zero[GRAPH_YAXIS_SIDE_LEFT] != $this->sizeY+$this->shiftY) &&
1197
1205
                                ($this->zero[GRAPH_YAXIS_SIDE_LEFT] != $this->shiftY))
1198
1206
                        {
1199
1207
                                imageline($this->im,
1221
1229
                        $hstr_count = $this->gridLinesCount;
1222
1230
                        for($i=0;$i<=$hstr_count;$i++){
1223
1231
                                $str = str_pad(convert_units($this->sizeY*$i/$hstr_count*($maxY-$minY)/$this->sizeY+$minY,$units),10,' ');
1224
 
                                imagestring($this->im, 
1225
 
                                                        1, 
1226
 
                                                        $this->sizeX+$this->shiftXleft+2, 
1227
 
                                                        $this->sizeY-$this->sizeY*$i/$hstr_count-4+$this->shiftY, 
1228
 
                                                        $str, 
 
1232
                                imagestring($this->im,
 
1233
                                                        1,
 
1234
                                                        $this->sizeX+$this->shiftXleft+2,
 
1235
                                                        $this->sizeY-$this->sizeY*$i/$hstr_count-4+$this->shiftY,
 
1236
                                                        $str,
1229
1237
                                                        $this->GetColor('Dark Red No Alpha'));
1230
1238
                        }
1231
 
                        
1232
 
                        if(($this->zero[GRAPH_YAXIS_SIDE_RIGHT] != $this->sizeY+$this->shiftY) && 
 
1239
 
 
1240
                        if(($this->zero[GRAPH_YAXIS_SIDE_RIGHT] != $this->sizeY+$this->shiftY) &&
1233
1241
                                ($this->zero[GRAPH_YAXIS_SIDE_RIGHT] != $this->shiftY))
1234
1242
                        {
1235
1243
                                imageline($this->im,
1242
1250
                        }
1243
1251
                }
1244
1252
        }
1245
 
        
 
1253
 
1246
1254
        function drawPercentile(){
1247
1255
                if($this->type != GRAPH_TYPE_NORMAL){
1248
1256
                        return ;
1259
1267
                                        $minY = $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT];
1260
1268
                                        $maxY = $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT];
1261
1269
                                }
1262
 
        
 
1270
 
1263
1271
                                $y = $this->sizeY - (($percentile['value']-$minY) / ($maxY-$minY)) * $this->sizeY + $this->shiftY;
1264
1272
                                imageline(
1265
1273
                                        $this->im,
1268
1276
                                        $this->sizeX+$this->shiftXleft,
1269
1277
                                        $y,
1270
1278
                                        $this->GetColor($color));
1271
 
                                
 
1279
 
1272
1280
                                $color = '00AA00';
1273
1281
                        }
1274
 
                }               
 
1282
                }
1275
1283
        }
1276
1284
 
1277
1285
        function draw(){
1280
1288
                set_image_header();
1281
1289
 
1282
1290
                check_authorisation();
1283
 
                
 
1291
 
1284
1292
                $this->selectData();
1285
1293
 
1286
1294
                $this->m_minY[GRAPH_YAXIS_SIDE_LEFT]    = $this->calculateMinY(GRAPH_YAXIS_SIDE_LEFT);
1289
1297
                $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT]   = $this->calculateMaxY(GRAPH_YAXIS_SIDE_RIGHT);
1290
1298
 
1291
1299
                $this->correctMinMax();
1292
 
                
 
1300
 
1293
1301
                $this->updateShifts();
1294
1302
                $this->calcTriggers();
1295
1303
                $this->calcZero();
1296
1304
                $this->calcPercentile();
1297
 
                
 
1305
 
1298
1306
                $this->fullSizeX = $this->sizeX+$this->shiftXleft+$this->shiftXright+1;
1299
1307
                $this->fullSizeY = $this->sizeY+$this->shiftY+62;
1300
1308
                $this->fullSizeY += 12*($this->num+(($this->sizeY < 120)?0:count($this->triggers)))+8;
1304
1312
                                $this->fullSizeY += 12;
1305
1313
                        }
1306
1314
                }
1307
 
                
 
1315
 
1308
1316
                if(function_exists('imagecolorexactalpha') && function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1,1))
1309
1317
                        $this->im = imagecreatetruecolor($this->fullSizeX,$this->fullSizeY);
1310
1318
                else
1321
1329
 
1322
1330
                $this->drawWorkPeriod();
1323
1331
                $this->drawGrid();
1324
 
                
 
1332
 
1325
1333
                $maxX = $this->sizeX;
1326
 
                
 
1334
 
1327
1335
// For each metric
1328
1336
                for($item = 0; $item < $this->num; $item++){
1329
1337
                        $minY = $this->m_minY[$this->items[$item]['axisside']];
1330
1338
                        $maxY = $this->m_maxY[$this->items[$item]['axisside']];
1331
1339
 
1332
1340
                        $data = &$this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']];
1333
 
                        
 
1341
 
1334
1342
                        if(!isset($data))       continue;
1335
1343
 
1336
1344
                        if($this->items[$item]['calc_type'] == GRAPH_ITEM_AGGREGATED){
1351
1359
                                $min_color      = $this->GetColor('ValueMin',GRAPH_STACKED_ALFA);
1352
1360
                                $minmax_color   = $this->GetColor('ValueMinMax',GRAPH_STACKED_ALFA);
1353
1361
 
1354
 
                                $calc_fnc = $this->items[$item]['calc_fnc'];                                    
 
1362
                                $calc_fnc = $this->items[$item]['calc_fnc'];
1355
1363
                        }
1356
1364
                        else{
1357
1365
                                $drawtype       = $this->items[$item]['drawtype'];
1358
1366
 
1359
 
                                $max_color      = $this->GetColor('ValueMax');
1360
 
                                $avg_color      = $this->GetColor($this->items[$item]['color']);
1361
 
                                $min_color      = $this->GetColor('ValueMin');
1362
 
                                $minmax_color   = $this->GetColor('ValueMinMax');
 
1367
                                $max_color      = $this->GetColor('ValueMax', GRAPH_STACKED_ALFA);
 
1368
                                $avg_color      = $this->GetColor($this->items[$item]['color'], GRAPH_STACKED_ALFA);
 
1369
                                $min_color      = $this->GetColor('ValueMin', GRAPH_STACKED_ALFA);
 
1370
                                $minmax_color   = $this->GetColor('ValueMinMax', GRAPH_STACKED_ALFA);
1363
1371
 
1364
1372
                                $calc_fnc = $this->items[$item]['calc_fnc'];
1365
1373
                        }
1366
1374
// For each X
1367
1375
                        for($i = 1, $j = 0; $i < $maxX; $i++){  // new point
1368
 
                        
 
1376
 
1369
1377
                                if(($data->count[$i] == 0) && ($i != ($maxX-1))) continue;
1370
1378
 
1371
1379
                                $diff   = abs($data->clock[$i] - $data->clock[$j]);
1372
1380
                                $cell   = ($this->to_time - $this->from_time)/$this->sizeX;
1373
1381
                                $delay  = $this->items[$item]['delay'];
1374
 
                                                                        
 
1382
 
1375
1383
                                if($cell > $delay)
1376
1384
                                        $draw = (boolean) ($diff < ZBX_GRAPH_MAX_SKIP_CELL * $cell);
1377
 
                                else            
 
1385
                                else
1378
1386
                                        $draw = (boolean) ($diff < ZBX_GRAPH_MAX_SKIP_DELAY * $delay);
1379
1387
 
1380
1388
                                if(($draw == false) && ($this->items[$item]['calc_type'] == GRAPH_ITEM_AGGREGATED))
1388
1396
                                        $this->drawElement(
1389
1397
                                                $data,
1390
1398
                                                $i, $j,
1391
 
                                                0, $this->sizeX, 
 
1399
                                                0, $this->sizeX,
1392
1400
                                                $minY, $maxY,
1393
1401
                                                $drawtype,
1394
1402
                                                $max_color,
1404
1412
                                $j = $i;
1405
1413
                        }
1406
1414
                }
1407
 
                
 
1415
 
1408
1416
                $this->drawLeftSide();
1409
1417
                $this->drawRightSide();
1410
1418
                $this->drawTriggers();
1413
1421
                $this->drawLogo();
1414
1422
 
1415
1423
                $this->drawLegend();
1416
 
                
 
1424
 
1417
1425
                $end_time=getmicrotime();
1418
1426
                $str=sprintf('%0.2f',(getmicrotime()-$start_time));
1419
1427
                imagestring($this->im, 0,$this->fullSizeX-120,$this->fullSizeY-12,"Generated in $str sec", $this->GetColor('Gray'));
1420
1428
 
1421
1429
                unset($this->items, $this->data);
1422
1430
 
1423
 
                ImageOut($this->im); 
 
1431
                ImageOut($this->im);
1424
1432
        }
1425
1433
}
1426
1434
?>