本文整理汇总了Java中org.jrobin.graph.RrdGraph类的典型用法代码示例。如果您正苦于以下问题:Java RrdGraph类的具体用法?Java RrdGraph怎么用?Java RrdGraph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RrdGraph类属于org.jrobin.graph包,在下文中一共展示了RrdGraph类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: graphByTemplate
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
/**
* 根据定义的XML模板生成图片
*
* @param rootPath
* @param tempFileName
*/
private void graphByTemplate(String rootPath, String tempFileName) {
try {
System.out.println("[rrd graph by xml template start...]");
RrdGraphDefTemplate defTemplate = new RrdGraphDefTemplate(
new InputSource(rootPath + tempFileName));
// setVariable 设置XML template的变量
defTemplate.setVariable("startTime", "20101001 00:00");
defTemplate.setVariable("endTime", "20101031 23:59");
defTemplate.setVariable("in_rrd_file", rootPath + "demo_flow.rrd");
defTemplate.setVariable("out_rrd_file", rootPath + "demo_flow.rrd");
RrdGraph graph = new RrdGraph(defTemplate.getRrdGraphDef());
BufferedImage image = new BufferedImage(graph.getRrdGraphInfo()
.getWidth(), graph.getRrdGraphInfo().getHeight(),
BufferedImage.TYPE_INT_RGB);
graph.render(image.getGraphics());
File imgFile = new File(rootPath + "demo_graph_tmp.PNG");
ImageIO.write(image, "PNG", imgFile);//
System.out.println("[rrd graph by xml template success.]");
} catch (Exception e) {
e.printStackTrace();
}
}
开发者ID:micmiu,项目名称:snmp-tutorial,代码行数:30,代码来源:TestGraphCommon.java
示例2: graphByDef
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
public static void graphByDef(RrdGraphDef rgdef) {
try {
RrdGraph graph = new RrdGraph(rgdef);
System.out.println("[rrd graph info:]"
+ graph.getRrdGraphInfo().dump());
// 如果filename没有设置,只是在内存中,可以调用下面的方法再次生成图片文件
if ("-".equals(graph.getRrdGraphInfo().getFilename())) {
createImgFile(graph, "jrobin-graph.jpg");
}
System.out.println("[Jrobin graph by RrdGraphDef success.]");
} catch (Exception e) {
e.printStackTrace();
}
}
开发者ID:micmiu,项目名称:snmp-tutorial,代码行数:17,代码来源:GraphDemoHandler.java
示例3: testPrint
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
@Test
public void testPrint() throws Exception {
long end = System.currentTimeMillis();
long start = end - (24 * 60 * 60 * 1000);
String[] command = new String[] {
"--start=" + start,
"--end=" + end,
"CDEF:something=1",
"PRINT:something:AVERAGE:\"%le\""
};
RrdGraphDef graphDef = ((JRobinRrdStrategy)m_strategy).createGraphDef(new File(""), command);
RrdGraph graph = new RrdGraph(graphDef);
assertNotNull("graph object", graph);
RrdGraphInfo info = graph.getRrdGraphInfo();
assertNotNull("graph info object", info);
String[] printLines = info.getPrintLines();
assertNotNull("graph printLines", printLines);
assertEquals("graph printLines size", 1, printLines.length);
assertEquals("graph printLines item 0", "1.000000e+00", printLines[0]);
double d = Double.parseDouble(printLines[0]);
assertEquals("graph printLines item 0 as a double", 1.0, d, 0.0);
}
开发者ID:qoswork,项目名称:opennmszh,代码行数:26,代码来源:JRobinRrdStrategyTest.java
示例4: execute
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
Object execute() throws RrdException, IOException {
gdef = getGraphDef();
// create diagram finally
RrdGraphInfo info = new RrdGraph(gdef).getRrdGraphInfo();
if (info.getFilename().equals(RrdGraphConstants.IN_MEMORY_IMAGE)) {
println(new String(info.getBytes()));
}
else {
println(info.getWidth() + "x" + info.getHeight());
String[] plines = info.getPrintLines();
for (String pline : plines) {
println(pline);
}
if (info.getImgInfo() != null && info.getImgInfo().length() > 0) {
println(info.getImgInfo());
}
}
return info;
}
开发者ID:OpenNMS,项目名称:jrobin,代码行数:21,代码来源:RrdGraphCmd.java
示例5: graph
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
public byte[] graph(Range range, int width, int height, boolean maxHidden) throws IOException {
// static init of the AppContext ClassLoader
AppContextClassLoaderLeakPrevention.dummy();
try {
// Rq : il pourrait être envisagé de récupérer les données dans les fichiers rrd ou autre stockage
// puis de faire des courbes en sparklines html (écrites dans la page html) ou jfreechart
// create common part of graph definition
final RrdGraphDef graphDef = new RrdGraphDef();
if (Locale.CHINESE.getLanguage()
.equals(I18N.getResourceBundle().getLocale().getLanguage())) {
graphDef.setSmallFont(new Font(Font.MONOSPACED, Font.PLAIN, 10));
graphDef.setLargeFont(new Font(Font.MONOSPACED, Font.BOLD, 12));
}
initGraphSource(graphDef, height, maxHidden);
initGraphPeriodAndSize(range, width, height, graphDef);
graphDef.setImageFormat("png");
graphDef.setFilename("-");
// il faut utiliser le pool pour les performances
// et pour éviter des erreurs d'accès concurrents sur les fichiers
// entre différentes générations de graphs et aussi avec l'écriture des données
graphDef.setPoolUsed(true);
return new RrdGraph(graphDef).getRrdGraphInfo().getBytes();
} catch (final RrdException e) {
throw createIOException(e);
}
}
开发者ID:javamelody,项目名称:javamelody,代码行数:32,代码来源:JRobin.java
示例6: createGraph
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
/**
* Creates a graphics binary of this statistics in PNG format.
*
* @param range the range to be shown
* @param width the width of the created PNG
* @param height the height of the created PNG
* @return the created binary image data
* @throws IOException if image creation failed
*/
public byte[] createGraph(Range range, int width, int height) throws IOException {
try {
// Create the graph definition:
RrdGraphDef graphDef = new RrdGraphDef();
graphDef.setPoolUsed(true);
graphDef.setFilename("-"); // Important for in-memory generation!
// Set datasources:
graphDef.datasource("average", _rrdPath, _name, FUNCTION_AVG, _rrdBackendFactory.getFactoryName());
graphDef.datasource("max", _rrdPath, _name, FUNCTION_MAX, _rrdBackendFactory.getFactoryName());
graphDef.setMinValue(0);
// Set graphics stuff:
graphDef.setImageFormat("png");
graphDef.area("average", new GradientPaint(0, 0, Color.RED, 0, height, Color.GREEN, false), "Mean");
graphDef.line("max", Color.BLUE, "Maximum");
graphDef.gprint("average", FUNCTION_AVG, "Mean: %9.0f " + _unit + "\\r");
graphDef.gprint("max", FUNCTION_MAX, "Maximum: %9.0f " + _unit + "\\r");
graphDef.setWidth(width);
graphDef.setHeight(height);
setGraphStartEndTime(graphDef, range);
setGraphTitle(graphDef, _label, range, width);
return new RrdGraph(graphDef).getRrdGraphInfo().getBytes();
}
catch (final RrdException e) {
throw new IOException(e);
}
}
开发者ID:purej,项目名称:purej-vminspect,代码行数:40,代码来源:Statistics.java
示例7: createImgFile
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
/**
* ImageIO 生成图片文件
*/
private void createImgFile(RrdGraph graph, String imgFileFullName) {
try {
BufferedImage image = new BufferedImage(graph.getRrdGraphInfo()
.getWidth(), graph.getRrdGraphInfo().getHeight(),
BufferedImage.TYPE_INT_RGB);
graph.render(image.getGraphics());
File imgFile = new File(imgFileFullName);
ImageIO.write(image, "PNG", imgFile);
} catch (Exception e) {
e.printStackTrace();
}
}
开发者ID:micmiu,项目名称:snmp-tutorial,代码行数:17,代码来源:TestGraphCommon.java
示例8: createImgFile
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
/**
* ImageIO 生成图片文件
*/
public static void createImgFile(RrdGraph graph, String imgFileName) {
try {
BufferedImage image = new BufferedImage(graph.getRrdGraphInfo()
.getWidth(), graph.getRrdGraphInfo().getHeight(),
BufferedImage.TYPE_INT_RGB);
graph.render(image.getGraphics());
File imgFile = new File(imgFileName);
ImageIO.write(image, "PNG", imgFile);
} catch (Exception e) {
e.printStackTrace();
}
}
开发者ID:micmiu,项目名称:snmp-tutorial,代码行数:17,代码来源:GraphDemoHandler.java
示例9: createGraphReturnDetails
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* This constructs a graphDef by parsing the rrdtool style command and using
* the values to create the JRobin graphDef. It does not understand the 'AT
* style' time arguments however. Also there may be some rrdtool parameters
* that it does not understand. These will be ignored. The graphDef will be
* used to construct an RrdGraph and a PNG image will be created. An input
* stream returning the bytes of the PNG image is returned.
*/
public RrdGraphDetails createGraphReturnDetails(final String command, final File workDir) throws IOException, org.opennms.netmgt.rrd.RrdException {
try {
String[] commandArray = tokenize(command, " \t", false);
RrdGraphDef graphDef = createGraphDef(workDir, commandArray);
graphDef.setSignature("OpenNMS/JRobin");
RrdGraph graph = new RrdGraph(graphDef);
/*
* We use a custom RrdGraphDetails object here instead of the
* DefaultRrdGraphDetails because we won't have an InputStream
* available if no graphing commands were used, e.g.: if we only
* use PRINT or if the user goofs up a graph definition.
*
* We want to throw an RrdException if the caller calls
* RrdGraphDetails.getInputStream and no graphing commands were
* used. If they just call RrdGraphDetails.getPrintLines, though,
* we don't want to throw an exception.
*/
return new JRobinRrdGraphDetails(graph, command);
} catch (Throwable e) {
log().error("JRobin: exception occurred creating graph: " + e.getMessage(), e);
throw new org.opennms.netmgt.rrd.RrdException("An exception occurred creating the graph: " + e.getMessage(), e);
}
}
开发者ID:qoswork,项目名称:opennmszh,代码行数:38,代码来源:JRobinRrdStrategy.java
示例10: testCommentWithNewlines
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
@Test
public void testCommentWithNewlines() throws Exception {
long end = System.currentTimeMillis();
long start = end - (24 * 60 * 60 * 1000);
String[] command = new String[] {
"--start=" + start,
"--end=" + end,
"COMMENT:foo\\n"
};
String[] command2 = new String[] {
"--start=" + start,
"--end=" + end,
"COMMENT:foo\\n",
"COMMENT:foo2\\n"
};
RrdGraphDef graphDef = ((JRobinRrdStrategy)m_strategy).createGraphDef(new File(""), command);
RrdGraph graph = new RrdGraph(graphDef);
assertNotNull("graph object", graph);
int firstHeight = graph.getRrdGraphInfo().getHeight();
RrdGraphDef graphDef2 = ((JRobinRrdStrategy)m_strategy).createGraphDef(new File(""), command2);
RrdGraph graph2 = new RrdGraph(graphDef2);
assertNotNull("second graph object", graph2);
int secondHeight = graph2.getRrdGraphInfo().getHeight();
assertFalse("first graph height " + firstHeight + " and second graph height " + secondHeight + " should not be equal... there should be another newline in the second one making it taller", firstHeight == secondHeight);
}
开发者ID:qoswork,项目名称:opennmszh,代码行数:31,代码来源:JRobinRrdStrategyTest.java
示例11: testGprintWithNewlines
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
@Test
public void testGprintWithNewlines() throws Exception {
long end = System.currentTimeMillis();
long start = end - (24 * 60 * 60 * 1000);
String[] command = new String[] {
"--start=" + start,
"--end=" + end,
"CDEF:a=1",
"GPRINT:a:AVERAGE:\"%8.2lf\\n\""
};
String[] command2 = new String[] {
"--start=" + start,
"--end=" + end,
"CDEF:a=1",
"CDEF:b=1",
"GPRINT:a:AVERAGE:\"%8.2lf\\n\"",
"GPRINT:b:AVERAGE:\"%8.2lf\\n\""
};
RrdGraphDef graphDef = ((JRobinRrdStrategy)m_strategy).createGraphDef(new File(""), command);
RrdGraph graph = new RrdGraph(graphDef);
assertNotNull("graph object", graph);
int firstHeight = graph.getRrdGraphInfo().getHeight();
RrdGraphDef graphDef2 = ((JRobinRrdStrategy)m_strategy).createGraphDef(new File(""), command2);
RrdGraph graph2 = new RrdGraph(graphDef2);
assertNotNull("second graph object", graph2);
int secondHeight = graph2.getRrdGraphInfo().getHeight();
assertFalse("first graph height " + firstHeight + " and second graph height " + secondHeight + " should not be equal... there should be another line with a newline in the second one making it taller", firstHeight == secondHeight);
}
开发者ID:qoswork,项目名称:opennmszh,代码行数:34,代码来源:JRobinRrdStrategyTest.java
示例12: prepareFrame
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
private void prepareFrame() throws RrdException {
gDef = new RrdGraphDef();
gDef.setTimePeriod(start - 5, start);
gDef.setImageBorder(Color.WHITE, 0);
gDef.setTitle(graphTitle);
gDef.setVerticalLabel(graphYLabel);
gDef.setTimeAxisLabel(graphXLabel);
gDef.datasource("a", rrd, "a", "AVERAGE", "MEMORY");
gDef.datasource( "avg", "a", "AVERAGE");
gDef.area("a", Color.decode("0xb6e4"), "Real");
gDef.line("avg", Color.RED, "[email protected]", 2);
gDef.gprint("a", "MIN", "@lmin = @2 [email protected]");
gDef.gprint("a", "MAX", "max = @2 [email protected]");
gDef.gprint("a", "AVERAGE", "avg = @2 [email protected]");
gDef.time("@t", "MMM dd, yyyy - HH:mm:ss", start);
gDef.time("to @[email protected]", "HH:mm:ss");
gDef.comment("@[email protected]"); // some spacing
// create graph
graph = new RrdGraph(gDef);
// add swing components
graphPanel = new GUIGraphPanel(graph);
graphPanel.setGraphDimension(frame.getContentPane().getSize());
jpOutTab.add(graphPanel);
jtp.setSelectedIndex(1); // switch to output tab
// listener to re-render when the window is resized
jpOutTab.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
graphPanel.setGraphDimension(frame.getContentPane().getSize());
}
});
}
开发者ID:cgoldberg,项目名称:netplot,代码行数:35,代码来源:NetPlot.java
示例13: prepareFrame
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
private void prepareFrame() throws RrdException {
gDef = new RrdGraphDef();
gDef.setTimePeriod(START - 10, START);
gDef.setImageBorder(Color.WHITE, 0);
gDef.setTitle(graphTitle);
gDef.setVerticalLabel(graphYLabel);
gDef.setTimeAxisLabel(graphXLabel);
gDef.datasource("a", rrd, "a", "AVERAGE", "MEMORY");
gDef.datasource( "avg", "a", "AVERAGE");
gDef.area("a", Color.decode("0xb6e4"), "Real");
gDef.line("avg", Color.RED, "[email protected]");
gDef.gprint("a", "MIN", "min = @2 [email protected]");
gDef.gprint("a", "MAX", "max = @2 [email protected]");
gDef.gprint("a", "AVERAGE", "avg = @2 ms");
gDef.time("@[email protected] period: @t", "MMM dd, yyyy HH:mm:ss", START);
gDef.time("to @[email protected]", "HH:mm:ss");
// create graph
graph = new RrdGraph(gDef);
// create swing components
graphPanel = new GUIGraphPanel(graph);
frame = new JFrame("Monitor");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(graphPanel);
frame.pack();
frame.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
Dimension d = frame.getContentPane().getSize();
graphPanel.setGraphDimension(d);
}
});
frame.setBounds(100, 100, 500, 400);
frame.setVisible(true);
}
开发者ID:cgoldberg,项目名称:netplot,代码行数:36,代码来源:GUIMonitor.java
示例14: graphByGraphDef
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
/**
* 直接定义画图模板生成图片
*
* @param rootPath
* @param imgFileName
*/
private void graphByGraphDef(String rootPath, String imgFileName) {
try {
System.out.println("[rrd graph by RrdGraphDef start...]");
// 2010-10-01:1285862400L 2010-11-01:1288540800L
long startTime = Util.getTimestamp(2010, 10 - 1, 1);
long endTime = Util.getTimestamp(2010, 10 - 1, 31);
RrdGraphDef rgdef = new RrdGraphDef();
// If the filename is set to '-' the image will be created only in
// memory (no file will be created).
// rgdef.setFilename("-");
rgdef.setFilename(rootPath + imgFileName);
// "PNG", "GIF" or "JPG"
rgdef.setImageFormat("PNG");
// rgdef.setTimeSpan(startTime, endTime);
rgdef.setStartTime(startTime);
rgdef.setEndTime(endTime);
rgdef.setAntiAliasing(false);
rgdef.setSmallFont(new Font("Monospaced", Font.PLAIN, 11));
rgdef.setLargeFont(new Font("SansSerif", Font.BOLD, 14));
rgdef.setTitle("JRobin graph by RrdGraphDef demo");
// default 400
rgdef.setWidth(500);
// default 100
rgdef.setHeight(200);
// 一般不需要设置这个参数
// rgdef.setStep(86400);
rgdef.setVerticalLabel("transfer speed [bits/sec]");
rgdef.datasource("in", rootPath + "demo_flow.rrd", "input",
"AVERAGE");
rgdef.datasource("out", rootPath + "demo_flow.rrd", "output",
"AVERAGE");
rgdef.datasource("in8", "in,8,*");
rgdef.datasource("out8", "out,8,*");
// PS:先画域的再画线的,否则线会被域遮盖
rgdef.area("out8", new Color(0, 206, 0), "output traffic");
rgdef.line("in8", Color.BLUE, "input traffic\\l");
// \\l->左对齐 \\c->中间对齐 \\r->右对齐 \\j->自适应
// \\s-> \\g->glue \\J->
rgdef.gprint("in8", "MAX", "maxIn=%.2f %sbits/sec");
rgdef.gprint("out8", "MAX", "maxOut=%.2f %sbits/sec\\l");
rgdef.gprint("in8", "AVERAGE", "avgIn=%.2f %sbits/sec");
rgdef.gprint("out8", "AVERAGE", "avgOut=%.2f %sbits/sec\\l");
rgdef.gprint("in8", "TOTAL", "totalIn=%.2f %sbits/sec");
rgdef.gprint("out8", "TOTAL", "totalOut=%.2f %sbits/sec\\l");
rgdef.comment("画图测试");
RrdGraph graph = new RrdGraph(rgdef);
System.out.println("[rrd graph info:]"
+ graph.getRrdGraphInfo().dump());
// 如果filename没有设置,只是在内存中,可以调用下面的方法再次生成图片文件
if ("-".equals(graph.getRrdGraphInfo().getFilename())) {
createImgFile(graph, rootPath + imgFileName);
}
System.out.println("[rrd graph by RrdGraphDef success.]");
} catch (Exception e) {
e.printStackTrace();
}
}
开发者ID:micmiu,项目名称:snmp-tutorial,代码行数:73,代码来源:TestGraphCommon.java
示例15: GUIGraphPanel
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
GUIGraphPanel(RrdGraph graph) {
this.graph = graph;
}
开发者ID:cgoldberg,项目名称:netplot,代码行数:4,代码来源:GUIGraphPanel.java
示例16: JRobinRrdGraphDetails
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
/**
* <p>Constructor for JRobinRrdGraphDetails.</p>
*
* @param rrdGraph a {@link org.jrobin.graph.RrdGraph} object.
* @param graphCommand a {@link java.lang.String} object.
*/
public JRobinRrdGraphDetails(RrdGraph rrdGraph, String graphCommand) {
m_rrdGraph = rrdGraph;
m_graphCommand = graphCommand;
}
开发者ID:qoswork,项目名称:opennmszh,代码行数:11,代码来源:JRobinRrdGraphDetails.java
示例17: getRrdGraph
import org.jrobin.graph.RrdGraph; //导入依赖的package包/类
/**
* <p>getRrdGraph</p>
*
* @return a {@link org.jrobin.graph.RrdGraph} object.
*/
public RrdGraph getRrdGraph() {
return m_rrdGraph;
}
开发者ID:qoswork,项目名称:opennmszh,代码行数:9,代码来源:JRobinRrdGraphDetails.java
注:本文中的org.jrobin.graph.RrdGraph类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论