2006-03-19 00:23:23 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.Writer;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
import net.i2p.data.DataHelper;
|
|
|
|
import net.i2p.stat.Rate;
|
|
|
|
import net.i2p.router.RouterContext;
|
|
|
|
|
|
|
|
public class GraphHelper {
|
|
|
|
private RouterContext _context;
|
|
|
|
private Writer _out;
|
|
|
|
private int _periodCount;
|
|
|
|
private boolean _showEvents;
|
|
|
|
private int _width;
|
|
|
|
private int _height;
|
|
|
|
private int _refreshDelaySeconds;
|
|
|
|
/**
|
|
|
|
* Configure this bean to query a particular router context
|
|
|
|
*
|
|
|
|
* @param contextId begging few characters of the routerHash, or null to pick
|
|
|
|
* the first one we come across.
|
|
|
|
*/
|
|
|
|
public void setContextId(String contextId) {
|
|
|
|
try {
|
|
|
|
_context = ContextHelper.getContext(contextId);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
t.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public GraphHelper() {
|
2006-03-20 05:31:09 +00:00
|
|
|
_periodCount = 60; // SummaryListener.PERIODS;
|
2006-03-19 00:23:23 +00:00
|
|
|
_showEvents = false;
|
2006-03-20 05:31:09 +00:00
|
|
|
_width = 250;
|
|
|
|
_height = 100;
|
2006-03-19 00:23:23 +00:00
|
|
|
_refreshDelaySeconds = 60;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOut(Writer out) { _out = out; }
|
|
|
|
public void setPeriodCount(String str) {
|
|
|
|
try { _periodCount = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
|
|
|
|
}
|
|
|
|
public void setShowEvents(boolean b) { _showEvents = b; }
|
|
|
|
public void setHeight(String str) {
|
|
|
|
try { _height = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
|
|
|
|
}
|
|
|
|
public void setWidth(String str) {
|
|
|
|
try { _width = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
|
|
|
|
}
|
|
|
|
public void setRefreshDelay(String str) {
|
|
|
|
try { _refreshDelaySeconds = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getImages() {
|
|
|
|
try {
|
2006-04-10 05:37:28 +00:00
|
|
|
_out.write("<img src=\"viewstat.jsp?stat=bw.combined"
|
|
|
|
+ "&periodCount=" + _periodCount
|
|
|
|
+ "&width=" + _width
|
|
|
|
+ "&height=" + _height
|
|
|
|
+ "\" title=\"Combined bandwidth graph\" />\n");
|
|
|
|
|
2006-03-19 00:23:23 +00:00
|
|
|
List listeners = StatSummarizer.instance().getListeners();
|
|
|
|
for (int i = 0; i < listeners.size(); i++) {
|
|
|
|
SummaryListener lsnr = (SummaryListener)listeners.get(i);
|
|
|
|
Rate r = lsnr.getRate();
|
|
|
|
String title = r.getRateStat().getName() + " for " + DataHelper.formatDuration(_periodCount * r.getPeriod());
|
|
|
|
_out.write("<img src=\"viewstat.jsp?stat=" + r.getRateStat().getName()
|
|
|
|
+ "&showEvents=" + _showEvents
|
|
|
|
+ "&period=" + r.getPeriod()
|
|
|
|
+ "&periodCount=" + _periodCount
|
|
|
|
+ "&width=" + _width
|
|
|
|
+ "&height=" + _height
|
|
|
|
+ "\" title=\"" + title + "\" />\n");
|
|
|
|
}
|
|
|
|
if (_refreshDelaySeconds > 0)
|
|
|
|
_out.write("<meta http-equiv=\"refresh\" content=\"" + _refreshDelaySeconds + "\" />\n");
|
|
|
|
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
ioe.printStackTrace();
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
public String getForm() {
|
|
|
|
try {
|
|
|
|
_out.write("<form action=\"graphs.jsp\" method=\"GET\">");
|
2006-03-20 05:31:09 +00:00
|
|
|
_out.write("Periods: <input size=\"3\" type=\"text\" name=\"periodCount\" value=\"" + _periodCount + "\" /><br />\n");
|
2006-03-19 00:23:23 +00:00
|
|
|
_out.write("Plot averages: <input type=\"radio\" name=\"showEvents\" value=\"false\" " + (_showEvents ? "" : "checked=\"true\" ") + " /> ");
|
|
|
|
_out.write("or plot events: <input type=\"radio\" name=\"showEvents\" value=\"true\" "+ (_showEvents ? "checked=\"true\" " : "") + " /><br />\n");
|
|
|
|
_out.write("Image sizes: width: <input size=\"4\" type=\"text\" name=\"width\" value=\"" + _width
|
|
|
|
+ "\" /> pixels, height: <input size=\"4\" type=\"text\" name=\"height\" value=\"" + _height
|
2006-03-20 05:31:09 +00:00
|
|
|
+ "\" /><br />\n");
|
2006-03-19 00:23:23 +00:00
|
|
|
_out.write("Refresh delay: <select name=\"refreshDelay\"><option value=\"60\">1 minute</option><option value=\"120\">2 minutes</option><option value=\"300\">5 minutes</option><option value=\"600\">10 minutes</option><option value=\"-1\">Never</option></select><br />\n");
|
|
|
|
_out.write("<input type=\"submit\" value=\"Redraw\" />");
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
ioe.printStackTrace();
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
public String getPeerSummary() {
|
|
|
|
try {
|
|
|
|
_context.commSystem().renderStatusHTML(_out);
|
|
|
|
_context.bandwidthLimiter().renderStatusHTML(_out);
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
ioe.printStackTrace();
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|