public LinkedList<String> getTreePathByView() { return gd.getViewTree(this); }
public Sum(String name, ArrayList<String> graphList) { super(name); this.graphList = graphList; GraphDesc gd = new GraphDesc(); gd.setGraphName(name); gd.setGraphTitle(name); gd.setName(name); setGraphDesc(gd); getProbe().addGraph(this); }
/** * Add a datastore that will not generate a graph * * @param name String */ public void add(String name) { add(name, name, null, GraphType.NONE, null, null, DEFAULTCF, false, null, null, null); }
public void initializeLimits(Graphics2D g2d) { FontRenderContext frc = g2d.getFontRenderContext(); ImageParameters im = new ImageParameters(); int summaryLines = withSummary ? 5 : 0; im.xsize = getWidth(); im.ysize = getHeight(); im.unitslength = DEFAULT_UNITS_LENGTH; im.xorigin = (int) (PADDING_LEFT + im.unitslength * getSmallFontCharWidth(frc)); im.xorigin += getSmallFontHeight(frc); im.yorigin = PADDING_TOP + im.ysize; if(graphTitle != null && !"".equals(graphTitle)) im.yorigin += getLargeFontHeight(frc) + PADDING_TITLE; im.xgif = PADDING_RIGHT + im.xsize + im.xorigin; im.ygif = im.yorigin + (int) (PADDING_PLOT * getSmallFontHeight(frc)); im.ygif += ((int) getSmallLeading(frc) + summaryLines) * (getLegendLines() + summaryLines); im.ygif += PADDING_BOTTOM; setDimension(im.ygif, im.xgif); }
static public GraphDesc getGraphDesc() { GraphDesc gd = new GraphDesc(); gd.setGraphName("MokeGD"); return gd; }
@Test public void loadGraphDesc() throws Exception { JrdsDocument d = Tools.parseRessource("graphdesc2.xml"); GraphDescBuilder builder = new GraphDescBuilder(); builder.setPm(new PropertiesManager()); GraphDesc gd = (GraphDesc) builder.build(d); Assert.assertEquals("mokegraph", gd.getName()); Assert.assertEquals("mokegraphname", gd.getGraphName()); Assert.assertEquals("mokegraphtitle", gd.getGraphTitle()); Assert.assertTrue(gd.isSiUnit()); Assert.assertEquals("verticallabel", gd.getVerticalLabel()); GraphNode gn = new GraphNode(GetMoke.getProbe(), gd); logger.debug(gd.getHostTree(gn)); logger.debug(gd.getViewTree(gn)); }
@Test public void testCustomGraph() throws Exception { JrdsDocument d = Tools.parseRessource("customgraph.xml"); GraphDescBuilder gdbuild = new GraphDescBuilder(); gdbuild.setPm(Tools.makePm(testFolder)); GraphDesc gd = gdbuild.makeGraphDesc(d); Assert.assertEquals("graph name failed", "graphName", gd.getGraphName()); Assert.assertEquals("graph title failed", "", gd.getGraphTitle()); Assert.assertEquals("graph name failed", "name", gd.getName()); Assert.assertEquals("graph height invalid", 800, gd.getHeight()); Assert.assertEquals("graph width invalid", 600, gd.getWidth()); Assert.assertTrue("Lower limit is a number (not a NaN)" + gd.getUpperLimit(), Double.isNaN(gd.getUpperLimit())); Assert.assertEquals("graph lower limit is invalid", 1000, gd.getLowerLimit(), 0.1); Assert.assertFalse("graph is with legend", gd.withLegend()); Assert.assertFalse("graph is with summary", gd.withSummary()); Assert.assertEquals("legend count failed", 0, gd.getLegendLines()); }
GraphDesc gd = new GraphDesc(); gd.setGraphClass(clazz); else throw new IllegalArgumentException("Invalid constructor"); if(gd.getVerticalLabel() == null) gd.setVerticalLabel(""); gd.setWithLegend(subnode.getElementbyName("nolegend") == null); gd.setWithSummary(subnode.getElementbyName("novalues") == null); gd.setLogarithmic(subnode.getElementbyName("logarithmic") != null); setMethod(unitElem.getElementbyName("base"), gd, "setUnitExponent"); if(unitElem.getElementbyName("binary") != null) gd.setSiUnit(false); else if(unitElem.getElementbyName("SI") != null) gd.setSiUnit(true); gd.add(addName, addrpn, addgraphType, addColor, addLegend, consFunc, reversed, percentile, host, probe, dsName); gd.setTree(PropertiesManager.HOSTSTAB, enumerateTree(subnode.getElementbyName("hosttree"))); gd.setTree(PropertiesManager.VIEWSTAB, enumerateTree(subnode.getElementbyName("viewtree"))); for(JrdsElement treenode: subnode.getChildElementsByName("tree")) { String treetab = treenode.getAttribute("tab"); gd.setTree(treetab, enumerateTree(treenode)); if(gd.getGraphClass() == jrds.Graph.class) { gd.initializeLimits(g2d);
GraphDesc gd = gdbuild.build(d); if(logger.isTraceEnabled()) { Document gddom = gd.dumpAsXml(); ByteArrayOutputStream os = new ByteArrayOutputStream(); Map<String, String> prop = new HashMap<String, String>(3); ExtractInfo ei = ExtractInfo.get().make(pr.getBegin(), pr.getEnd()); Map<String, Plottable> empty = Collections.emptyMap(); RrdGraphDef def = gd.getGraphDef(p, ei, empty); RrdGraphInfo gi = new RrdGraph(def).getRrdGraphInfo(); Assert.assertEquals("graph name failed", "graphName", gd.getGraphName()); Assert.assertEquals("graph title failed", "graphTitle", gd.getGraphTitle()); Assert.assertEquals("graph name failed", "graphdesctest", gd.getName()); Assert.assertEquals("legend count failed", 5, gd.getLegendLines()); Assert.assertFalse("Graph unit should be binary", gd.isSiUnit()); Assert.assertEquals("Graph unit scale should be fixed", 0, gd.getUnitExponent().intValue()); List<String> tree = gd.getTree(new GraphNode(p, gd), treename); Assert.assertEquals("not enough element in tree " + treename, 2, tree.size()); int i = 1;
public GraphNode getGraphNode(JrdsServlet caller) { GraphNode gn = null; if(id != null) gn = hostlist.getGraphById(id); if(gn != null) { logger.debug(jrds.Util.delayedFormatString("Graph found: %s", gn)); } else if(pid != null && pid != 0 && dsName != null) { if(!caller.allowed(this, hostlist.getDefaultRoles())) return null; Probe<?, ?> p = getProbe(); if(p == null) { logger.error("Looking for unknown probe"); return null; } logger.debug(jrds.Util.delayedFormatString("Probe found: %s", p)); Graphics2D g2d = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB).createGraphics(); String graphDescName = p.getName() + "." + dsName; GraphDesc gd = new GraphDesc(); gd.setName(graphDescName); gd.setGraphName(p.getHost().getName() + "." + p.getName() + "." + dsName); gd.setGraphTitle(p.getName() + "." + dsName + " on ${host}"); gd.add(dsName, GraphDesc.LINE); gd.initializeLimits(g2d); gn = new GraphNode(p, gd); gn.addACL(Configuration.get().getPropertiesManager().defaultACL); } return gn; }
static public GraphDesc getGd() { GraphDesc gd = new GraphDesc(); gd.add("sun", null, GraphDesc.LINE.toString(), "green", null, null, null, null, null, null, null); gd.add("shade", null, GraphDesc.LINE.toString(), "blue", null, null, null, null, null, null, null); gd.add("median", "sun,shade,+,2,/", GraphDesc.LINE.toString(), "magenta", null, null, null, null, null, null, null); gd.add("diff", "sun,shade,-,ABS,-1,*", GraphDesc.AREA.toString(), "yellow", null, null, null, null, null, null, null); gd.setGraphTitle("Temperatures in May 2003"); gd.setVerticalLabel("temperature"); return gd; }
@Test public void testCustomGraph() throws IOException { PropertiesManager pm = Tools.makePm(testFolder); pm.setProperty("tabs", "filtertab"); pm.update(); HostsList hl = new HostsList(pm); GraphDesc gd = new GraphDesc(); gd.setName("truc"); gd.setGraphTitle("title"); Map<String, GraphDesc> gdmap = new HashMap<String, GraphDesc>(); gdmap.put(gd.getName(), gd); Set<Tab> tabs = new HashSet<Tab>(); Map<Integer, GraphNode> graphMap = new HashMap<Integer, GraphNode>(); Map<String, GraphTree> graphTrees = new HashMap<String, GraphTree>(); hl.doCustomGraphs(gdmap, graphMap, graphTrees, tabs); hl.addGraphs(graphMap.values()); boolean found = false; GraphNode node = null; for(Tab t: tabs) { if(PropertiesManager.CUSTOMGRAPHTAB.equals(t.id)) { found = true; t.setHostlist(hl); node = t.getGraphTree().enumerateChildsGraph().get(0); } } Assert.assertNotNull(graphMap.get(node.hashCode())); Assert.assertTrue(found); Assert.assertNotEquals(graphTrees.size(), 0); } }
@Test public void test1() throws IOException, InvocationTargetException { RRDToolProbe p = new RRDToolProbe(); p.setHost(new HostStarter(new HostInfo("toto"))); ProbeDesc<String> pd = new ProbeDesc<String>(); pd.setName("Rrdtool"); pd.setProbeName("rrdtool"); p.setPd(pd); Map<String, String> empty = Collections.emptyMap(); p.setMainStore(new RrdDbStoreFactory(), empty); Assert.assertTrue("rrd native file can't be read", rrdfile.canRead()); Assert.assertTrue("Configuration of the probe failed", p.configure(rrdfile)); Assert.assertTrue("Check of the probe failed", p.checkStore()); GraphDesc gd = new GraphDesc(); gd.setGraphName("rrdtool"); gd.setName("rrdtool"); gd.add("speed", "speed", null, GraphDesc.LINE, Color.BLUE, "speed", GraphDesc.DEFAULTCF, false, null, null, null); gd.add("weight", "weight", null, GraphDesc.LINE, Color.GREEN, "weight", GraphDesc.DEFAULTCF, false, null, null, null); p.addGraph(gd); for(GraphNode gn: p.getGraphList()) { Graph g = gn.getGraph(); g.setEnd(new Date(end * 1000)); g.setStart(new Date(start * 1000)); File outputFile = new File(testFolder.getRoot(), "rrdtool.png"); OutputStream out = new FileOutputStream(outputFile); g.writePng(out); Assert.assertTrue("graph not created", outputFile.canRead()); } }
public RrdGraphDef getEmptyGraphDef() { RrdGraphDef retValue = new RrdGraphDef(); if(!Double.isNaN(lowerLimit)) retValue.setMinValue(lowerLimit); if(!Double.isNaN(upperLimit)) retValue.setMaxValue(upperLimit); if(verticalLabel != null) retValue.setVerticalLabel(verticalLabel); if(this.siUnit) retValue.setBase(1000); else retValue.setBase(1024); if(unitExponent != null) { retValue.setUnitsExponent(unitExponent); } retValue.setLogarithmic(logarithmic); retValue.setPoolUsed(true); retValue.setAntiAliasing(true); retValue.setTextAntiAliasing(true); retValue.setImageFormat("PNG"); retValue.setWidth(getWidth()); retValue.setHeight(getHeight()); return retValue; }
@Override String toString(Object o) { GraphDesc gd = (GraphDesc) o; return gd.getGraphName(); } };
public Graph getGraph() { Class<Graph> gclass = gd.getGraphClass(); Graph g; Map<String, GenericBean> beansList; try { g = gclass.getConstructor(GraphNode.class).newInstance(this); beansList = ArgFactory.getBeanPropertiesMap(gclass, Graph.class); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { Util.log(this, logger, Level.ERROR, e, "Failed to build a graph instance %s", gclass.getCanonicalName()); return null; } // Resolve the beans for(Map.Entry<String, String> e: beans.entrySet()) { String name = Util.parseTemplate(e.getKey(), probe); String textValue = Util.parseTemplate(e.getValue(), probe); GenericBean bean = beansList.get(name); if(bean == null) { logger.error(String.format("Unknown bean for %s: %s", gd.getName(), name)); continue; } logger.trace(Util.delayedFormatString("Found attribute %s with value %s", name, textValue)); bean.set(g, textValue); } return g; }
@Override String toString(Object o) { GraphDesc gd = (GraphDesc) o; return gd.getGraphTitle(); } },
Document d = gd.dumpAsXml(); res.setContentType(CONTENT_TYPE); Map<String, String> prop = new HashMap<String, String>(5);
public AutonomousGraphNode(GraphDesc gd) { this.name = gd.getName(); setGraphDesc(gd); setProbe(new ContainerProbe(name)); }
public MockGraph(Probe<?, ?> theStore) { super(theStore, new GraphDesc()); }