var bwxhr = new XHR();
var G;
- var TIME = 0;
- var UDP = 1;
- var TCP = 2;
+ var TIME = 0;
+ var UDP = 1;
+ var TCP = 2;
+ var OTHER = 3;
var width = 760;
var height = 300;
var data_udp = [ ];
var data_tcp = [ ];
+ var data_otr = [ ];
var line_udp;
var line_tcp;
var label_50;
var label_75;
- var label_rx_cur;
- var label_rx_avg;
- var label_rx_peak;
+ var label_udp_cur;
+ var label_udp_avg;
+ var label_udp_peak;
- var label_tx_cur;
- var label_tx_avg;
- var label_tx_peak;
+ var label_tcp_cur;
+ var label_tcp_avg;
+ var label_tcp_peak;
+
+ var label_otr_cur;
+ var label_otr_avg;
+ var label_otr_peak;
var label_scale;
var data_udp_avg = 0;
var data_tcp_avg = 0;
+ var data_otr_avg = 0;
var data_udp_peak = 0;
var data_tcp_peak = 0;
+ var data_otr_peak = 0;
for (var i = data_stamp ? 0 : 1; i < data.length; i++)
{
data_udp.push(data[i][UDP]);
data_tcp.push(data[i][TCP]);
+ data_otr.push(data[i][OTHER]);
}
/* cut off outdated entries */
data_udp = data_udp.slice(data_udp.length - data_wanted, data_udp.length);
data_tcp = data_tcp.slice(data_tcp.length - data_wanted, data_tcp.length);
+ data_otr = data_otr.slice(data_otr.length - data_wanted, data_otr.length);
/* find peak */
for (var i = 0; i < data_udp.length; i++)
{
data_max = Math.max(data_max, data_udp[i]);
data_max = Math.max(data_max, data_tcp[i]);
+ data_max = Math.max(data_max, data_otr[i]);
data_udp_peak = Math.max(data_udp_peak, data_udp[i]);
data_tcp_peak = Math.max(data_tcp_peak, data_tcp[i]);
+ data_otr_peak = Math.max(data_otr_peak, data_otr[i]);
if (i > 0)
{
data_udp_avg = (data_udp_avg + data_udp[i]) / 2;
data_tcp_avg = (data_tcp_avg + data_tcp[i]) / 2;
+ data_otr_avg = (data_otr_avg + data_otr[i]) / 2;
}
else
{
data_udp_avg = data_udp[i];
data_tcp_avg = data_tcp[i];
+ data_otr_avg = data_otr[i];
}
}
/* plot data */
- var pt_rx = '0,' + height;
- var pt_tx = '0,' + height;
+ var pt_udp = '0,' + height;
+ var pt_tcp = '0,' + height;
+ var pt_otr = '0,' + height;
- var y_rx = 0;
- var y_tx = 0;
+ var y_udp = 0;
+ var y_tcp = 0;
+ var y_otr = 0;
for (var i = 0; i < data_udp.length; i++)
{
var x = i * step;
- y_rx = height - Math.floor(data_udp[i] * data_scale);
- y_tx = height - Math.floor(data_tcp[i] * data_scale);
+ y_udp = height - Math.floor(data_udp[i] * data_scale);
+ y_tcp = height - Math.floor(data_tcp[i] * data_scale);
+ y_otr = height - Math.floor(data_otr[i] * data_scale);
- pt_rx += ' ' + x + ',' + y_rx;
- pt_tx += ' ' + x + ',' + y_tx;
+ pt_udp += ' ' + x + ',' + y_udp;
+ pt_tcp += ' ' + x + ',' + y_tcp;
+ pt_otr += ' ' + x + ',' + y_otr;
}
- pt_rx += ' ' + width + ',' + y_rx + ' ' + width + ',' + height;
- pt_tx += ' ' + width + ',' + y_tx + ' ' + width + ',' + height;
+ pt_udp += ' ' + width + ',' + y_udp + ' ' + width + ',' + height;
+ pt_tcp += ' ' + width + ',' + y_tcp + ' ' + width + ',' + height;
+ pt_otr += ' ' + width + ',' + y_otr + ' ' + width + ',' + height;
- line_udp.setAttribute('points', pt_rx);
- line_tcp.setAttribute('points', pt_tx);
+ line_udp.setAttribute('points', pt_udp);
+ line_tcp.setAttribute('points', pt_tcp);
+ line_otr.setAttribute('points', pt_otr);
label_25.firstChild.data = Math.floor(1.1 * 0.25 * data_max);
label_50.firstChild.data = Math.floor(1.1 * 0.50 * data_max);
label_75.firstChild.data = Math.floor(1.1 * 0.75 * data_max);
- label_rx_cur.innerHTML = Math.floor(data_udp[data_udp.length-1]);
- label_tx_cur.innerHTML = Math.floor(data_tcp[data_tcp.length-1]);
+ label_udp_cur.innerHTML = Math.floor(data_udp[data_udp.length-1]);
+ label_tcp_cur.innerHTML = Math.floor(data_tcp[data_tcp.length-1]);
+ label_otr_cur.innerHTML = Math.floor(data_otr[data_otr.length-1]);
- label_rx_avg.innerHTML = Math.floor(data_udp_avg);
- label_tx_avg.innerHTML = Math.floor(data_tcp_avg);
+ label_udp_avg.innerHTML = Math.floor(data_udp_avg);
+ label_tcp_avg.innerHTML = Math.floor(data_tcp_avg);
+ label_otr_avg.innerHTML = Math.floor(data_otr_avg);
- label_rx_peak.innerHTML = Math.floor(data_udp_peak);
- label_tx_peak.innerHTML = Math.floor(data_tcp_peak);
+ label_udp_peak.innerHTML = Math.floor(data_udp_peak);
+ label_tcp_peak.innerHTML = Math.floor(data_tcp_peak);
+ label_otr_peak.innerHTML = Math.floor(data_otr_peak);
/* reset timer */
window.setTimeout(update_graph, 1000);
{
data_udp[i] = 0;
data_tcp[i] = 0;
+ data_otr[i] = 0;
}
/* find svg elements */
line_udp = G.getElementById('udp');
line_tcp = G.getElementById('tcp');
+ line_otr = G.getElementById('other');
label_25 = G.getElementById('label_25');
label_50 = G.getElementById('label_50');
label_75 = G.getElementById('label_75');
- label_rx_cur = document.getElementById('lb_udp_cur');
- label_rx_avg = document.getElementById('lb_udp_avg');
- label_rx_peak = document.getElementById('lb_udp_peak');
+ label_udp_cur = document.getElementById('lb_udp_cur');
+ label_udp_avg = document.getElementById('lb_udp_avg');
+ label_udp_peak = document.getElementById('lb_udp_peak');
+
+ label_tcp_cur = document.getElementById('lb_tcp_cur');
+ label_tcp_avg = document.getElementById('lb_tcp_avg');
+ label_tcp_peak = document.getElementById('lb_tcp_peak');
- label_tx_cur = document.getElementById('lb_tcp_cur');
- label_tx_avg = document.getElementById('lb_tcp_avg');
- label_tx_peak = document.getElementById('lb_tcp_peak');
+ label_otr_cur = document.getElementById('lb_otr_cur');
+ label_otr_avg = document.getElementById('lb_otr_avg');
+ label_otr_peak = document.getElementById('lb_otr_peak');
label_scale = document.getElementById('scale');
<td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td>
<td id="lb_tcp_peak">0</td>
</tr>
+ <tr>
+ <td style="text-align:right; vertical-align:top"><strong style="border-bottom:2px solid red"><%:Other:%></strong></td>
+ <td id="lb_otr_cur">0</td>
+
+ <td style="text-align:right; vertical-align:top"><strong><%:Average:%></strong></td>
+ <td id="lb_otr_avg">0</td>
+
+ <td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td>
+ <td id="lb_otr_peak">0</td>
+ </tr>
</table>
<%+footer%>
uint64_t time;
uint32_t udp;
uint32_t tcp;
+ uint32_t other;
};
struct load_entry {
return update_file(path, &e, sizeof(struct traffic_entry));
}
-static int update_cnstat(uint32_t udp, uint32_t tcp)
+static int update_cnstat(uint32_t udp, uint32_t tcp, uint32_t other)
{
char path[1024];
}
}
- e.time = htonll(time(NULL));
- e.udp = htonl(udp);
- e.tcp = htonl(tcp);
+ e.time = htonll(time(NULL));
+ e.udp = htonl(udp);
+ e.tcp = htonl(tcp);
+ e.other = htonl(other);
return update_file(path, &e, sizeof(struct conn_entry));
}
{
FILE *info;
uint64_t rxb, txb, rxp, txp;
- uint32_t udp, tcp;
+ uint32_t udp, tcp, other;
float lf1, lf5, lf15;
char line[1024];
char ifname[16];
+ struct stat s;
+ const char *ipc = stat("/proc/net/nf_conntrack", &s)
+ ? "/proc/net/ip_conntrack" : "/proc/net/nf_conntrack";
if (!nofork)
{
fclose(info);
}
- if ((info = fopen("/proc/net/ip_conntrack", "r")) != NULL)
+ if ((info = fopen(ipc, "r")) != NULL)
{
- udp = 0;
- tcp = 0;
+ udp = 0;
+ tcp = 0;
+ other = 0;
while (fgets(line, sizeof(line), info))
{
- switch (line[0])
+ if (sscanf(line, "%*s %*d %s", ifname) || sscanf(line, "%s %*d", ifname))
{
- case 't':
+ if (!strcmp(ifname, "tcp"))
tcp++;
- break;
-
- case 'u':
+ else if (!strcmp(ifname, "udp"))
udp++;
- break;
-
- default:
- break;
+ else
+ other++;
}
}
- update_cnstat(udp, tcp);
+ update_cnstat(udp, tcp, other);
fclose(info);
}
if (!e->time)
continue;
- printf("[ %" PRIu64 ", %u, %u ]%s\n",
- ntohll(e->time), ntohl(e->udp), ntohl(e->tcp),
+ printf("[ %" PRIu64 ", %u, %u, %u ]%s\n",
+ ntohll(e->time), ntohl(e->udp),
+ ntohl(e->tcp), ntohl(e->other),
((i + sizeof(struct conn_entry)) < m.size) ? "," : "");
}