|
From: <sa...@us...> - 2003-11-12 10:22:34
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/server
In directory sc8-pr-cvs1:/tmp/cvs-serv5554/org/jrobin/mrtg/server
Modified Files:
Archiver.java Grapher.java Server.java
Log Message:
MRTD demo now uses RrdDbPool for maximum performance
Index: Archiver.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Archiver.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Archiver.java 10 Nov 2003 08:52:29 -0000 1.2
--- Archiver.java 12 Nov 2003 10:22:09 -0000 1.3
***************
*** 25,32 ****
package org.jrobin.mrtg.server;
! import org.jrobin.core.RrdDb;
! import org.jrobin.core.RrdDef;
! import org.jrobin.core.RrdException;
! import org.jrobin.core.Sample;
import org.jrobin.mrtg.Debug;
--- 25,29 ----
package org.jrobin.mrtg.server;
! import org.jrobin.core.*;
import org.jrobin.mrtg.Debug;
***************
*** 38,41 ****
--- 35,39 ----
private int sampleCount, badSavesCount, goodSavesCount;
private LinkedList queue = new LinkedList();
+ private static final RrdDbPool pool = RrdDbPool.getInstance();
public void run() {
***************
*** 58,65 ****
private void process(RawSample rawSample) {
- String rrdFile = getRrdFilename(rawSample);
RrdDb rrdDb = null;
try {
! rrdDb = openRrdFile(rrdFile);
Sample sample = rrdDb.createSample();
sample.setTime(rawSample.getTimestamp());
--- 56,62 ----
private void process(RawSample rawSample) {
RrdDb rrdDb = null;
try {
! rrdDb = openRrdFileFor(rawSample);
Sample sample = rrdDb.createSample();
sample.setTime(rawSample.getTimestamp());
***************
*** 69,91 ****
}
sample.update();
- rrdDb.close();
goodSavesCount++;
! Debug.print("Updated: " + rrdFile);
! } catch (Exception e) {
badSavesCount++;
! Debug.print("Error while storing sample to RRD file " + rrdFile + ": " + e);
! }
! finally {
! if(rrdDb != null) {
! try {
! rrdDb.close();
! } catch (IOException e) {
!
! }
}
}
}
! private String getRrdFilename(RawSample rawSample) {
return getRrdFilename(rawSample.getHost(), rawSample.getIfDescr());
}
--- 66,88 ----
}
sample.update();
goodSavesCount++;
! } catch (IOException e) {
badSavesCount++;
! e.printStackTrace();
! } catch (RrdException e) {
! badSavesCount++;
! e.printStackTrace();
! } finally {
! try {
! pool.release(rrdDb);
! } catch (IOException e) {
! e.printStackTrace();
! } catch (RrdException e) {
! e.printStackTrace();
}
}
}
! private String getRrdFilenameFor(RawSample rawSample) {
return getRrdFilename(rawSample.getHost(), rawSample.getIfDescr());
}
***************
*** 104,114 ****
}
! private RrdDb openRrdFile(String rrdFile) throws IOException, RrdException {
if(new File(rrdFile).exists()) {
! return new RrdDb(rrdFile);
}
else {
// create RRD file first
! RrdDef rrdDef = new RrdDef(rrdFile);
rrdDef.addDatasource("in", "COUNTER", 600, Double.NaN, Double.NaN);
rrdDef.addDatasource("out", "COUNTER", 600, Double.NaN, Double.NaN);
--- 101,115 ----
}
! private RrdDb openRrdFileFor(RawSample rawSample)
! throws IOException, RrdException {
! String rrdFile = getRrdFilenameFor(rawSample);
if(new File(rrdFile).exists()) {
! return pool.requestRrdDb(rrdFile);
}
else {
// create RRD file first
! final RrdDef rrdDef = new RrdDef(rrdFile);
! rrdDef.setStep(300);
! rrdDef.setStartTime(rawSample.getTimestamp() - 10);
rrdDef.addDatasource("in", "COUNTER", 600, Double.NaN, Double.NaN);
rrdDef.addDatasource("out", "COUNTER", 600, Double.NaN, Double.NaN);
***************
*** 126,130 ****
rrdDef.addArchive("MIN", 0.5, 288, 797);
Debug.print("Created: " + rrdFile);
! return new RrdDb(rrdDef);
}
}
--- 127,131 ----
rrdDef.addArchive("MIN", 0.5, 288, 797);
Debug.print("Created: " + rrdFile);
! return pool.requestRrdDb(rrdDef);
}
}
Index: Grapher.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Grapher.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Grapher.java 10 Nov 2003 08:52:29 -0000 1.2
--- Grapher.java 12 Nov 2003 10:22:09 -0000 1.3
***************
*** 59,88 ****
RrdGraph getRrdGraph(long start, long stop) throws MrtgException {
String filename = Archiver.getRrdFilename(host, ifDescr);
! RrdGraphDef gDef = new RrdGraphDef();
try {
! gDef.setImageBorder(Color.WHITE, 0); // Don't show border
! gDef.setTimePeriod(start, stop);
! gDef.setTitle(ifDescr + "@" + host);
! gDef.setVerticalLabel("transfer speed [bits/sec]");
! gDef.datasource("in", filename, "in", "AVERAGE");
! gDef.datasource("out", filename, "out", "AVERAGE");
! gDef.datasource("in8", "in,8,*");
! gDef.datasource("out8", "out,8,*");
! gDef.area("out8", Color.GREEN, "output traffic\n");
! gDef.line("in8", Color.BLUE, "input traffic");
! gDef.comment("\n");
! gDef.gprint("in8", "AVERAGE", "Average input: @7.2 @sbits/s");
! gDef.gprint("in8", "MAX", "Maximum input: @7.2 @Sbits/s\n");
! gDef.gprint("out8", "AVERAGE", "Average output:@7.2 @sbits/s");
! gDef.gprint("out8", "MAX", "Maximum output:@7.2 @Sbits/s\n");
! gDef.comment("\n");
! gDef.comment("Description on device: " + alias);
! gDef.comment("\n");
! gDef.comment("Graph from " + new Date(start * 1000L));
! gDef.comment("to " + new Date(stop * 1000L + 1));
! return new RrdGraph(gDef);
} catch (RrdException e) {
- throw new MrtgException(e);
- } catch (IOException e) {
throw new MrtgException(e);
}
--- 59,88 ----
RrdGraph getRrdGraph(long start, long stop) throws MrtgException {
String filename = Archiver.getRrdFilename(host, ifDescr);
! RrdGraph graph = new RrdGraph(true);
! RrdGraphDef graphDef = new RrdGraphDef();
try {
! graphDef.setImageBorder(Color.WHITE, 0); // Don't show border
! graphDef.setTimePeriod(start, stop);
! graphDef.setTitle(ifDescr + "@" + host);
! graphDef.setVerticalLabel("transfer speed [bits/sec]");
! graphDef.datasource("in", filename, "in", "AVERAGE");
! graphDef.datasource("out", filename, "out", "AVERAGE");
! graphDef.datasource("in8", "in,8,*");
! graphDef.datasource("out8", "out,8,*");
! graphDef.area("out8", Color.GREEN, "output traffic\n");
! graphDef.line("in8", Color.BLUE, "input traffic");
! graphDef.comment("\n");
! graphDef.gprint("in8", "AVERAGE", "Average input: @7.2 @sbits/s");
! graphDef.gprint("in8", "MAX", "Maximum input: @7.2 @Sbits/s\n");
! graphDef.gprint("out8", "AVERAGE", "Average output:@7.2 @sbits/s");
! graphDef.gprint("out8", "MAX", "Maximum output:@7.2 @Sbits/s\n");
! graphDef.comment("\n");
! graphDef.comment("Description on device: " + alias);
! graphDef.comment("\n");
! graphDef.comment("Graph from " + new Date(start * 1000L));
! graphDef.comment("to " + new Date(stop * 1000L + 1));
! graph.setGraphDef(graphDef);
! return graph;
} catch (RrdException e) {
throw new MrtgException(e);
}
Index: Server.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Server.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Server.java 10 Nov 2003 08:52:29 -0000 1.2
--- Server.java 12 Nov 2003 10:22:09 -0000 1.3
***************
*** 63,67 ****
private Server() throws MrtgException {
// set RrdDb locking mode
! RrdDb.setLockMode(RrdDb.WAIT_IF_LOCKED);
String hwFile = Config.getHardwareFile();
if(new File(hwFile).exists()) {
--- 63,67 ----
private Server() throws MrtgException {
// set RrdDb locking mode
! RrdDb.setLockMode(RrdDb.NO_LOCKS);
String hwFile = Config.getHardwareFile();
if(new File(hwFile).exists()) {
|