forked from proche-rainmaker/phplicensewatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.php
113 lines (96 loc) · 2.96 KB
/
graph.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
define("RRDTOOL", "/usr/bin/rrdtool");
$rrd_dir="/var/www/html/phplicensewatcher/rrd";
$metricname = "msimlevsimvlog";
$vlabel = "Licenses";
$subtitle = "Modelsim";
$size = "small";
$style = "";
$subtitle = $metricname;
if (is_numeric($max))
$upper_limit = "--upper-limit '$max' ";
if (is_numeric($min))
$lower_limit ="--lower-limit '$min' ";
if ($vlabel)
$vertical_label = "--vertical-label '$vlabel'";
else if ($upper_limit or $lower_limit)
{
$max = $max>1000 ? number_format($max) : number_format($max, 2);
$min = $min>0 ? number_format($min,2) : $min;
$vertical_label ="--vertical-label '$min - $max' ";
}
$rrd_file = "$rrd_dir/$metricname.rrd";
$default_metric_color = "5555cc";
$series = "DEF:'sum'='$rrd_file':'sum':AVERAGE "
."AREA:'sum'#$default_metric_color:'$subtitle' ";
if ($jobstart)
$series .= "VRULE:$jobstart#$jobstart_color ";
# Set the graph title.
if($context == "meta")
{
$title = "$self $meta_designator $style last $range";
}
else if ($context == "grid")
{
$title = "$grid $meta_designator $style last $range";
}
else if ($context == "cluster")
{
$title = "$clustername $style last $range";
}
else
{
if ($size == "small")
{
# Value for this graph define a background color.
if (!$load_color) $load_color = "ffffff";
$background = "--color BACK#'$load_color'";
$title = $hostname;
}
else if ($style)
$title = "$hostname $style last $range";
else
$title = $metricname;
}
# Calculate time range.
if ($sourcetime)
{
$end = $sourcetime;
# Get_context makes start negative.
$start = $sourcetime + $start;
}
# Fix from Phil Radden, but step is not always 15 anymore.
if ($range=="month")
$end = floor($end / 672) * 672;
#
# Generate the rrdtool graph command.
#
$end = time();
$start = $end - 3600;
$width = 400;
$height = 200;
$fudge += $height;
#$command = RRDTOOL . " graph - --start $start --end $end ".
# "--width $width --height $fudge $upper_limit $lower_limit ".
# "--title '$title' $vertical_label $extras $background ".
# $series;
$command = RRDTOOL . " graph - --start='end-3 day' --end=now --imgformat=PNG --width=500 --base=1000 --height=120 --interlaced DEF:a=/var/www/html/phplicensewatcher/rrd//msimlevsimvlog.rrd:msimlevsimvlog:MAX AREA:a#800000:ModelSim";
$debug=0;
# Did we generate a command? Run it.
if($command)
{
/*Make sure the image is not cached*/
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
if ($debug) {
header ("Content-type: text/html");
print "$command\n\n\n\n\n";
}
else {
header ("Content-type: image/png");
passthru($command);
}
}
?>