new command line flags to harvest from an explicit file list rather than using all files in a single directory
(this lets us specify lots of my.info references to make sure we harvest fresh data, rather than depending upon stat propogation) usage: NetMonitor [configFilename] [--routers filename[,filename]*]
This commit is contained in:
@ -18,7 +18,7 @@ import net.i2p.util.Log;
|
|||||||
* Main driver for the app that harvests data about the performance of the network,
|
* Main driver for the app that harvests data about the performance of the network,
|
||||||
* building summaries for each peer that change over time. <p />
|
* building summaries for each peer that change over time. <p />
|
||||||
*
|
*
|
||||||
* Usage: <code>NetMonitor [configFilename]</code> <p />
|
* Usage: <code>NetMonitor [configFilename] [--routers filename[,filename]*]</code> <p />
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
@ -41,15 +41,20 @@ public class NetMonitor {
|
|||||||
private int _exportDelay;
|
private int _exportDelay;
|
||||||
private String _exportDir;
|
private String _exportDir;
|
||||||
private String _netDbDir;
|
private String _netDbDir;
|
||||||
|
private String _explicitRouters;
|
||||||
private int _summaryDurationHours;
|
private int _summaryDurationHours;
|
||||||
private boolean _isRunning;
|
private boolean _isRunning;
|
||||||
private Map _peerSummaries;
|
private Map _peerSummaries;
|
||||||
|
|
||||||
public NetMonitor() {
|
public NetMonitor() {
|
||||||
this(CONFIG_LOCATION_DEFAULT);
|
this(CONFIG_LOCATION_DEFAULT, null);
|
||||||
}
|
}
|
||||||
public NetMonitor(String configLocation) {
|
public NetMonitor(String configLocation) {
|
||||||
|
this(configLocation, null);
|
||||||
|
}
|
||||||
|
public NetMonitor(String configLocation, String explicitFilenames) {
|
||||||
_configLocation = configLocation;
|
_configLocation = configLocation;
|
||||||
|
_explicitRouters = explicitFilenames;
|
||||||
_peerSummaries = new HashMap(32);
|
_peerSummaries = new HashMap(32);
|
||||||
loadConfig();
|
loadConfig();
|
||||||
}
|
}
|
||||||
@ -120,6 +125,8 @@ public class NetMonitor {
|
|||||||
public int getSummaryDurationHours() { return _summaryDurationHours; }
|
public int getSummaryDurationHours() { return _summaryDurationHours; }
|
||||||
/** where should we read the data from? */
|
/** where should we read the data from? */
|
||||||
public String getNetDbDir() { return _netDbDir; }
|
public String getNetDbDir() { return _netDbDir; }
|
||||||
|
/** if specified, contains a set of filenames we want to harvest routerInfo data from */
|
||||||
|
public String getExplicitRouters() { return _explicitRouters; }
|
||||||
/**
|
/**
|
||||||
* what peers are we keeping track of?
|
* what peers are we keeping track of?
|
||||||
*
|
*
|
||||||
@ -203,10 +210,30 @@ public class NetMonitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main driver for the netMonitor. the usage is:
|
||||||
|
* <code>NetMonitor [configFilename] [--routers filename[,filename]*]</code>
|
||||||
|
*/
|
||||||
public static final void main(String args[]) {
|
public static final void main(String args[]) {
|
||||||
if (args.length == 1)
|
String cfgLocation = CONFIG_LOCATION_DEFAULT;
|
||||||
new NetMonitor(args[0]).startMonitor();
|
String explicitFilenames = null;
|
||||||
else
|
switch (args.length) {
|
||||||
new NetMonitor(CONFIG_LOCATION_DEFAULT).startMonitor();
|
case 0:
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
cfgLocation = args[0];
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
explicitFilenames = args[1];
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
cfgLocation = args[0];
|
||||||
|
explicitFilenames = args[2];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.err.println("Usage: NetMonitor [configFilename] [--routers filename[,filename]*]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
new NetMonitor(cfgLocation, explicitFilenames).startMonitor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import java.io.FilenameFilter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
import net.i2p.data.RouterInfo;
|
import net.i2p.data.RouterInfo;
|
||||||
@ -128,12 +129,35 @@ class NetMonitorRunner implements Runnable {
|
|||||||
* @return list of File objects pointing at the routers around
|
* @return list of File objects pointing at the routers around
|
||||||
*/
|
*/
|
||||||
private File[] listRouters() {
|
private File[] listRouters() {
|
||||||
File dbDir = new File(_monitor.getNetDbDir());
|
if (_monitor.getExplicitRouters() != null) {
|
||||||
File files[] = dbDir.listFiles(new FilenameFilter() {
|
return listRoutersExplicit();
|
||||||
public boolean accept(File f, String name) {
|
} else {
|
||||||
return name.startsWith("routerInfo-");
|
File dbDir = new File(_monitor.getNetDbDir());
|
||||||
}
|
File files[] = dbDir.listFiles(new FilenameFilter() {
|
||||||
});
|
public boolean accept(File f, String name) {
|
||||||
|
return name.startsWith("routerInfo-");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of router files that were explicitly specified by the netMonitor
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private File[] listRoutersExplicit() {
|
||||||
|
StringTokenizer tok = new StringTokenizer(_monitor.getExplicitRouters().trim(), ",");
|
||||||
|
List rv = new ArrayList();
|
||||||
|
while (tok.hasMoreTokens()) {
|
||||||
|
String name = tok.nextToken();
|
||||||
|
File cur = new File(name);
|
||||||
|
if (cur.exists())
|
||||||
|
rv.add(cur);
|
||||||
|
}
|
||||||
|
File files[] = new File[rv.size()];
|
||||||
|
for (int i = 0; i < rv.size(); i++)
|
||||||
|
files[i] = (File)rv.get(i);
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,4 +170,4 @@ class NetMonitorRunner implements Runnable {
|
|||||||
Thread.sleep(_monitor.getHarvestDelay());
|
Thread.sleep(_monitor.getHarvestDelay());
|
||||||
} catch (InterruptedException ie) {}
|
} catch (InterruptedException ie) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user