2006-03-18 jrandom

* Made the netDb search load limitations a little less stringent
    * Add support for specifying the number of periods to be plotted on the
      graphs - e.g. to plot only the last hour of a stat that is averaged at
      the 60 second period, add &periodCount=60
This commit is contained in:
jrandom
2006-03-18 23:09:35 +00:00
committed by zzz
parent b03ff21d3b
commit f3849a22ad
7 changed files with 84 additions and 21 deletions

View File

@ -87,18 +87,22 @@ public class StatSummarizer implements Runnable {
//System.out.println("Start listening for " + r.getRateStat().getName() + ": " + r.getPeriod());
}
public boolean renderPng(Rate rate, OutputStream out) throws IOException {
return renderPng(rate, out, -1, -1, false, false, false, false);
return renderPng(rate, out, -1, -1, false, false, false, false, -1);
}
public boolean renderPng(Rate rate, OutputStream out, int width, int height, boolean hideLegend, boolean hideGrid, boolean hideTitle, boolean showEvents) throws IOException {
public boolean renderPng(Rate rate, OutputStream out, int width, int height, boolean hideLegend, boolean hideGrid, boolean hideTitle, boolean showEvents, int periodCount) throws IOException {
for (int i = 0; i < _listeners.size(); i++) {
SummaryListener lsnr = (SummaryListener)_listeners.get(i);
if (lsnr.getRate().equals(rate)) {
lsnr.renderPng(out, width, height, hideLegend, hideGrid, hideTitle, showEvents);
lsnr.renderPng(out, width, height, hideLegend, hideGrid, hideTitle, showEvents, periodCount);
return true;
}
}
return false;
}
public boolean renderPng(OutputStream out, String templateFilename) throws IOException {
SummaryRenderer.render(_context, out, templateFilename);
return true;
}
public boolean getXML(Rate rate, OutputStream out) throws IOException {
for (int i = 0; i < _listeners.size(); i++) {
SummaryListener lsnr = (SummaryListener)_listeners.get(i);

View File

@ -18,6 +18,7 @@ import org.jrobin.core.Sample;
import java.awt.Color;
import org.jrobin.graph.RrdGraph;
import org.jrobin.graph.RrdGraphDef;
import org.jrobin.graph.RrdGraphDefTemplate;
import org.jrobin.core.RrdException;
class SummaryListener implements RateSummaryListener {
@ -116,8 +117,8 @@ class SummaryListener implements RateSummaryListener {
_factory.delete(_db.getPath());
_db = null;
}
public void renderPng(OutputStream out, int width, int height, boolean hideLegend, boolean hideGrid, boolean hideTitle, boolean showEvents) throws IOException {
_renderer.render(out, width, height, hideLegend, hideGrid, hideTitle, showEvents);
public void renderPng(OutputStream out, int width, int height, boolean hideLegend, boolean hideGrid, boolean hideTitle, boolean showEvents, int periodCount) throws IOException {
_renderer.render(out, width, height, hideLegend, hideGrid, hideTitle, showEvents, periodCount);
}
public void renderPng(OutputStream out) throws IOException { _renderer.render(out); }
@ -140,10 +141,39 @@ class SummaryRenderer {
_listener = lsnr;
}
public void render(OutputStream out) throws IOException { render(out, -1, -1, false, false, false, false); }
public void render(OutputStream out, int width, int height, boolean hideLegend, boolean hideGrid, boolean hideTitle, boolean showEvents) throws IOException {
/**
* Render the stats as determined by the specified JRobin xml config,
* but note that this doesn't work on stock jvms, as it requires
* DOM level 3 load and store support. Perhaps we can bundle that, or
* specify who can get it from where, etc.
*
*/
public static void render(I2PAppContext ctx, OutputStream out, String filename) throws IOException {
long end = ctx.clock().now();
long start = end - 60*1000*SummaryListener.PERIODS;
long begin = System.currentTimeMillis();
try {
RrdGraphDefTemplate template = new RrdGraphDefTemplate(filename);
RrdGraphDef def = template.getRrdGraphDef();
def.setTimePeriod(start/1000, end/1000); // ignore the periods in the template
RrdGraph graph = new RrdGraph(def);
byte img[] = graph.getPNGBytes();
out.write(img);
} catch (RrdException re) {
//_log.error("Error rendering " + filename, re);
throw new IOException("Error plotting: " + re.getMessage());
} catch (IOException ioe) {
//_log.error("Error rendering " + filename, ioe);
throw ioe;
}
}
public void render(OutputStream out) throws IOException { render(out, -1, -1, false, false, false, false, -1); }
public void render(OutputStream out, int width, int height, boolean hideLegend, boolean hideGrid, boolean hideTitle, boolean showEvents, int periodCount) throws IOException {
long end = _listener.now();
long start = end - _listener.getRate().getPeriod()*SummaryListener.PERIODS;
if (periodCount <= 0) periodCount = SummaryListener.PERIODS;
if (periodCount > SummaryListener.PERIODS)
periodCount = SummaryListener.PERIODS;
long start = end - _listener.getRate().getPeriod()*periodCount;
long begin = System.currentTimeMillis();
try {
RrdGraphDef def = new RrdGraphDef();
@ -166,17 +196,31 @@ class SummaryRenderer {
descr = _listener.getRate().getRateStat().getDescription();
}
def.datasource(plotName, path, plotName, "AVERAGE", "MEMORY");
def.area(plotName, Color.BLUE, descr);
def.area(plotName, Color.BLUE, descr + "@r");
if (!hideLegend) {
def.gprint(plotName, "AVERAGE", "average: @2@s");
def.gprint(plotName, "MAX", " max: @2@s@r");
}
/*
// these four lines set up a graph plotting both values and events on the same chart
// (but with the same coordinates, so the values may look pretty skewed)
def.datasource(dsNames[0], path, dsNames[0], "AVERAGE", "MEMORY");
def.datasource(dsNames[1], path, dsNames[1], "AVERAGE", "MEMORY");
def.area(dsNames[0], Color.BLUE, _listener.getRate().getRateStat().getDescription());
def.line(dsNames[1], Color.RED, "Events per period");
*/
if (hideLegend)
def.setShowLegend(false);
if (hideGrid) {
def.setGridX(false);
def.setGridY(false);
}
System.out.println("rendering: path=" + path + " dsNames[0]=" + dsNames[0] + " dsNames[1]=" + dsNames[1] + " lsnr.getName=" + _listener.getName());
//System.out.println("rendering: path=" + path + " dsNames[0]=" + dsNames[0] + " dsNames[1]=" + dsNames[1] + " lsnr.getName=" + _listener.getName());
def.setAntiAliasing(false);
//System.out.println("Rendering: \n" + def.exportXmlTemplate());
//System.out.println("*****************\nData: \n" + _listener.getData().dump());
RrdGraph graph = new RrdGraph(def);
//System.out.println("Graph created");em.
System.out.println("Graph created");
byte data[] = null;
if ( (width <= 0) || (height <= 0) )
data = graph.getPNGBytes();
@ -196,4 +240,4 @@ class SummaryRenderer {
throw ioe;
}
}
}
}

View File

@ -1,10 +1,16 @@
<%
boolean rendered = false;
String templateFile = request.getParameter("template");
if (templateFile != null) {
java.io.OutputStream cout = response.getOutputStream();
response.setContentType("image/png");
rendered = net.i2p.router.web.StatSummarizer.instance().renderPng(cout, templateFile);
}
net.i2p.stat.Rate rate = null;
String stat = request.getParameter("stat");
String period = request.getParameter("period");
net.i2p.stat.RateStat rs = net.i2p.I2PAppContext.getGlobalContext().statManager().getRate(stat);
boolean rendered = false;
if (rs != null) {
if ( !rendered && (rs != null)) {
long per = -1;
try {
per = Long.parseLong(period);
@ -19,15 +25,18 @@ if (rs != null) {
response.setContentType("image/png");
int width = -1;
int height = -1;
int periodCount = -1;
String str = request.getParameter("width");
if (str != null) try { width = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
str = request.getParameter("height");
if (str != null) try { height = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
str = request.getParameter("periodCount");
if (str != null) try { periodCount = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
boolean hideLegend = Boolean.valueOf(""+request.getParameter("hideLegend")).booleanValue();
boolean hideGrid = Boolean.valueOf(""+request.getParameter("hideGrid")).booleanValue();
boolean hideTitle = Boolean.valueOf(""+request.getParameter("hideTitle")).booleanValue();
boolean showEvents = Boolean.valueOf(""+request.getParameter("showEvents")).booleanValue();
rendered = net.i2p.router.web.StatSummarizer.instance().renderPng(rate, cout, width, height, hideLegend, hideGrid, hideTitle, showEvents);
rendered = net.i2p.router.web.StatSummarizer.instance().renderPng(rate, cout, width, height, hideLegend, hideGrid, hideTitle, showEvents, periodCount);
}
if (rendered)
cout.close();

View File

@ -1,4 +1,10 @@
$Id: history.txt,v 1.432 2006/03/16 16:45:28 jrandom Exp $
$Id: history.txt,v 1.433 2006/03/17 18:46:03 jrandom Exp $
2006-03-18 jrandom
* Made the netDb search load limitations a little less stringent
* Add support for specifying the number of periods to be plotted on the
graphs - e.g. to plot only the last hour of a stat that is averaged at
the 60 second period, add &periodCount=60
2006-03-17 jrandom
* Add support for graphing the event count as well as the average stat

View File

@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
*
*/
public class RouterVersion {
public final static String ID = "$Revision: 1.373 $ $Date: 2006/03/16 16:45:26 $";
public final static String ID = "$Revision: 1.374 $ $Date: 2006/03/17 18:46:02 $";
public final static String VERSION = "0.6.1.12";
public final static long BUILD = 11;
public final static long BUILD = 12;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID);

View File

@ -335,7 +335,7 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
if (wantACK)
_inTunnel = selectInboundTunnel();
boolean ok = buildClove();
boolean ok = (_clientMessage != null) && buildClove();
if (!ok) {
dieFatal();
return;

View File

@ -133,7 +133,7 @@ class SearchJob extends JobImpl {
public long getExpiration() { return _expiration; }
public long getTimeoutMs() { return _timeoutMs; }
private static final int PER_FLOODFILL_PEER_TIMEOUT = 30*1000;
private static final int PER_FLOODFILL_PEER_TIMEOUT = 10*1000;
protected int getPerPeerTimeoutMs(Hash peer) {
int timeout = 0;
@ -174,7 +174,7 @@ class SearchJob extends JobImpl {
*/
}
private static int MAX_PEERS_QUERIED = 20;
private static int MAX_PEERS_QUERIED = 40;
/**
* Send the next search, or stop if its completed