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:
jrandom
2004-06-22 04:50:43 +00:00
committed by zzz
parent 2b714967aa
commit 2901287d9e
2 changed files with 65 additions and 14 deletions

View File

@ -18,7 +18,7 @@ import net.i2p.util.Log;
* Main driver for the app that harvests data about the performance of the network,
* 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 String _exportDir;
private String _netDbDir;
private String _explicitRouters;
private int _summaryDurationHours;
private boolean _isRunning;
private Map _peerSummaries;
public NetMonitor() {
this(CONFIG_LOCATION_DEFAULT);
this(CONFIG_LOCATION_DEFAULT, null);
}
public NetMonitor(String configLocation) {
this(configLocation, null);
}
public NetMonitor(String configLocation, String explicitFilenames) {
_configLocation = configLocation;
_explicitRouters = explicitFilenames;
_peerSummaries = new HashMap(32);
loadConfig();
}
@ -120,6 +125,8 @@ public class NetMonitor {
public int getSummaryDurationHours() { return _summaryDurationHours; }
/** where should we read the data from? */
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?
*
@ -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[]) {
if (args.length == 1)
new NetMonitor(args[0]).startMonitor();
else
new NetMonitor(CONFIG_LOCATION_DEFAULT).startMonitor();
String cfgLocation = CONFIG_LOCATION_DEFAULT;
String explicitFilenames = null;
switch (args.length) {
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();
}
}
}

View File

@ -7,6 +7,7 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import net.i2p.data.DataFormatException;
import net.i2p.data.RouterInfo;
@ -128,12 +129,35 @@ class NetMonitorRunner implements Runnable {
* @return list of File objects pointing at the routers around
*/
private File[] listRouters() {
File dbDir = new File(_monitor.getNetDbDir());
File files[] = dbDir.listFiles(new FilenameFilter() {
public boolean accept(File f, String name) {
return name.startsWith("routerInfo-");
}
});
if (_monitor.getExplicitRouters() != null) {
return listRoutersExplicit();
} else {
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;
}
@ -146,4 +170,4 @@ class NetMonitorRunner implements Runnable {
Thread.sleep(_monitor.getHarvestDelay());
} catch (InterruptedException ie) {}
}
}
}