Commit 471e1bd0 authored by 's avatar

packetloss + EXPIRED_FLOWS:

added timestamps to flow records (only close flow records are paired)

reverted/removed fix introduced in revision 1235, because timestamps should
solve the problem too. Expired flows cannot be "fragmented" in different read_results
-- these "fragments" are not fragments, but different flows (with same IPs, ports...
but different timestamps since now).
So these flows are not joined, but keep separately and distinguished by timestamps.

Note:

historically timestamp was transformed to epoch counter,
since now timestamps are timestamps, epochs are epochs :)

eflow_data is flow record with epoch (internal)
 flow_data is flow record without epoch (to send out)


packetloss GUI:

everything *Top renamed to *Status
added "restart" button (requires some back-end shell script)
some logging/debugging ability
some reorganization...



git-svn-id: file:///home/svn/mapi/trunk@1367 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent bc0f576e
......@@ -7,7 +7,7 @@
#define CGI_FILENAME BASENAME".cgi"
#define CGI_PACKETCOUNT_FILENAME "packetcount.cgi"
#define TOP_FILENAME BASENAME"_top.html" // right frame
#define TOP_FILENAME_CSV BASENAME"_top.csv"
#define TOP_FILENAME_CSV BASENAME"_status.csv"
static char cgi_head[] = "\
#!/usr/bin/rrdcgi\n\
......
......@@ -217,7 +217,7 @@ div.altitle-acronym { /* Do NOT remove -- altitle depends on this. */
opacity: 0.85 /* CSS3 */
}
div.altitle-top {
div.altitle-status {
border-width: 1px;
border-color: #666666;
border-style: dashed;
......
......@@ -8,9 +8,9 @@ require_once "${DIR}lib/config.php";
# }}}
readfile($config->abspath($config->packetloss_home, $config->packetloss_top));
readfile($config->abspath($config->packetloss_home, $config->packetloss_status));
//$content = "";
//$fp = fopen($config->abspath($config->packetloss_home, $config->packetloss_top), "r");
//$fp = fopen($config->abspath($config->packetloss_home, $config->packetloss_status), "r");
//while (!feof($fp)) $content .= fgets($fp, 4096);
//echo $content;
//fclose($fp);
......
......@@ -4,20 +4,24 @@
# packetloss home
packetloss_home = "/path/to/packetloss"
# packetloss restart command
packetloss_restart = "/path/to/packetloss.sh restart '%filter%'"
# rrdtool binary
rrdtool = "rrdtool"
# log file
# rrdtool log file
rrdtool_error_log = "log/packetloss_rrdtool_error.log"
# rrds
packetloss_rrd = "packetloss.rrd"
packetcount_rrd = "packetloss_packets.rrd"
# packetloss top file
packetloss_top = "packetloss_top.csv"
# packetloss status file
packetloss_status = "packetloss_status.csv"
# enable or disable tops
enable_packetloss_top
# enable or disable status
enable_packetloss_status
# packetloss GUI home
......
This diff is collapsed.
/*
* Filename: altitle.js
* Date:
* Author: Aleš Friedl <ales.friedl@email.cz>
*
*/
// Object Literal altitle {{{
var altitle = {
author: "Aleš Friedl",
version: "2.1a",
autorun: true,
exists: false,
init: function() {
if(altitle.exists) return false;
altitle.exists = true;
if(altitle.autorun) altitle.start();
},
start: function() {
var isImg = 0;
var isAcronym = 1;
var isAnchor = 2;
var altitlec = 0;
if(document.getElementsByTagName) {
var miragearr = new Array(
document.getElementsByTagName("img"),
document.getElementsByTagName("acronym"),
document.getElementsByTagName("a")
);
var hasAltitleClassRegExp = new RegExp("(^|\\s)altitleclass_[^\\s$]+(\\s|$)");
for(j = 0; j < miragearr.length; j++) {
for(i = 0; i < miragearr[j].length; i++) {
// exact match! vs. miragearr[i].className.search(/(^a| a)ltitl(e$|e )/) != -1);
// automirage
if(!miragearr[j][i].className.match(new RegExp("(^|\\s)noaltitle(\\s|$)"))) {
var title = miragearr[j][i].getAttribute("title");
if(title != null && title!="") {
var hasAltitleClass = miragearr[j][i].className.match(hasAltitleClassRegExp);
var altitleClass = "";
if(hasAltitleClass) {
var altitleClassRegExp = new RegExp("(^|\\s)altitleclass_[^\\s$]+(\\s|$)");
var altitleClass = altitleClassRegExp.exec(miragearr[j][i].className)[0].substring("altitleclass_".length + 1);
}
var additionaltitle = "";
var firstChild = miragearr[j][i].firstChild;
if(firstChild) {
if(firstChild.nodeName.toLowerCase() == "img") {
//firstChild.setAttribute("alt",""); // XXX mirage needs alt
additionaltitle = "";
}
}
var onmouseoverstr = "if(typeof(altitle) != 'undefined') altitle.show("+(altitlec)+",'"+escape(title+additionaltitle)+"','"+(altitleClass != "" ? altitleClass : (j == isImg ? "altitle-img" : (j == isAcronym ? "altitle-acronym" : "altitle-a")))+"'); return false;";
var onmouseoutstr = "if(typeof(altitle) != 'undefined') altitle.hide("+(altitlec)+"); return true;";
altitlec++;
//miragearr[j][i].setAttribute("onmouseover", onmouseoverstr); // W3C
//miragearr[j][i].setAttribute("onmouseover", new Function(onmouseoverstr)); // M$
miragearr[j][i].onmouseover = new Function(onmouseoverstr);
//miragearr[j][i].setAttribute("onmouseout", onmouseoutstr); // W3C
//miragearr[j][i].setAttribute("onmouseout", new Function(onmouseoutstr)); // M$
miragearr[j][i].onmouseout = new Function(onmouseoutstr);
miragearr[j][i].setAttribute("title", ""); // kill title, bye bye browser
}
}
}
}
}
},
id: null,
show: function(id, title, altitleclass) {
if(id != null || altitle.id != null) { // explicit call or onmousemove implicit call
if(id != null && altitle.id != null){ // previous id not destroyed or duplicit call
if(altitle.id != id) {
altitle.hide(altitle.id); // hide previous
altitle.id = id;
}
else return false; // duplicit -> mutex
}
if(altitle.id == null) altitle.id = id; // first time
if(document.getElementsByTagName) {
var altitleid = document.getElementById("altitle"+altitle.id);
if(!altitleid) { // explicit call, else onmousemove implicit call
altitleid = document.createHTMLElement("div", {"class":altitleclass, "id":"altitle"+(id), "smarttext":unescape(title)});
document.getElementsByTagName("body")[0].appendChild(altitleid);
}
}
if(altitleid) {
var MX = mouse?mouse.MX:0;
var MY = mouse?mouse.MY:0;
var seeX = mouse?mouse.seeX:800;
var seeY = mouse?mouse.seeY:600;
if(MX == 0 && MY == 0) {
MX = (seeX - 100) / 2;
MY = (seeY - 50) / 2;
}
altitleid.style.position = "absolute";
altitleid.style.left = (((MX+100) < seeX) ? MX + 15 : MX - 50) + "px";
altitleid.style.top = (((MY+50) < seeY) ? (((MX+100) < seeX) ? MY + 15 : MY + 20) : MY - 20) + "px";
}
}
else return false; // void onmousemove implicit call
},
hide: function(id) {
if(document.getElementsByTagName) {
var altitleid = document.getElementById("altitle"+id);
if(altitleid) {
document.getElementsByTagName("body")[0].removeChild(altitleid);
}
}
altitle.id = null;
}
}
// }}}
window_onDOMContentLoaded_add(altitle.init);
// vim: set foldmethod=marker foldmarker=\ {{{,\ }}} foldclose= foldcolumn=0 :
/*
* File name: logger.js
* Date: 2007/11/10 18:34
* Author: Ales Friedl <ales.friedl@email.cz>
*
* JavaScript, version
*
*/
// Object Literal logger {{{
var logger = {
author: "Aleš Friedl",
version: "0.1",
debug: false,
logging: true,
autorun: true,
exists: false,
init: function() {
if(logger.exists) return false;
logger.exists = true;
if(logger.autorun) logger.start();
},
logarea: null,
start: function() {
logger.logarea = document.forms["debugform"].debugarea;
logger.running = true;
if(logger.logging) { logger.smartlog("logger.js: Started..."); }
},
stop: function() {
if(logger.logging) logger.smartlog("logger.js: Stopped...");
logger.running = false;
},
clear: function() {
logger.logarea.value = "";
},
smartlog: function(str) {
if(logger.running) {
var delim = " ";
d = new Date();
datestr = (d.getHours() < 10 ? "0" + d.getHours() : d.getHours()) +
":" +
(d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes()) +
":" +
(d.getSeconds() < 10 ? "0" + d.getSeconds() : d.getSeconds()) +
" " +
d.getDate() +
" " +
monthNumberToLongName[d.getMonth()] +
" " +
d.getFullYear();
logger.logarea.value += datestr + delim + str + "\n";
}
}
}
// }}}
window_onDOMContentLoaded_add(logger.init);
// vim: set foldmethod=marker foldmarker=\ {{{,\ }}} foldclose= foldcolumn=0 :
/*
* Filename: mouse.js
* Date: 2007/01/25 18:43
* Author: Aleš Friedl <ales.friedl@email.cz>
*
*/
// Object Literal mouse {{{
var mouse = {
author: "Aleš Friedl",
version: "0.2",
exists: false,
autorun: true,
MX: 0,
MY: 0,
seeX: 800,
seeY: 600,
init: function() {
if(mouse.exists) return false;
mouse.exists = true;
if(mouse.autorun) mouse.start();
},
start: function() {
document.onmousemove = mouse.mousemove;
//if(document.captureEvents) document.captureEvents(Event.MOUSEMOVE);
},
stop: function() {
document.onmousemove = null
//if(document.releaseEvents) document.releaseEvents(Event.MOUSEMOVE);
},
mousemove: function(e) {
if(mouse.exists) {
if(e) {
mouse.MX = e.pageX
mouse.MY = e.pageY
}
else {
mouse.MX = window.event.clientX + (document.documentElement?document.documentElement.scrollLeft:document.body.scrollLeft)
mouse.MY = window.event.clientY + (document.documentElement?document.documentElement.scrollTop:document.body.scrollTop)
}
if(window.innerWidth) {
mouse.seeX = window.innerWidth + window.pageXOffset - 22;
mouse.seeY = window.innerHeight + window.pageYOffset;
}
else {
mouse.seeX = document.body.offsetWidth + (document.documentElement?document.documentElement.scrollLeft:document.body.scrollLeft - 22);
mouse.seeY = document.body.offsetHeight + (document.documentElement?document.documentElement.scrollTop:document.body.scrollTop);
}
if(typeof(altitle) != "undefined") altitle.show();
//window.status = "seeX: "+mouse.seeX+" seeY: "+mouse.seeY+" MX: "+mouse.MX+" MY: "+mouse.MY+"";
}
}
}
// }}}
window_onDOMContentLoaded_add(mouse.init);
// vim: set foldmethod=marker foldmarker=\ {{{,\ }}} foldclose= foldcolumn=0 :
/*
* File name: packetlossTop.js
* File name: packetlossStatus.js
* Date: 2007/09/20 08:48
* Author: Ales Friedl <ales.friedl@email.cz>
*
*/
// Object Literal packetlossTop {{{
// Object Literal packetlossStatus {{{
var packetlossTop = {
var packetlossStatus = {
author: "Aleš Friedl",
version: "0.1",
......@@ -20,13 +20,15 @@ var packetlossTop = {
autorun: true,
running: false,
topfilename: "data/packetloss_top.php",
statusfilename: "data/packetloss_status.php",
init: function() {
if(packetlossTop.exists) return false;
if(packetlossTop.logging) logger.smartlog("packetlossTop.js: Initialized...");
packetlossTop.exists = true;
if(packetlossTop.autorun) packetlossTop.start();
if(packetlossStatus.exists) return false;
packetlossStatus.exists = true;
this.logger = typeof(logger) != "undefined" ? logger : null;
if(packetlossStatus.logging) if(this.logger) this.logger.smartlog("packetlossStatus.js: Initialized...");
if(packetlossStatus.autorun) packetlossStatus.start();
},
request: null,
......@@ -36,9 +38,10 @@ var packetlossTop = {
threadid: 0,
counter: 0,
last_ts: parseInt((new Date()).getTime() / 1000),
last_ts_tolerance: 10, // server-client startup tolerance
last_ts_startuptolerance: 60, // server-client startup tolerance
uptodate: 0,
rslash: ".*.*",
rslash: "↻*↻*",
rqmark: "?¿?¿",
objarr: Array(),
......@@ -49,56 +52,56 @@ var packetlossTop = {
hostarr: Array(),
start: function() {
if(packetlossTop.logging) logger.smartlog("packetlossTop.js: Started...");
packetlossTop.running = true;
packetlossTop.threadid++;
packetlossTop.refresh();
if(packetlossStatus.logging) if(this.logger) this.logger.smartlog("packetlossStatus.js: Started...");
packetlossStatus.running = true;
packetlossStatus.threadid++;
packetlossStatus.refresh();
packetlossTop.buildHostArr();
packetlossStatus.buildHostArr();
},
stop: function() {
if(packetlossTop.logging) logger.smartlog("packetlossTop.js: Stopped...");
if(packetlossTop.tid) {
clearTimeout(packetlossTop.tid);
packetlossTop.tid = null;
if(packetlossTop.logging) logger.smartlog("packetlossTop.js: Some thread killed while sleeping ;)");
if(packetlossStatus.logging) if(this.logger) this.logger.smartlog("packetlossStatus.js: Stopped...");
if(packetlossStatus.tid) {
clearTimeout(packetlossStatus.tid);
packetlossStatus.tid = null;
if(packetlossStatus.logging) if(this.logger) this.logger.smartlog("packetlossStatus.js: Some thread killed while sleeping ;)");
}
packetlossTop.threadid++;
packetlossTop.running = false;
packetlossStatus.threadid++;
packetlossStatus.running = false;
},
restart: function() {
packetlossTop.stop();
packetlossTop.start();
packetlossStatus.stop();
packetlossStatus.start();
},
setRefreshDelay: function(delay) {
if(packetlossTop.logging) logger.smartlog("packetlossTop.js: Changed refresh delay to " + delay + "...");
if(packetlossStatus.logging) if(this.logger) this.logger.smartlog("packetlossStatus.js: Changed refresh delay to " + delay + "...");
if(delay == 0)
packetlossTop.stop();
packetlossStatus.stop();
else {
packetlossTop.delay = delay;
packetlossTop.restart();
packetlossStatus.delay = delay;
packetlossStatus.restart();
}
},
refresh: function() {
packetlossTop.__file2buffer();
packetlossTop.__buffer2arr();
packetlossStatus.__file2buffer();
packetlossStatus.__buffer2arr();
},
__file2buffer: function() {
if(packetlossTop.logging) logger.smartlog("packetlossTop.js: Reading file...");
packetlossTop.request = new Request();
packetlossTop.request.request(packetlossTop.topfilename, {}, packetlossTop.rhandler_closure()); // continue async
if(packetlossStatus.logging) if(this.logger) this.logger.smartlog("packetlossStatus.js: Reading file...");
packetlossStatus.request = new Request();
packetlossStatus.request.request(packetlossStatus.statusfilename, {}, packetlossStatus.rhandler_closure()); // continue async
},
__buffer2arr: function() {
packetlossTop.arr = new Array();
packetlossStatus.arr = new Array();
for(var i = 0; i < packetlossTop.bufferarr.length; i++) {
var record = packetlossTop.bufferarr[i].split(";");
for(var i = 0; i < packetlossStatus.bufferarr.length; i++) {
var record = packetlossStatus.bufferarr[i].split(";");
var stats = record[0];
var category = record[1];
var h0 = record[2];
......@@ -112,12 +115,12 @@ var packetlossTop = {
var unit = record[10];
if(id == "ts") {
packetlossTop.uptodate = (parseInt(value) + packetlossTop.last_ts_tolerance) > packetlossTop.last_ts;
packetlossTop.last_ts_tolerance = 0;
packetlossTop.last_ts = parseInt(value);
packetlossStatus.uptodate = (parseInt(value) + packetlossStatus.last_ts_startuptolerance) > packetlossStatus.last_ts;
packetlossStatus.last_ts_startuptolerance = 0;
packetlossStatus.last_ts = parseInt(value);
}
if(id == "ts" || id == "starttime") {
d = new Date();
var d = new Date();
d.setTime(value + "000");
value = (d.getHours() < 10 ? "0" + d.getHours() : d.getHours()) +
":" +
......@@ -131,18 +134,41 @@ var packetlossTop = {
" " +
d.getFullYear();
}
packetlossTop.arr.push({category: category, h0: h0, d0: d0, relation: relation, h1: h1, d1: d1, id: id, label: label, value: value, unit: unit});
if(id == "uptime") {
var upd = parseInt(value / 86400);
value = value % 86400;
var uphh = parseInt(value / 3600);
value = value % 3600;
var upmm = parseInt(value / 60);
value = value % 60;
var upss = value;
value = "";
if(upd) {
value += upd == 1 ? upd + " day, " : " days, ";
}
if(upd || uphh) {
value += uphh + ":";
}
if(upd || uphh || upmm){
value += (uphh ? upmm.zero() : upmm) + ":";
}
if(upd || uphh || upmm || upss) {
value += (upmm ? upss.zero() : upss);
}
}
packetlossStatus.arr.push({category: category, h0: h0, d0: d0, relation: relation, h1: h1, d1: d1, id: id, label: label, value: value, unit: unit});
}
if(packetlossTop.debug && packetlossTop.logging) logger.smartlog("packetlossTop.js: Stored " + packetlossTop.arr.length + " records");
if(packetlossStatus.debug && packetlossStatus.logging) if(this.logger) this.logger.smartlog("packetlossStatus.js: Stored " + packetlossStatus.arr.length + " records");
},
buildHostArr: function() {
for(var i = 0; i < packetlossTop.arr.length; i++) {
var record = packetlossTop.arr[i];
for(var i = 0; i < packetlossStatus.arr.length; i++) {
var record = packetlossStatus.arr[i];
if(record["id"] == "hostname" && record["h0"] != "*") {
var h0 = record["h0"];
var value = record["value"];
packetlossTop.hostarr.push({
packetlossStatus.hostarr.push({
h0: h0,
value: value,
});
......@@ -151,8 +177,8 @@ var packetlossTop = {
},
__writearr: function() {
for(var i = 0; i < packetlossTop.arr.length; i++) {
var record = packetlossTop.arr[i];
for(var i = 0; i < packetlossStatus.arr.length; i++) {
var record = packetlossStatus.arr[i];
var category = record["category"];
var h0 = record["h0"];
var d0 = record["d0"];
......@@ -165,60 +191,64 @@ var packetlossTop = {
var unit = record["unit"];
var uid = ("id_" + h0 + d0 + relation + h1 + d1 + id).replace(/\*/g, "_");
if(!packetlossTop.objarr[uid]) {
packetlossTop.objarr[uid] = document.getElementById(uid);
if(!packetlossStatus.objarr[uid]) {
packetlossStatus.objarr[uid] = document.getElementById(uid);
}
element = packetlossTop.objarr[uid];
//if(packetlossTop.debug && packetlossTop.logging) logger.smartlog("packetlossTop.js: Updating " + uid + " found " + element);
element = packetlossStatus.objarr[uid];
//if(packetlossStatus.debug && packetlossStatus.logging) if(this.logger) this.logger.smartlog("packetlossStatus.js: Updating " + uid + " found " + element);
if(element) {
if(element.textContent) {
element.textContent = packetlossTop.addSlash(value);
element.textContent = packetlossStatus.addSlash(value);
}
else {
element.innerText = packetlossTop.addSlash(value);
element.innerText = packetlossStatus.addSlash(value);
}
//if(packetlossTop.debug && packetlossTop.logging) logger.smartlog("packetlossTop.js: Updated " + uid + " to " + value);
//if(packetlossStatus.debug && packetlossStatus.logging) logger.smartlog("packetlossStatus.js: Updated " + uid + " to " + value);
}
}