1.说明
rrd: A high performance data logging and graphing system for time series data.
rrd4j的jar包下载:http://code.google.com/p/rrd4j/
本例子是官方网站上的Demo
2.官方网站上的源码Demo
import org.rrd4j.core.*;
import org.rrd4j.graph.RrdGraph;
import org.rrd4j.graph.RrdGraphDef;
import java.awt.*;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import static org.rrd4j.ConsolFun.*;
import static org.rrd4j.DsType.GAUGE;
/**
* Simple demo just to check that everything is OK with this library. Creates two files in your
* $HOME/rrd4j-demo directory: demo.rrd and demo.png.
*/
public class RrdDemo {
static final long SEED = 1909752002L;
static final Random RANDOM = new Random(SEED);
//文件名称
static final String FILE = "demo";
static final long START = Util.getTimestamp(2010, 4, 1);
static final long END = Util.getTimestamp(2010, 6, 1);
static final int MAX_STEP = 300;
//生成图片的宽度高度
static final int IMG_WIDTH = 500;
static final int IMG_HEIGHT = 300;
/**
* <p>To start the demo, use the following command:</p>
* <pre>
* java -cp rrd4j-{version}.jar org.rrd4j.demo.Demo
* </pre>
*
* @param args the name of the backend factory to use (optional)
* @throws IOException Thrown
*/
public static void main(String[] args) throws IOException {
println("== Starting demo");
long startMillis = System.currentTimeMillis();
if (args.length > 0) {
println("Setting default backend factory to " + args[0]);
RrdDb.setDefaultFactory(args[0]);
}
long start = START;
long end = END;
//文件路径
String rrdPath = Util.getRrd4jDemoPath(FILE + ".rrd");
String xmlPath = Util.getRrd4jDemoPath(