diff --git a/apps/netmonitor/java/src/net/i2p/netmonitor/NetMonitor.java b/apps/netmonitor/java/src/net/i2p/netmonitor/NetMonitor.java index 31be7918f..6ecd354de 100644 --- a/apps/netmonitor/java/src/net/i2p/netmonitor/NetMonitor.java +++ b/apps/netmonitor/java/src/net/i2p/netmonitor/NetMonitor.java @@ -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.
* - * Usage:NetMonitor [configFilename]
+ * Usage: NetMonitor [configFilename] [--routers filename[,filename]*]
*
*
*
@@ -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:
+ * NetMonitor [configFilename] [--routers filename[,filename]*]
+ */
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();
}
-}
\ No newline at end of file
+}
diff --git a/apps/netmonitor/java/src/net/i2p/netmonitor/NetMonitorRunner.java b/apps/netmonitor/java/src/net/i2p/netmonitor/NetMonitorRunner.java
index 6b2b03e96..116ba7471 100644
--- a/apps/netmonitor/java/src/net/i2p/netmonitor/NetMonitorRunner.java
+++ b/apps/netmonitor/java/src/net/i2p/netmonitor/NetMonitorRunner.java
@@ -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) {}
}
-}
\ No newline at end of file
+}