[30] | 1 | <?php |
---|
| 2 | function generation_graph_jour($nom_du_site, $prefixe, $cidr, $rrdname, $sampling) { |
---|
| 3 | |
---|
| 4 | $png_path = "/var/www/saga/www/images/tmp/"; |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | $filename = $nom_du_site."_j".".png"; |
---|
| 13 | $pngname = $png_path.$filename; |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | $res = `rrdtool graph $pngname -s -1D --title "$nom_du_site - prefixe : $prefixe / $cidr" --vertical-label "bits/s" DEF:inBytesG=$rrdname:inBytes:AVERAGE DEF:outBytesG=$rrdname:outBytes:AVERAGE CDEF:input10=inBytesG,8,*,5,/,60,/,$sampling,* CDEF:output10=outBytesG,8,*,5,/,60,/,$sampling,* AREA:input10\#00FF00:"In b/s\\n" LINE1:output10\#0000FF:"Out b/s\\n"`; |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | return $filename; |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | function generation_graph_mois($nom_du_site, $prefixe, $cidr, $rrdname, $sampling) { |
---|
| 23 | |
---|
| 24 | global $cfgTmp, $cfgFileSep; |
---|
| 25 | |
---|
| 26 | $png_path = "/var/www/saga/www/images/tmp/"; |
---|
| 27 | $tmp_path .= $cfgTmp.$cfgFileSep; |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | $filename = $nom_du_site."_m".".png"; |
---|
| 37 | $pngname = $png_path.$filename; |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | $tmp_file = $tmp_path.$nom_du_site.".tmp"; |
---|
| 41 | |
---|
| 42 | `rrdtool fetch $rrdname AVERAGE --start -31Days | cut -d " " -f 2,3 > $tmp_file`; |
---|
| 43 | |
---|
| 44 | $fd = fopen ($tmp_file, "r"); |
---|
| 45 | $i=0; |
---|
| 46 | $tab_in = array(); |
---|
| 47 | $tab_out = array(); |
---|
| 48 | while (!feof ($fd)) { |
---|
| 49 | $buffer = fgets($fd, 4096); |
---|
| 50 | $buffer_split = split(" ",$buffer); |
---|
| 51 | $tab_in[$i] = trim($buffer_split[0]); |
---|
| 52 | $tab_out[$i] = trim($buffer_split[1]); |
---|
| 53 | $i++; |
---|
| 54 | } |
---|
| 55 | fclose ($fd); |
---|
| 56 | rsort($tab_in,SORT_NUMERIC); |
---|
| 57 | rsort($tab_out,SORT_NUMERIC); |
---|
[31] | 58 | foreach ( $tab_in as $key => $value ) { |
---|
| 59 | if ($value != "nan") {$lgin++;} |
---|
| 60 | } |
---|
[30] | 61 | $percin = $lgin-intval(($lgin*95/100)); |
---|
[31] | 62 | foreach ( $tab_out as $key2 => $value2 ) { |
---|
| 63 | if ($value2 != "nan") {$lgout++;} |
---|
| 64 | } |
---|
[30] | 65 | $percout = $lgout-intval(($lgout*95/100)); |
---|
[31] | 66 | $dr1 = max($tab_in[$percin-1],$tab_out[$percout-1]); |
---|
[30] | 67 | $debit = number_format($dr1*$sampling); |
---|
| 68 | `rm $tmp_file`; |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | $res = `rrdtool graph $pngname -s -31D --title "$nom_du_site - prefixe : $prefixe / $cidr" --vertical-label "bits/s" DEF:inBytesG=$rrdname:inBytes:AVERAGE DEF:outBytesG=$rrdname:outBytes:AVERAGE CDEF:input10=inBytesG,8,*,5,/,60,/,$sampling,* CDEF:output10=outBytesG,8,*,5,/,60,/,$sampling,* AREA:input10\#00FF00:"In b/s\\n" LINE1:output10\#0000FF:"Out b/s\\n" HRULE:$dr1\#FF0000:"RENATER debit (95th percentile) $debit bits/s"`; |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | return $filename; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | function graphiqueMetrologie() { |
---|
| 78 | |
---|
| 79 | global $cfgTmp, $cfgFileSep, $cfgRrdPath; |
---|
| 80 | |
---|
| 81 | $png_path = "/var/www/saga/www/images/tmp/"; |
---|
| 82 | $nfs_path = $cfgRrdPath.$cfgFileSep; |
---|
| 83 | |
---|
| 84 | $monAg = new Agrement_2($this->tuple['ip_ag_numero'],$this->tuple['ip_ag_version'], $this->dbh); |
---|
| 85 | $monAg->querySelect('r', true); |
---|
| 86 | $nom_du_site = $monAg->get_dc_et_code(); |
---|
| 87 | $prefixe = $this->tuple['ip_adresse']; |
---|
| 88 | $cidr = $this->tuple['ip_cidr']; |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | $tmp = str_replace(".", "_", $prefixe); |
---|
| 103 | $prefix_name = $tmp . "_" . $cidr; |
---|
| 104 | if (is_dir($nfs_path)) { |
---|
| 105 | if ($dh = opendir($nfs_path)) { |
---|
| 106 | while (($file = readdir($dh)) !== false) { |
---|
| 107 | if (strpos($file, $prefix_name) !== false) { |
---|
| 108 | $found = 1; |
---|
| 109 | break; |
---|
| 110 | }; |
---|
| 111 | } |
---|
| 112 | closedir($dh); |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | $title = "Graphiques Métrologie"; |
---|
| 117 | require_once("saga_2.inc.php"); |
---|
| 118 | include("head_2.inc.php"); |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | if ($found == true) { |
---|
| 130 | $rrdname = $nfs_path.$file; |
---|
| 131 | $file_split = split("_", $file); |
---|
| 132 | $tmp = split("\.",$file_split[5]); |
---|
| 133 | $sampling = $tmp[0]; |
---|
| 134 | |
---|
| 135 | $pngJour = $this->generation_graph_jour($nom_du_site, $prefixe, $cidr, $rrdname, $sampling); |
---|
| 136 | $pngMois = $this->generation_graph_mois($nom_du_site, $prefixe, $cidr, $rrdname, $sampling); |
---|
| 137 | |
---|
| 138 | $html .= "<img border=\"0\" src=\"images/tmp/".$pngJour."\" alt=\"Graphique journalier\">\n"; |
---|
| 139 | $html .= "<br>\n"; |
---|
| 140 | $html .= "<img border=\"0\" src=\"images/tmp/".$pngMois."\" alt=\"Graphique mensuel\">\n"; |
---|
| 141 | $html .= "</body></html>\n"; |
---|
| 142 | |
---|
| 143 | echo $html; |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | } else { |
---|
| 149 | |
---|
| 150 | $html .= "<br> Données indisponibles pour le moment\n"; |
---|
| 151 | $html .= "</body></html>\n"; |
---|
| 152 | |
---|
| 153 | echo $html; |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | ?> |
---|