-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgraph_pon.php
149 lines (139 loc) · 5.66 KB
/
graph_pon.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
include ("common.php");
include ("dbconnect.php");
if ($_GET) {
$type = $_GET['type'];
$id = $_GET['id'];
if (!preg_match('/^[0-9]*$/', $id)) {
print "that sux";
exit;
} else {
try {
$result = $db->query("SELECT PON.ID, PON.SLOT_ID, PON.PORT_ID, INET_NTOA(OLT.IP_ADDRESS) as IP_ADDRESS from PON LEFT JOIN OLT on PON.OLT=OLT.ID where PON.ID = '$id'");
} catch (PDOException $e) {
echo "Connection Failed:" . $e->getMessage() . "\n";
exit;
}
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$pon_id = type2ponid($row{'SLOT_ID'},$row{'PORT_ID'});
$olt_ip_address = $row["IP_ADDRESS"];
$rrd_name = dirname(__FILE__) . "/rrd/" . $olt_ip_address . "_" . $pon_id . "_" . $type . ".rrd";
if ($type == "unicast" || $type == "broadcast" || $type == "multicast") {
$opts = array( "--start", "-1d", "--lower-limit=0", "--vertical-label=pkts/s", "--title=Daily $type",
"DEF:inoctets=$rrd_name:input:AVERAGE",
"DEF:outoctets=$rrd_name:output:AVERAGE",
"AREA:inoctets#00FF00:In",
"LINE1:outoctets#0000FF:Out\\r",
"GPRINT:inoctets:MAX:IN Max\: %6.0lf pkts/s",
"GPRINT:inoctets:AVERAGE:Avg\: %6.0lf pkts/s",
"GPRINT:inoctets:LAST:Last\: %6.0lf pkts/s\\r",
"GPRINT:outoctets:MAX:OUT Max\: %6.0lf pkts/s",
"GPRINT:outoctets:AVERAGE:Avg\: %6.0lf pkts/s",
"GPRINT:outoctets:LAST:Last\: %6.0lf pkts/s\\r"
);
$opts2 = array( "--start", "-1w", "--lower-limit=0", "--vertical-label=pkts/s", "--title=Weekly $type",
"DEF:inoctets=$rrd_name:input:AVERAGE",
"DEF:outoctets=$rrd_name:output:AVERAGE",
"AREA:inoctets#00FF00:In",
"LINE1:outoctets#0000FF:Out\\r",
"GPRINT:inoctets:MAX:IN Max\: %6.0lf pkts/s",
"GPRINT:inoctets:AVERAGE:Avg\: %6.0lf pkts/s",
"GPRINT:inoctets:LAST:Last\: %6.0lf pkts/s\\r",
"GPRINT:outoctets:MAX:OUT Max\: %6.0lf pkts/s",
"GPRINT:outoctets:AVERAGE:Avg\: %6.0lf pkts/s",
"GPRINT:outoctets:LAST:Last\: %6.0lf pkts/s\\r"
);
$opts3 = array( "--start", "-1m", "--lower-limit=0", "--vertical-label=pkts/s", "--title=Monthly $type",
"DEF:inoctets=$rrd_name:input:AVERAGE",
"DEF:outoctets=$rrd_name:output:AVERAGE",
"AREA:inoctets#00FF00:In",
"LINE1:outoctets#0000FF:Out\\r",
"GPRINT:inoctets:MAX:IN Max\: %6.0lf pkts/s",
"GPRINT:inoctets:AVERAGE:Avg\: %6.0lf pkts/s",
"GPRINT:inoctets:LAST:Last\: %6.0lf pkts/s\\r",
"GPRINT:outoctets:MAX:OUT Max\: %6.0lf pkts/s",
"GPRINT:outoctets:AVERAGE:Avg\: %6.0lf pkts/s",
"GPRINT:outoctets:LAST:Last\: %6.0lf pkts/s\\r"
);
}
if ($type == "traffic") {
$opts = array( "--start", "-1d", "--lower-limit=0", "--vertical-label=b/s", "--title=Daily $type",
"DEF:inoctets=$rrd_name:input:AVERAGE",
"DEF:outoctets=$rrd_name:output:AVERAGE",
"CDEF:inbits=inoctets,8,*",
"CDEF:outbits=outoctets,8,*",
"AREA:inbits#00FF00:In traffic",
"LINE1:outbits#0000FF:Out traffic\\r",
"GPRINT:inbits:MAX:IN Max\: %6.2lf%Sbps",
"COMMENT: ",
"GPRINT:inbits:AVERAGE:Avg\: %6.2lf%Sbps",
"COMMENT: ",
"GPRINT:inbits:LAST:Last\: %6.2lf%Sbps\\r",
"COMMENT:\\n",
"GPRINT:outbits:MAX:OUT Max\: %6.2lf%Sbps",
"COMMENT: ",
"GPRINT:outbits:AVERAGE:Avg\: %6.2lf%Sbps",
"COMMENT: ",
"GPRINT:outbits:LAST:Last\: %6.2lf%Sbps\\r"
);
$opts2 = array( "--start", "-1w", "--lower-limit=0", "--vertical-label=b/s", "--title=Weekly $type",
"DEF:inoctets=$rrd_name:input:AVERAGE",
"DEF:outoctets=$rrd_name:output:AVERAGE",
"CDEF:inbits=inoctets,8,*",
"CDEF:outbits=outoctets,8,*",
"AREA:inbits#00FF00:In traffic",
"LINE1:outbits#0000FF:Out traffic\\r",
"GPRINT:inbits:MAX:IN Max\: %6.2lf%Sbps",
"COMMENT: ",
"GPRINT:inbits:AVERAGE:Avg\: %6.2lf%Sbps",
"COMMENT: ",
"GPRINT:inbits:LAST:Last\: %6.2lf%Sbps\\r",
"COMMENT:\\n",
"GPRINT:outbits:MAX:OUT Max\: %6.2lf%Sbps",
"COMMENT: ",
"GPRINT:outbits:AVERAGE:Avg\: %6.2lf%Sbps",
"COMMENT: ",
"GPRINT:outbits:LAST:Last\: %6.2lf%Sbps\\r"
);
$opts3 = array( "--start", "-1m", "--lower-limit=0", "--vertical-label=b/s", "--title=Monthly $type",
"DEF:inoctets=$rrd_name:input:AVERAGE",
"DEF:outoctets=$rrd_name:output:AVERAGE",
"CDEF:inbits=inoctets,8,*",
"CDEF:outbits=outoctets,8,*",
"AREA:inbits#00FF00:In traffic",
"LINE1:outbits#0000FF:Out traffic\\r",
"GPRINT:inbits:MAX:IN Max\: %6.2lf%Sbps",
"COMMENT: ",
"GPRINT:inbits:AVERAGE:Avg\: %6.2lf%Sbps",
"COMMENT: ",
"GPRINT:inbits:LAST:Last\: %6.2lf%Sbps\\r",
"COMMENT:\\n",
"GPRINT:outbits:MAX:OUT Max\: %6.2lf%Sbps",
"COMMENT: ",
"GPRINT:outbits:AVERAGE:Avg\: %6.2lf%Sbps",
"COMMENT: ",
"GPRINT:outbits:LAST:Last\: %6.2lf%Sbps\\r"
);
}
$rrd_traffic_url = $olt_ip_address . "_" . $pon_id . "_" . $type . ".gif";
$rrd_traffic_url_week = $olt_ip_address . "_" . $pon_id . "_" . $type . "_week.gif";
$rrd_traffic_url_month = $olt_ip_address . "_" . $pon_id . "_" . $type . "_month.gif";
$rrd_traffic = dirname(__FILE__) . "/rrd/" . $rrd_traffic_url;
$rrd_traffic_week = dirname(__FILE__) . "/rrd/" . $rrd_traffic_url_week;
$rrd_traffic_month = dirname(__FILE__) . "/rrd/" . $rrd_traffic_url_month;
$ret = rrd_graph($rrd_traffic, $opts);
$ret = rrd_graph($rrd_traffic_week, $opts2);
$ret = rrd_graph($rrd_traffic_month, $opts3);
if( !is_array($ret) )
{
$err = rrd_error();
echo "rrd_graph() ERROR: $err\n";
}
}
print "<center><h2>RRD $type Graphs for PON: $olt_ip_address :: $pon_id</h2> ";
print "<p><img src=\"rrd/" . $rrd_traffic_url . "\"></img></p>";
print "<p><img src=\"rrd/" . $rrd_traffic_url_week . "\"></img></p>";
print "<p><img src=\"rrd/" . $rrd_traffic_url_month . "\"></img></p>";
}
}
?>