/** * return the RrdGraphDef for this graph, used the indicated probe any data can be overridden of a * provided map of Plottable * * @param probe * @param ownData data used to override probe's own values * @return * @throws IOException * @throws RrdException */ public DataProcessor getPlottedDatas(Probe<?, ?> probe, Map<?, ?> ownData, long start, long end) throws IOException { DataProcessor retValue = new DataProcessor(start, end); String rrdName = probe.getRrdName(); String lastName = null; for (DsDesc ds : allds) { boolean stack = ds.graphType == GraphType.STACK; boolean plotted = stack || ds.graphType == GraphType.LINE || ds.graphType == GraphType.AREA; if (ds.rpn == null && ds.dsName != null) { // Does the datas existe in the provided values if (ownData != null && ownData.containsKey(ds.dsName) && ds.graphType == GraphType.LINE) { retValue.addDatasource(ds.name, (Plottable) ownData.get(ds.dsName)); } // Or they might be on the associated rrd else if (probe.dsExist(ds.dsName)) { retValue.addDatasource(ds.name, rrdName, ds.dsName, ds.cf); } } else if (ds.rpn != null) { retValue.addDatasource(ds.name, ds.rpn); } if (plotted && stack) { retValue.addDatasource("Plotted" + ds.name, lastName + ", " + ds.name + ", +"); } else if (plotted) { retValue.addDatasource("Plotted" + ds.name, ds.name); } lastName = ds.name; } if (logger.isTraceEnabled()) { logger.trace("Datastore for " + getName()); for (String s : retValue.getSourceNames()) logger.trace("\t" + s); } return retValue; }
/** * Fill a GraphDef with values as defined by the graph desc * * @param graphDef the GraphDef to configure * @param defProbe The probe to get values from * @param customData some custom data, they override existing values in the associated probe */ public void fillGraphDef( RrdGraphDef graphDef, Probe<?, ?> defProbe, Map<String, ? extends Plottable> customData) { HostsList hl = defProbe.getHostList(); List<DsDesc> toDo = new ArrayList<DsDesc>(); // The datasources already found Set<String> datasources = new HashSet<String>(); for (DsDesc ds : allds) { boolean complete = false; // not a data source, don't try to add it in datasources if (!ds.graphType.datasource()) { complete = true; } // The graph is a percentile else if (ds.percentile != null) { complete = true; graphDef.percentile(ds.name, ds.dsName, ds.percentile); datasources.add(ds.name); } // A rpn datasource else if (ds.rpn != null) { complete = true; if (!datasources.contains(ds.name)) { graphDef.datasource(ds.name, ds.rpn); datasources.add(ds.name); } } else if (ds.graphType == GraphType.LEGEND) { complete = true; } // Does the datas existe in the provided values // It override existing values in the probe else if (customData != null && customData.containsKey(ds.dsName)) { complete = true; if (!datasources.contains(ds.name)) { graphDef.datasource(ds.name, customData.get(ds.dsName)); datasources.add(ds.name); logger.trace(Util.delayedFormatString("custom data found for %s", ds.dsName)); } } // Last but common case, datasource refers to a rrd // Or they might be on the associated rrd else { Probe<?, ?> probe = defProbe; if (ds.dspath != null) { if (logger.isTraceEnabled()) logger.trace( "External probe path: " + ds.dspath.host + "/" + ds.dspath.probe + "/" + ds.dsName); probe = hl.getProbeByPath(ds.dspath.host, ds.dspath.probe); if (probe == null) { logger.error("Invalide probe: " + ds.dspath.host + "/" + ds.dspath.probe); continue; } } if (!probe.dsExist(ds.dsName)) { logger.error("Invalide datasource " + ds.dsName + ", not found in " + probe); continue; } complete = true; if (!datasources.contains(ds.name)) { String rrdName = probe.getRrdName(); graphDef.datasource(ds.name, rrdName, ds.dsName, ds.cf); datasources.add(ds.name); } else { logger.error( "Datasource '" + ds.name + "' defined twice in " + name + ", for found: " + ds); } } if (complete) { toDo.add(ds); } else { logger.debug("Error for " + ds); logger.error("No way to plot " + ds.name + " in " + name + " found"); } } // The title line, only if values block is required if (withSummary) { graphDef.comment(""); // We simulate the color box graphDef.comment(MANYSPACE.substring(0, Math.min(maxLengthLegend, MANYSPACE.length()) + 2)); graphDef.comment("Current"); graphDef.comment(" Average"); graphDef.comment(" Minimum"); graphDef.comment(" Maximum"); graphDef.comment("\\l"); } if (logger.isTraceEnabled()) { logger.trace("Datasource: " + datasources); logger.trace("Todo: " + toDo); } String shortLegend = withSummary ? " \\g" : null; for (DsDesc ds : toDo) { ds.graphType.draw(graphDef, ds.name, ds.color, shortLegend); if (withSummary && ds.graphType.legend()) addLegend(graphDef, ds.name, ds.graphType, ds.legend); } }