summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-07-21 14:08:45 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-07-21 14:08:45 +0000
commit97b8344b5ced74f883a6250d0adb57946cc9e6f4 (patch)
tree55a5e322949ff4d17013aac5d1bd90460eb9ba31
parentee5e45f099eab3ea937ac0234d005b9514b155e8 (diff)
downloadzabbix-97b8344b5ced74f883a6250d0adb57946cc9e6f4.tar.gz
zabbix-97b8344b5ced74f883a6250d0adb57946cc9e6f4.tar.xz
zabbix-97b8344b5ced74f883a6250d0adb57946cc9e6f4.zip
- developed stacked graphs (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3071 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r--frontends/php/graph.php6
-rw-r--r--frontends/php/include/classes/clink.inc.php2
-rw-r--r--frontends/php/include/classes/graph.inc.php250
-rw-r--r--frontends/php/include/config.inc.php2
-rw-r--r--frontends/php/include/defines.inc.php2
5 files changed, 195 insertions, 67 deletions
diff --git a/frontends/php/graph.php b/frontends/php/graph.php
index bd72b6ec..c7438e02 100644
--- a/frontends/php/graph.php
+++ b/frontends/php/graph.php
@@ -199,9 +199,9 @@
$table->AddRow(array(
$row["sortorder"],
$row["host"],
- NEW CLink(item_description($row["description"],$row["key_"],
- "chart.php?itemid=".$row["itemid"]."&period=3600&from=0"),
- "action"),
+ NEW CLink(item_description($row["description"],$row["key_"]),
+ 'chart.php?itemid='.$row["itemid"].'&period=3600&from=0',
+ 'action'),
$fnc_name,
$type,
$drawtype,
diff --git a/frontends/php/include/classes/clink.inc.php b/frontends/php/include/classes/clink.inc.php
index 0493076c..78c358eb 100644
--- a/frontends/php/include/classes/clink.inc.php
+++ b/frontends/php/include/classes/clink.inc.php
@@ -44,7 +44,7 @@
}
function SetUrl($value)
{
- parent::AddOption('href', $value);
+ $this->AddOption('href', $value);
}
function SetTarget($value=NULL)
{
diff --git a/frontends/php/include/classes/graph.inc.php b/frontends/php/include/classes/graph.inc.php
index 9c2ea375..2781e4f7 100644
--- a/frontends/php/include/classes/graph.inc.php
+++ b/frontends/php/include/classes/graph.inc.php
@@ -37,6 +37,8 @@
var $m_showWorkPeriod;
var $m_showTriggers;
+ var $type; /* 0 - simple graph; 1 - stacked graph; */
+
var $yaxistype;
var $yaxismin;
var $yaxismax;
@@ -121,6 +123,8 @@
"Priority Average" => array(221,120,120),
"Priority" => array(100,100,100),
"Not Work Period" => array(230,230,230),
+
+ "UncnownData" => array(130,130,130, 50)
);
// I should rename No Alpha to Alpha at some point to get rid of some confusion
@@ -141,7 +145,7 @@
}
}
- function Graph()
+ function Graph($type = GRAPH_TYPE_STACKED /* TMP!!! */ /* mist be GRAPH_TYPE_NORMAL */)
{
$this->period=3600;
$this->from=0;
@@ -152,6 +156,7 @@
$this->shiftY=17;
$this->border=1;
$this->num=0;
+ $this->type = $type;
$this->yaxistype=GRAPH_YAXIS_TYPE_CALCULATED;
$this->yaxisright=0;
$this->yaxisleft=0;
@@ -607,24 +612,53 @@
$calc_fnc
)
{
- $x1 = ($this->sizeX * ($from - $minX)/($maxX-$minX)) + $this->shiftXleft;
- $x2 = ($this->sizeX * ($to - $minX)/($maxX-$minX)) + $this->shiftXleft+1;
+ $shift_min_from = $shift_min_to = 0;
+ $shift_max_from = $shift_max_to = 0;
+ $shift_avg_from = $shift_avg_to = 0;
+
+ if(isset($data->shift_min[$from])) $shift_min_from = $data->shift_min[$from];
+ if(isset($data->shift_min[$to])) $shift_min_to = $data->shift_min[$to];
+
+ if(isset($data->shift_max[$from])) $shift_max_from = $data->shift_max[$from];
+ if(isset($data->shift_max[$to])) $shift_max_to = $data->shift_max[$to];
- $y1min = $this->sizeY - ($this->sizeY*($data->min[$from]-$minY)/($maxY-$minY)) + $this->shiftY;
- $y2min = $this->sizeY - ($this->sizeY*($data->min[$to]-$minY)/($maxY-$minY)) + $this->shiftY;
+ if(isset($data->shift_avg[$from])) $shift_avg_from = $data->shift_avg[$from];
+ if(isset($data->shift_avg[$to])) $shift_avg_to = $data->shift_avg[$to];
+/**/
+ $min_from = $data->min[$from] + $shift_min_from;
+ $min_to = $data->min[$to] + $shift_min_to;
+ $max_from = $data->max[$from] + $shift_max_from;
+ $max_to = $data->max[$to] + $shift_max_to;
+ $avg_from = $data->avg[$from] + $shift_avg_from;
+ $avg_to = $data->avg[$to] + $shift_avg_to;
- $y1max = $this->sizeY - ($this->sizeY*($data->max[$from]-$minY)/($maxY-$minY)) + $this->shiftY;
- $y2max = $this->sizeY - ($this->sizeY*($data->max[$to]-$minY)/($maxY-$minY)) + $this->shiftY;
+// $x1 = ($this->sizeX * ($from - $minX)/($maxX-$minX)) + $this->shiftXleft;
+// $x2 = ($this->sizeX * ($to - $minX)/($maxX-$minX)) + $this->shiftXleft + 1;
+ $x1 = $from + $this->shiftXleft - 1;
+ $x2 = $to + $this->shiftXleft;
+
+ $y1min = $this->sizeY - ($this->sizeY*($min_from-$minY)/($maxY-$minY)) + $this->shiftY;
+ $y2min = $this->sizeY - ($this->sizeY*($min_to-$minY)/($maxY-$minY)) + $this->shiftY;
+
+ $y1max = $this->sizeY - ($this->sizeY*($max_from-$minY)/($maxY-$minY)) + $this->shiftY;
+ $y2max = $this->sizeY - ($this->sizeY*($max_to-$minY)/($maxY-$minY)) + $this->shiftY;
+
+ $y1avg = $this->sizeY - ($this->sizeY*($avg_from-$minY)/($maxY-$minY)) + $this->shiftY;
+ $y2avg = $this->sizeY - ($this->sizeY*($avg_to-$minY)/($maxY-$minY)) + $this->shiftY;
switch($calc_fnc)
{
case CALC_FNC_MAX:
$y1 = $y1max;
$y2 = $y2max;
+ $shift_from = $shift_max_from;
+ $shift_to = $shift_max_to;
break;
case CALC_FNC_MIN:
$y1 = $y1min;
$y2 = $y2min;
+ $shift_from = $shift_min_from;
+ $shift_to = $shift_min_to;
break;
case CALC_FNC_ALL:
$a[0] = $x1; $a[1] = $y1max;
@@ -642,11 +676,16 @@
/* don't use break, avg must be drawed in this statement */
// break;
default:
- $y1 = $this->sizeY - ($this->sizeY*($data->avg[$from]-$minY)/($maxY-$minY)) + $this->shiftY;
- $y2 = $this->sizeY - ($this->sizeY*($data->avg[$to]-$minY)/($maxY-$minY)) + $this->shiftY;
+ $y1 = $y1avg;
+ $y2 = $y2avg;
+ $shift_from = $shift_avg_from;
+ $shift_to = $shift_avg_to;
}
+ $y1_shift = $this->sizeY - ($this->sizeY*$shift_from/($maxY-$minY)) + $this->shiftY;
+ $y2_shift = $this->sizeY - ($this->sizeY*$shift_to/($maxY-$minY)) + $this->shiftY;
+
/* draw main line */
switch($drawtype)
{
@@ -658,8 +697,8 @@
break;
case GRAPH_DRAW_TYPE_FILL:
$a[0] = $x1; $a[1] = $y1;
- $a[2] = $x1; $a[3] = $this->shiftY+$this->sizeY;
- $a[4] = $x2; $a[5] = $this->shiftY+$this->sizeY;
+ $a[2] = $x1; $a[3] = $y1_shift;
+ $a[4] = $x2; $a[5] = $y2_shift;
$a[6] = $x2; $a[7] = $y2;
ImageFilledPolygon($this->im,$a,4,$avg_color);
@@ -702,12 +741,18 @@
switch($calc_fnc)
{
case CALC_FNC_ALL: /* use min */
- case CALC_FNC_MIN: $val = &$data->min; break;
- case CALC_FNC_MAX: $val = &$data->max; break;
+ case CALC_FNC_MIN: $val = $data->min; $shift_val = $data->shift_min; break;
+ case CALC_FNC_MAX: $val = $data->max; $shift_val = $data->shift_max; break;
case CALC_FNC_AVG:
- default: $val = &$data->avg;
+ default: $val = $data->avg; $shift_val = $data->shift_avg;
}
+ if(!isset($val)) continue;
+
+ if($this->type == GRAPH_TYPE_STACKED)
+ for($ci=0; $ci < min(count($val), count($shift_val)); $ci++)
+ $val[$ci] -= $shift_val[$ci];
+
if(!isset($minY))
{
if(isset($val) && count($val) > 0)
@@ -724,7 +769,7 @@
if(isset($minY)&&($minY>0))
{
- $exp = floor(log10($minY));
+ $exp = round(log10($minY));
$mant = $minY/pow(10,$exp);
}
else
@@ -733,8 +778,8 @@
$mant=0;
}
- $mant=(floor($mant*1.1*10/6)-1)*6/10;
-// $mant=(floor($mant*1.1*10/6)+1)*6/10;
+ $mant=((round(($mant*11)/6)-1)*6)/10;
+// $mant=(floor($mant*1.1*10/6)+1)*6/10; /* MAX */
$minY = $mant*pow(10,$exp);
@@ -777,11 +822,15 @@
switch($calc_fnc)
{
case CALC_FNC_ALL: /* use max */
- case CALC_FNC_MAX: $val = &$data->max; break;
- case CALC_FNC_MIN: $val = &$data->min; break;
+ case CALC_FNC_MAX: $val = $data->max; $shift_val = $data->shift_max; break;
+ case CALC_FNC_MIN: $val = $data->min; $shift_val = $data->shift_min; break;
case CALC_FNC_AVG:
- default: $val = &$data->avg;
+ default: $val = $data->avg; $shift_val = $data->shift_avg;
}
+
+ if(!isset($val)) continue;
+
+ for($ci=0; $ci < min(count($val),count($shift_val)); $ci++) $val[$ci] += $shift_val[$ci];
if(!isset($maxY))
{
@@ -864,20 +913,110 @@
"select itemid,round(900*(mod(clock+$z,$p))/($p),0) as i,sum(num) as count,avg(value_avg) as avg,min(value_min) as min,max(value_max) as max,max(clock) as clock from trends where itemid=".$this->items[$i]["itemid"]." and clock>=".$from_time." and clock<=".$to_time." group by itemid,round(900*(mod(clock+$z,$p))/($p),0)");
}
+ $curr_data = &$this->data[$this->items[$i]["itemid"]][$type];
+ $curr_data->count = NULL;
+ $curr_data->min = NULL;
+ $curr_data->max = NULL;
+ $curr_data->avg = NULL;
+ $curr_data->clock = NULL;
+
foreach($sql_arr as $sql)
{
$result=DBselect($sql);
while($row=DBfetch($result))
{
$idx=$row["i"];
- $this->data[$row["itemid"]][$type]->count[$idx] = $row["count"];
- $this->data[$row["itemid"]][$type]->min[$idx] = $row["min"];
- $this->data[$row["itemid"]][$type]->max[$idx] = $row["max"];
- $this->data[$row["itemid"]][$type]->avg[$idx] = $row["avg"];
- $this->data[$row["itemid"]][$type]->clock[$idx] = $row["clock"];
+ $curr_data->count[$idx] = $row["count"];
+ $curr_data->min[$idx] = $row["min"];
+ $curr_data->max[$idx] = $row["max"];
+ $curr_data->avg[$idx] = $row["avg"];
+ $curr_data->clock[$idx] = $row["clock"];
+ }
+ }
+
+ /* calculate missed points */
+ $first_idx = 0;
+ for($ci = 0, $cj=0; $ci < 900; $ci++)
+ {
+ if(!isset($curr_data->count[$ci]) || $curr_data->count[$ci] == 0)
+ {
+ $curr_data->count[$ci] = 0;
+ $cj++;
+ }
+ else if($cj > 0)
+ {
+ $dx = $cj + 1;
+
+ $first_idx = $ci - $dx;
+
+ if($first_idx < 0) $first_idx = $ci;
+
+ for(;$cj > 0; $cj--)
+ {
+ foreach(array('clock','min','max','avg') as $var_name)
+ {
+ $var = &$curr_data->$var_name;
+ if($first_idx == $ci && $var_name == 'clock')
+ {
+ $var[$ci - $cj] = 0;
+ continue;
+ }
+ $dy = $var[$first_idx] - $var[$ci];
+ $var[$ci - $cj] = $var[$first_idx] + ($cj * $dy) / $dx;
+ }
+ }
+ }
+ }
+ if($cj > 0 && $cj != $ci)
+ {
+ $ci--;
+ $dx = ++$cj;
+
+ $first_idx = $ci - $dx;
+
+ if($first_idx < 0) $first_idx = $ci;
+ $ci = $first_idx;
+
+ for(;$cj > 0; $cj--)
+ {
+ foreach(array('clock','min','max','avg') as $var_name)
+ {
+ $var = &$curr_data->$var_name;
+ $dy = $var[$first_idx] - $var[$ci];
+ $var[$first_idx + $cj] = $var[$first_idx] + ($cj * $dy) / $dx;
+ }
+ }
+ }
+ /* end of missed points calculation */
+ $curr_data->shift_min = NULL;
+ $curr_data->shift_max = NULL;
+ $curr_data->shift_avg = NULL;
+ }
+
+ /* calculte shift for stacked graphs */
+ if($this->type == GRAPH_TYPE_STACKED /* stacked graph */)
+ {
+ for($i=$this->num-2; $i >= 0; $i--)
+ {
+ $curr_data = &$this->data[$this->items[$i]["itemid"]][$this->items[$i]["type"]];
+ $prev_data = &$this->data[$this->items[$i+1]["itemid"]][$this->items[$i+1]["type"]];
+
+ for($ci = 0; $ci < 900; $ci++)
+ {
+ foreach(array('min','max','avg') as $var_name)
+ {
+ $shift_var_name = 'shift_'.$var_name;
+ $curr_shift = &$curr_data->$shift_var_name;
+ $curr_var = &$curr_data->$var_name;
+ $prev_shift = &$prev_data->$shift_var_name;
+ $prev_var = &$prev_data->$var_name;
+ $curr_shift[$ci] = $prev_var[$ci] + $prev_shift[$ci];
+ }
}
}
}
+ /* end calculation of stacked graphs */
+
}
function DrawLeftSide()
@@ -1005,47 +1144,34 @@
}
// For each X
- for($i = $minX; $i <= $maxX; $i++)
+ for($i = $minX+1, $j = $minX; $i < $maxX; $i++) // new point
{
- if(isset($data->count[$i])&&($data->count[$i]>0))
- {
- for($j=$i-1;$j>=0;$j--)
- {
- if(isset($data->count[$j])&&($data->count[$j]>0))
- {
- // Do not draw anything if difference between two points
- // is more than 4*(item refresh period)
+ if(!isset($data->count[$i]) || (isset($data->count[$i]) && $data->count[$i] == 0)) continue;
- $diff = $data->clock[$i] - $data->clock[$j];
- $cell = ($this->to_time - $this->from_time)/900;
- $delay = $this->items[$item]["delay"];
+ $diff = $data->clock[$i] - $data->clock[$j];
+ $cell = ($this->to_time - $this->from_time)/900;
+ $delay = $this->items[$item]["delay"];
- if($cell > $delay)
- {
- if($diff >= 16*$cell) break;
- }
- else
- {
- if($diff >= 4*$delay) break;
- }
-
- $this->drawElement(
- $data,
- $i, $j,
- $minX, $maxX,
- $minY, $maxY,
- $drawtype,
- $max_color,
- $avg_color,
- $min_color,
- $minmax_color,
- $calc_fnc
- );
-
- break;
- }
- }
+ if($cell > $delay) $max_diff = 16*$cell;
+ else $max_diff = 4*$delay;
+
+ if($diff < $max_diff)
+ {
+
+ $this->drawElement(
+ $data,
+ $i, $j,
+ $minX, $maxX,
+ $minY, $maxY,
+ $drawtype,
+ $max_color,
+ $avg_color,
+ $min_color,
+ $minmax_color,
+ $calc_fnc
+ );
}
+ $j = $i;
}
}
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index 6709a496..cad609de 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -2670,7 +2670,7 @@ COpt::profiling_stop("script");
function set_image_header()
{
- // Header( "Content-type: text/html");
+ //Header( "Content-type: text/html");
if(MAP_OUTPUT_FORMAT == "JPG") Header( "Content-type: image/jpeg");
else Header( "Content-type: image/png");
diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php
index b3b0ac2c..c5be2050 100644
--- a/frontends/php/include/defines.inc.php
+++ b/frontends/php/include/defines.inc.php
@@ -228,6 +228,8 @@
define("GRAPH_ITEM_SIMPLE" , 0);
define("GRAPH_ITEM_AGGREGATED", 1);
+ define("GRAPH_TYPE_NORMAL", 0);
+ define("GRAPH_TYPE_STACKED", 1);
/* Support for PHP5. PHP5 does not have $HTTP_..._VARS */
if (!function_exists('version_compare'))
{