1 | #!/usr/bin/php |
---|
2 | <?php |
---|
3 | function generation_graph_jour($nom_du_site, $prefixeTab) { |
---|
4 | |
---|
5 | global $cfgTmp, $cfgFileSep, $cfgRrdPath; |
---|
6 | |
---|
7 | $png_path = "/var/www/saga/www/images/tmp/"; |
---|
8 | $nfs_path = $cfgRrdPath.$cfgFileSep; |
---|
9 | |
---|
10 | |
---|
11 | |
---|
12 | |
---|
13 | |
---|
14 | |
---|
15 | $nbpref = count($prefixeTab); |
---|
16 | $found = 0; |
---|
17 | $nofoundnb = 0; |
---|
18 | $foundone = 0; |
---|
19 | $DEF_string = ""; |
---|
20 | $CDEF_string = ""; |
---|
21 | $CDEF_str_ALL = ""; |
---|
22 | $all = ""; |
---|
23 | $AREA_string = ""; |
---|
24 | $CDEF_str_ALLIN = ""; |
---|
25 | $CDEF_str_ALLOUT = ""; |
---|
26 | $all = ""; |
---|
27 | $allout = ""; |
---|
28 | |
---|
29 | foreach($prefixeTab as $key => $value) { |
---|
30 | |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | $tmp = str_replace(".", "_", $value[0]); |
---|
35 | $prefix_name = $tmp . "_" . $value[1]; |
---|
36 | if (is_dir($nfs_path)) { |
---|
37 | if ($dh = opendir($nfs_path)) { |
---|
38 | while (($file = readdir($dh)) !== false) { |
---|
39 | if (strpos($file, $prefix_name) !== false) { |
---|
40 | $found = 1; |
---|
41 | break; |
---|
42 | } |
---|
43 | } |
---|
44 | if ($found != 1){ |
---|
45 | $found = 0; |
---|
46 | $nofoundnb+=1; |
---|
47 | } |
---|
48 | closedir($dh); |
---|
49 | } |
---|
50 | } |
---|
51 | $rrdname = $nfs_path.$file; |
---|
52 | $file_split = split("_", $file); |
---|
53 | $tmp2 = split("\.",$file_split[5]); |
---|
54 | $sampling = $tmp2[0]; |
---|
55 | |
---|
56 | if ($found==1){ |
---|
57 | $foundone=1; |
---|
58 | $input = "inBytesG".$key; |
---|
59 | $output = "outBytesG".$key; |
---|
60 | $rrdfiles = "DEF:$input=".$rrdname.":inBytes:AVERAGE"." "."DEF:$output=".$rrdname.":outBytes:AVERAGE"; |
---|
61 | if ( $DEF_string == "") { |
---|
62 | $DEF_string = "$rrdfiles".""; |
---|
63 | } else { |
---|
64 | $DEF_string = "$rrdfiles"." ".$DEF_string; |
---|
65 | } |
---|
66 | |
---|
67 | $input10 = "input10".$key; |
---|
68 | $output10 = "output10".$key; |
---|
69 | $strtmp = "CDEF:$input10=$input,8,*,5,/,60,/,$sampling,*"." "."CDEF:$output10=$output,8,*,5,/,60,/,$sampling,*"; |
---|
70 | if ( $CDEF_string == "") { |
---|
71 | $CDEF_string = "$strtmp".""; |
---|
72 | } else { |
---|
73 | $CDEF_string = "$strtmp"." ".$CDEF_string; |
---|
74 | } |
---|
75 | $tmpin = "$input,UN,1,$input,IF,8,*,5,/,60,/,$sampling,*"; |
---|
76 | if ( $all == "") { |
---|
77 | $all = "$tmpin".""; |
---|
78 | } else { |
---|
79 | $all = "$tmpin".",".$all; |
---|
80 | } |
---|
81 | $tmpout = "$output,UN,1,$output,IF,8,*,5,/,60,/,$sampling,*"; |
---|
82 | if ( $allout == "") { |
---|
83 | $allout = "$tmpout".""; |
---|
84 | } else { |
---|
85 | $allout = "$tmpout".",".$allout; |
---|
86 | } |
---|
87 | } |
---|
88 | $found = 0; |
---|
89 | } |
---|
90 | for ($i=0; $i < $nbpref-$nofoundnb-1; $i++){ |
---|
91 | $all = $all.",+"; |
---|
92 | $allout = $allout.",+"; |
---|
93 | } |
---|
94 | $CDEF_str_ALLIN = "CDEF:TotalIN=".$all; |
---|
95 | $CDEF_str_ALLOUT = "CDEF:TotalOUT=".$allout; |
---|
96 | |
---|
97 | if ($foundone==1){ |
---|
98 | $filename = $nom_du_site."_j".".png"; |
---|
99 | $pngname = $png_path.$filename; |
---|
100 | |
---|
101 | |
---|
102 | $res = `rrdtool graph $pngname -s -1D --title "$nom_du_site" --vertical-label "bits/s" -A $DEF_string $CDEF_string $CDEF_str_ALLIN $CDEF_str_ALLOUT AREA:TotalIN\#00FF00:TotalIN LINE:TotalOUT\#0000FF:TotalOUT GPRINT:TotalIN:MAX:"MAX In %1.1lf%S b/s" GPRINT:TotalOUT:MAX:"MAX Out %1.1lf%S b/s"`; |
---|
103 | |
---|
104 | |
---|
105 | return $filename; |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | function generation_graph_mois($nom_du_site, $prefixeTab) { |
---|
110 | |
---|
111 | global $cfgTmp, $cfgFileSep; |
---|
112 | |
---|
113 | $png_path = "/var/www/saga/www/images/tmp/"; |
---|
114 | $tmp_path .= $cfgTmp.$cfgFileSep; |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | $nbpref = count($prefixeTab); |
---|
123 | $found = 0; |
---|
124 | $nofoundnb = 0; |
---|
125 | $foundone = 0; |
---|
126 | $DEF_string = ""; |
---|
127 | $CDEF_string = ""; |
---|
128 | $CDEF_str_ALL = ""; |
---|
129 | $all = ""; |
---|
130 | $AREA_string = ""; |
---|
131 | $CDEF_str_ALLIN = ""; |
---|
132 | $CDEF_str_ALLOUT = ""; |
---|
133 | $all = ""; |
---|
134 | $allout = ""; |
---|
135 | |
---|
136 | |
---|
137 | $filename = $nom_du_site."_m".".png"; |
---|
138 | $pngname = $png_path.$filename; |
---|
139 | |
---|
140 | $tab_in = array(); |
---|
141 | $tab_out = array(); |
---|
142 | foreach($prefixeTab as $key => $value) { |
---|
143 | $found = 0; |
---|
144 | |
---|
145 | |
---|
146 | |
---|
147 | $tmp = str_replace(".", "_", $value[0]); |
---|
148 | $prefix_name = $tmp . "_" . $value[1]; |
---|
149 | if (is_dir($nfs_path)) { |
---|
150 | if ($dh = opendir($nfs_path)) { |
---|
151 | while (($file = readdir($dh)) !== false) { |
---|
152 | if (strpos($file, $prefix_name) !== false) { |
---|
153 | $found = 1; |
---|
154 | break; |
---|
155 | } |
---|
156 | } |
---|
157 | if ($found != 1){ |
---|
158 | $found = 0; |
---|
159 | $nofoundnb+=1; |
---|
160 | } |
---|
161 | closedir($dh); |
---|
162 | } |
---|
163 | } |
---|
164 | if ($found==1){ |
---|
165 | $rrdname = $nfs_path.$file; |
---|
166 | $file_split = split("_", $file); |
---|
167 | $tmp2 = split("\.",$file_split[5]); |
---|
168 | $sampling = $tmp2[0]; |
---|
169 | |
---|
170 | $tmp_file = $tmp_path.$nom_du_site.".tmp"; |
---|
171 | `rrdtool fetch $rrdname AVERAGE --start -31Days | cut -d " " -f 4,5 > $tmp_file`; |
---|
172 | $fd = fopen ($tmp_file, "r"); |
---|
173 | $i=0; |
---|
174 | while (!feof ($fd)) { |
---|
175 | $buffer = fgets($fd, 4096); |
---|
176 | $buffer_split = split(" ",$buffer); |
---|
177 | if (trim($buffer_split[0]) != "nan"){ |
---|
178 | $tab_in[$i] += trim($buffer_split[0]); |
---|
179 | } |
---|
180 | if (trim($buffer_split[1]) != "nan"){ |
---|
181 | $tab_out[$i] += trim($buffer_split[1]); |
---|
182 | } |
---|
183 | $i++; |
---|
184 | } |
---|
185 | fclose ($fd); |
---|
186 | `rm $tmp_file`; |
---|
187 | $foundone=1; |
---|
188 | $input = "inBytesG".$key; |
---|
189 | $output = "outBytesG".$key; |
---|
190 | $rrdfiles = "DEF:$input=".$rrdname.":inBytes:AVERAGE"." "."DEF:$output=".$rrdname.":outBytes:AVERAGE"; |
---|
191 | if ( $DEF_string == "") { |
---|
192 | $DEF_string = "$rrdfiles".""; |
---|
193 | } else { |
---|
194 | $DEF_string = "$rrdfiles"." ".$DEF_string; |
---|
195 | } |
---|
196 | |
---|
197 | $input10 = "input10".$key; |
---|
198 | $output10 = "output10".$key; |
---|
199 | $strtmp = "CDEF:$input10=$input,8,*,5,/,60,/,$sampling,*"." "."CDEF:$output10=$output,8,*,5,/,60,/,$sampling,*"; |
---|
200 | if ( $CDEF_string == "") { |
---|
201 | $CDEF_string = "$strtmp".""; |
---|
202 | } else { |
---|
203 | $CDEF_string = "$strtmp"." ".$CDEF_string; |
---|
204 | } |
---|
205 | $tmpin = "$input,UN,1,$input,IF,8,*,5,/,60,/,$sampling,*"; |
---|
206 | if ( $all == "") { |
---|
207 | $all = "$tmpin".""; |
---|
208 | } else { |
---|
209 | $all = "$tmpin".",".$all; |
---|
210 | } |
---|
211 | $tmpout = "$output,UN,1,$output,IF,8,*,5,/,60,/,$sampling,*"; |
---|
212 | if ( $allout == "") { |
---|
213 | $allout = "$tmpout".""; |
---|
214 | } else { |
---|
215 | $allout = "$tmpout".",".$allout; |
---|
216 | } |
---|
217 | $found = 0; |
---|
218 | } |
---|
219 | } |
---|
220 | if ($foundone==1){ |
---|
221 | for ($i=0; $i < $nbpref-$nofoundnb-1; $i++){ |
---|
222 | $all = $all.",+"; |
---|
223 | $allout = $allout.",+"; |
---|
224 | } |
---|
225 | $CDEF_str_ALLIN = "CDEF:TotalIN=".$all; |
---|
226 | $CDEF_str_ALLOUT = "CDEF:TotalOUT=".$allout; |
---|
227 | rsort($tab_in,SORT_NUMERIC); |
---|
228 | rsort($tab_out,SORT_NUMERIC); |
---|
229 | foreach ( $tab_in as $key => $value ) { |
---|
230 | if ($value != "nan") {$lgin++;} |
---|
231 | } |
---|
232 | $percin = $lgin-intval(($lgin*95/100)); |
---|
233 | foreach ( $tab_out as $key2 => $value2 ) { |
---|
234 | if ($value2 != "nan") {$lgout++;} |
---|
235 | } |
---|
236 | $percout = $lgout-intval(($lgout*95/100)); |
---|
237 | $dr1 = max($tab_in[$percin-1],$tab_out[$percout-1]); |
---|
238 | $debit = number_format($dr1*$sampling*8/5/60,0,",",""); |
---|
239 | $debit = number_format($dr1*$sampling*8/5/60,0,",",""); |
---|
240 | if ($debit > 1000000000) { |
---|
241 | $debit2 = $debit/1000000000; |
---|
242 | $Scale = "G"; |
---|
243 | }else if ($debit > 1000000) { |
---|
244 | $debit2 = $debit/1000000; |
---|
245 | $Scale = "M"; |
---|
246 | }else if ($debit > 1000) { |
---|
247 | $debit2 = $debit/1000; |
---|
248 | $Scale = "K"; |
---|
249 | }else{ |
---|
250 | $Scale = ""; |
---|
251 | } |
---|
252 | $debit2 = number_format($debit2,2,",",""); |
---|
253 | |
---|
254 | $res = `rrdtool graph $pngname -s -31D --title "$nom_du_site" --vertical-label "bits/s" -A $DEF_string $CDEF_string $CDEF_str_ALLIN $CDEF_str_ALLOUT AREA:TotalIN\#00FF00:TotalIN LINE:TotalOUT\#0000FF:TotalOUT GPRINT:TotalIN:MAX:"MAX In %1.1lf%S b/s" GPRINT:TotalOUT:MAX:"MAX Out %1.1lf%S b/s" HRULE:$debit\#FF0000:"RENATER debit (95th percentile) $debit2 $Scale bits/s"`; |
---|
255 | |
---|
256 | |
---|
257 | return $filename; |
---|
258 | } |
---|
259 | } |
---|
260 | |
---|
261 | function graphiqueMetrologie() { |
---|
262 | |
---|
263 | |
---|
264 | $monAg = new Agrement_2($this->tuple['ip_ag_numero'],$this->tuple['ip_ag_version'], $this->dbh); |
---|
265 | $monAg->querySelect('r', true); |
---|
266 | $nom_du_site = $monAg->get_dc_et_code(); |
---|
267 | $prefixe = $this->tuple['ip_adresse']; |
---|
268 | $cidr = $this->tuple['ip_cidr']; |
---|
269 | |
---|
270 | |
---|
271 | |
---|
272 | |
---|
273 | |
---|
274 | |
---|
275 | |
---|
276 | |
---|
277 | |
---|
278 | |
---|
279 | |
---|
280 | $title = "Graphiques Métrologie"; |
---|
281 | require_once("saga_2.inc.php"); |
---|
282 | include("head_2.inc.php"); |
---|
283 | |
---|
284 | |
---|
285 | |
---|
286 | |
---|
287 | |
---|
288 | |
---|
289 | |
---|
290 | |
---|
291 | |
---|
292 | |
---|
293 | if ($found == true) { |
---|
294 | |
---|
295 | $pngJour = $this->generation_graph_jour($nom_du_site, $prefixeTab); |
---|
296 | $pngMois = $this->generation_graph_mois($nom_du_site, $prefixeTab); |
---|
297 | |
---|
298 | $html .= "<img border=\"0\" src=\"images/tmp/".$pngJour."\" alt=\"Graphique journalier\">\n"; |
---|
299 | $html .= "<br>\n"; |
---|
300 | $html .= "<img border=\"0\" src=\"images/tmp/".$pngMois."\" alt=\"Graphique mensuel\">\n"; |
---|
301 | $html .= "</body></html>\n"; |
---|
302 | |
---|
303 | echo $html; |
---|
304 | |
---|
305 | |
---|
306 | |
---|
307 | |
---|
308 | } else { |
---|
309 | |
---|
310 | $html .= "<br> Données indisponibles pour le moment\n"; |
---|
311 | $html .= "</body></html>\n"; |
---|
312 | |
---|
313 | echo $html; |
---|
314 | } |
---|
315 | } |
---|
316 | |
---|
317 | |
---|
318 | |
---|
319 | |
---|
320 | |
---|
321 | |
---|
322 | |
---|
323 | |
---|
324 | |
---|
325 | |
---|
326 | |
---|
327 | |
---|
328 | |
---|
329 | ?> |
---|