org.rrd4j.graph.RrdGraph Java Examples
The following examples show how to use
org.rrd4j.graph.RrdGraph.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RrdGraphController.java From plow with Apache License 2.0 | 6 votes |
private byte[] createImage(RrdGraphDef graphDef) throws IOException { RrdGraph graph = new RrdGraph(graphDef); BufferedImage bim = new BufferedImage(graph.getRrdGraphInfo().getWidth(), graph.getRrdGraphInfo().getHeight(), BufferedImage.TYPE_INT_RGB); graph.render(bim.getGraphics()); ByteArrayOutputStream baos = null; try { baos = new ByteArrayOutputStream(); ImageIO.write(bim, "png", baos); baos.flush(); return baos.toByteArray(); } finally { if (baos != null) { baos.close(); } } }
Example #2
Source File: RRDStorage.java From component-runtime with Apache License 2.0 | 5 votes |
private InputStream doRender(final long start, final long end, final int width, final int height) throws IOException { final String rrdPath = getLocation().toAbsolutePath().toString(); final RrdGraphDef def = new RrdGraphDef(); def.setImageFormat("png"); def.setShowSignature(false); def.setWidth(Math.min(width, 4000)); def.setHeight(Math.min(height, 4000)); def.setFilename(RrdGraphConstants.IN_MEMORY_IMAGE); def.setTitle("Statistics from " + Util.getDate(start) + " to " + Util.getDate(end)); def.setTimeSpan(start, end); def.setStep(getFetchStep(start, end)); def.datasource("projects!", rrdPath, "projects!", TOTAL); def.datasource("sources!", rrdPath, "sources!", TOTAL); def.datasource("processors!", rrdPath, "processors!", TOTAL); def.datasource("endpoints!", rrdPath, "endpoints!", TOTAL); facets.forEach(k -> { final String name = k + "!"; def.datasource(name, rrdPath, name, TOTAL); }); def.line("projects!", Color.GRAY, "#projects", 2.f); def.line("sources!", Color.BLUE, "#sources", 2.f); def.line("processors!", Color.CYAN, "#processors", 2.f); def.line("endpoints!", Color.GREEN, "#endpoints", 2.f); final AtomicInteger lastFacetColor = new AtomicInteger(); facets.forEach(k -> def.line(k + '!', new Color(100 + lastFacetColor.addAndGet(20) % 255, 0, 0), "#" + k, 2.f)); return new ByteArrayInputStream(new RrdGraph(def).getRrdGraphInfo().getBytes()); }
Example #3
Source File: MetricsHistoryHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
private NamedList<Object> getDbData(RrdDb db, String[] dsNames, Format format, SolrParams params) throws IOException { NamedList<Object> res = new SimpleOrderedMap<>(); if (dsNames == null || dsNames.length == 0) { dsNames = db.getDsNames(); } StringBuilder str = new StringBuilder(); RrdDef def = db.getRrdDef(); ArcDef[] arcDefs = def.getArcDefs(); for (ArcDef arcDef : arcDefs) { SimpleOrderedMap<Object> map = new SimpleOrderedMap<>(); res.add(arcDef.dump(), map); Archive a = db.getArchive(arcDef.getConsolFun(), arcDef.getSteps()); // startTime / endTime, arcStep are in seconds FetchRequest fr = db.createFetchRequest(arcDef.getConsolFun(), a.getStartTime() - a.getArcStep(), a.getEndTime() + a.getArcStep()); FetchData fd = fr.fetchData(); if (format != Format.GRAPH) { // add timestamps separately from values long[] timestamps = fd.getTimestamps(); if (format == Format.LIST) { // Arrays.asList works only on arrays of Objects map.add("timestamps", Arrays.stream(timestamps).boxed().collect(Collectors.toList())); } else { str.setLength(0); for (int i = 0; i < timestamps.length; i++) { if (i > 0) { str.append('\n'); } str.append(String.valueOf(timestamps[i])); } map.add("timestamps", str.toString()); } } SimpleOrderedMap<Object> values = new SimpleOrderedMap<>(); map.add("values", values); for (String name : dsNames) { double[] vals = fd.getValues(name); switch (format) { case GRAPH: RrdGraphDef graphDef = new RrdGraphDef(); graphDef.setTitle(name); graphDef.datasource(name, fd); graphDef.setStartTime(a.getStartTime() - a.getArcStep()); graphDef.setEndTime(a.getEndTime() + a.getArcStep()); graphDef.setPoolUsed(false); graphDef.setAltAutoscale(true); graphDef.setAltYGrid(true); graphDef.setAltYMrtg(true); graphDef.setSignature("Apache Solr " + versionString); graphDef.setNoLegend(true); graphDef.setAntiAliasing(true); graphDef.setTextAntiAliasing(true); graphDef.setWidth(500); graphDef.setHeight(175); graphDef.setTimeZone(TimeZone.getDefault()); graphDef.setLocale(Locale.ROOT); // redraw immediately graphDef.setLazy(false); // area with a border graphDef.area(name, new Color(0xffb860), null); graphDef.line(name, Color.RED, null, 1.0f); RrdGraph graph = new RrdGraph(graphDef); BufferedImage bi = new BufferedImage( graph.getRrdGraphInfo().getWidth(), graph.getRrdGraphInfo().getHeight(), BufferedImage.TYPE_INT_RGB); graph.render(bi.getGraphics()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(bi, "png", baos); values.add(name, Base64.byteArrayToBase64(baos.toByteArray())); break; case STRING: str.setLength(0); for (int i = 0; i < vals.length; i++) { if (i > 0) { str.append('\n'); } str.append(String.valueOf(vals[i])); } values.add(name, str.toString()); break; case LIST: values.add(name, Arrays.stream(vals).boxed().collect(Collectors.toList())); break; } } } return res; }