org.rrd4j.graph.RrdGraphDef Java Examples

The following examples show how to use org.rrd4j.graph.RrdGraphDef. 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 vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/node_dsp.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] nodeDispatcherStatsGraph() throws IOException {

    final String path = rrdPath(PLOW_RRD);
    final RrdGraphDef graphDef = baseGraph("Node Dispatcher Traffic", "dps/sec");

    graphDef.datasource("linea", path, "nodeDispatchHit", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "nodeDispatchMiss", ConsolFun.AVERAGE);
    graphDef.datasource("linec", path, "nodeDispatchFail", ConsolFun.AVERAGE);
    graphDef.area("linea", new Color(152, 175, 54), "Hit");
    graphDef.area("lineb", new Color(74, 104, 15), "Miss");
    graphDef.area("linec", new Color(164, 11, 23), "Error");

    return createImage(graphDef);
}
 
Example #2
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/proc_dsp.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] procDispatcherStatsGraph() throws IOException {

    final String path = rrdPath(PLOW_RRD);
    final RrdGraphDef graphDef = baseGraph("Proc Dispatcher Traffic", "dps/sec");

    graphDef.datasource("linea", path, "procDispatchHit", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "procDispatchMiss", ConsolFun.AVERAGE);
    graphDef.datasource("linec", path, "procDispatchFail", ConsolFun.AVERAGE);
    graphDef.area("linea", new Color(152, 175, 54), "Hit");
    graphDef.area("lineb", new Color(74, 104, 15), "Miss");
    graphDef.area("linec", new Color(164, 11, 23), "Error");

    return createImage(graphDef);
}
 
Example #3
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/task_exec.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] taskCountsGraph() throws IOException {

    final String path = rrdPath(PLOW_RRD);
    final RrdGraphDef graphDef = baseGraph("Task Executions", "task/sec");

    graphDef.datasource("linea", path, "taskStartedCount", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "taskStartedFailCount", ConsolFun.AVERAGE);
    graphDef.datasource("linec", path, "taskStoppedCount", ConsolFun.AVERAGE);
    graphDef.datasource("lined", path, "taskStoppedFailCount", ConsolFun.AVERAGE);
    graphDef.area("linea", new Color(8, 175, 193), "Started");
    graphDef.stack("linec", new Color(133, 225, 224), "Stopped");
    graphDef.line("lineb", new Color(243, 165, 41), "Error Started", 2);
    graphDef.line("lined", new Color(241, 93, 5), "Error Stopped", 2);

    return createImage(graphDef);
}
 
Example #4
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/job_launch.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] jobLaunchGraph() throws IOException {

    final String path = rrdPath(PLOW_RRD);
    final RrdGraphDef graphDef = baseGraph("Job Launch", "jobs/sec");

    graphDef.datasource("linea", path, "jobLaunchCount", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "jobLaunchFailCount", ConsolFun.AVERAGE);
    graphDef.datasource("linec", path, "jobFinishCount", ConsolFun.AVERAGE);
    graphDef.datasource("lined", path, "jobKillCount", ConsolFun.AVERAGE);
    graphDef.area("linea", new Color(8, 175, 193), "Launched");
    graphDef.stack("linec", new Color(133, 225, 224), "Finished");
    graphDef.line("lineb", new Color(241, 93, 5), "Launch Fail", 2);
    graphDef.line("lined",  new Color(243, 165, 41), "Jobs Killed", 2);

    return createImage(graphDef);
}
 
Example #5
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/rnd_traffic.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] rndTrafficGraph() throws IOException {

    final String path = rrdPath(PLOW_RRD);
    final RrdGraphDef graphDef = baseGraph("Rnd Traffic", "ops/sec");

    graphDef.datasource("ping", path, "rndPingCount", ConsolFun.AVERAGE);
    graphDef.datasource("task", path, "rndTaskComplete", ConsolFun.AVERAGE);
    graphDef.area("ping", new Color(179, 96, 157), "Ping");
    graphDef.stack("task", new Color(255, 163, 231), "Task Complete");

    graphDef.comment("\\r");

    graphDef.gprint("ping", MAX, "Max Pings = %.3f%S");
    graphDef.gprint("ping", AVERAGE, "Avg Pings = %.3f%S\n");

    graphDef.gprint("task", MAX, "Max Task Complate = %.3f%s");
    graphDef.gprint("task", AVERAGE, "Avg Task Complete = %.3f%S\n");

    return createImage(graphDef);
}
 
Example #6
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/node_threads.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] nodeDispatcherThreads() throws IOException {

    final String path = rrdPath(THREAD_RRD);
    final RrdGraphDef graphDef = baseGraph("Node Dispatcher Queue", "threads/sec");

    graphDef.datasource("threads", path, "nodeActiveThreads", ConsolFun.AVERAGE);
    graphDef.datasource("queue", path, "nodeWaiting", ConsolFun.AVERAGE);

    graphDef.line("threads", new Color(152, 175, 54), "Active Threads");
    graphDef.area("queue", new Color(74, 104, 15), "Queued Work");

    graphDef.comment("\\r");

    graphDef.gprint("threads", MAX, "Max Threads = %.3f%S");
    graphDef.gprint("threads", AVERAGE, "Avg Threads = %.3f%S\n");

    graphDef.gprint("queue", MAX, "Max Queued = %.3f%s");
    graphDef.gprint("queue", AVERAGE, "Avg Queued = %.3f%S\n");

    return createImage(graphDef);
}
 
Example #7
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
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 #8
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
private RrdGraphDef baseGraph(String title, String vertLabel) {
    final long now = System.currentTimeMillis() / 1000;
    RrdGraphDef graphDef = new RrdGraphDef();
    graphDef.setTimeSpan(now - 3600 , now);
    graphDef.setTitle(title);
    graphDef.setVerticalLabel(vertLabel);
    graphDef.setImageFormat("png");
    graphDef.setWidth(800);
    graphDef.setHeight(150);
    graphDef.setAntiAliasing(true);
    graphDef.setTextAntiAliasing(true);
    graphDef.setColor(RrdGraphConstants.COLOR_BACK, new Color(44, 44, 44));
    graphDef.setColor(RrdGraphConstants.COLOR_FONT, new Color(240, 240, 240));
    graphDef.setColor(RrdGraphConstants.COLOR_FRAME, new Color(55, 55, 55));
    graphDef.setColor(RrdGraphConstants.COLOR_CANVAS, new Color(55, 55, 55));
    graphDef.setColor(RrdGraphConstants.COLOR_GRID, new Color(82, 82, 82, 155));
    graphDef.setColor(RrdGraphConstants.COLOR_SHADEA, new Color(44, 44, 44));
    graphDef.setColor(RrdGraphConstants.COLOR_SHADEB, new Color(44, 44, 44));
    graphDef.setGridStroke(dottedStroke);
    return graphDef;
}
 
Example #9
Source File: RRDStorage.java    From component-runtime with Apache License 2.0 5 votes vote down vote up
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 #10
Source File: RrdGraphController.java    From plow with Apache License 2.0 5 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/proc_threads.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] procDispatcherThreads() throws IOException {

    final String path = rrdPath(THREAD_RRD);
    final RrdGraphDef graphDef = baseGraph("Proc Dispatcher Queue", "threads/sec");

    graphDef.datasource("linea", path, "procActiveThreads", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "procWaiting", ConsolFun.AVERAGE);
    graphDef.area("lineb", new Color(74, 104, 15), "Queued Work");
    graphDef.line("linea", new Color(152, 175, 54), "Active Threads");

    return createImage(graphDef);
}
 
Example #11
Source File: RrdGraphController.java    From plow with Apache License 2.0 5 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/async_threads.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] asyncWorkQueueThreads() throws IOException {

    final String path = rrdPath(THREAD_RRD);
    final RrdGraphDef graphDef = baseGraph("Async Work Queue", "threads/sec");

    graphDef.datasource("linea", path, "asyncActiveThreads", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "asyncWaiting", ConsolFun.AVERAGE);
    graphDef.area("lineb", new Color(74, 104, 15), "Queued Work");
    graphDef.line("linea", new Color(152, 175, 54), "Active Threads");

    return createImage(graphDef);
}
 
Example #12
Source File: RRD4jChartServlet.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Adds a line for the item to the graph definition.
 * The color of the line is determined by the counter, it simply picks the according index from LINECOLORS (and
 * rolls over if necessary).
 * 
 * @param graphDef the graph definition to fill
 * @param item the item to add a line for
 * @param counter defines the number of the datasource and is used to determine the line color
 */
protected void addLine(RrdGraphDef graphDef, Item item, int counter) {
    Color color = LINECOLORS[counter % LINECOLORS.length];
    String label = itemUIRegistry.getLabel(item.getName());
    String rrdName = RRD4jService.DB_FOLDER + File.separator + item.getName() + ".rrd";
    ConsolFun consolFun;
    if (label != null && label.contains("[") && label.contains("]")) {
        label = label.substring(0, label.indexOf('['));
    }
    try {
        RrdDb db = new RrdDb(rrdName);
        consolFun = db.getRrdDef().getArcDefs()[0].getConsolFun();
        db.close();
    } catch (IOException e) {
        consolFun = ConsolFun.MAX;
    }
    if (item instanceof NumberItem) {
        // we only draw a line
        graphDef.datasource(Integer.toString(counter), rrdName, "state", consolFun); // RRD4jService.getConsolidationFunction(item));
        graphDef.line(Integer.toString(counter), color, label, 2);
    } else {
        // we draw a line and fill the area beneath it with a transparent color
        graphDef.datasource(Integer.toString(counter), rrdName, "state", consolFun); // RRD4jService.getConsolidationFunction(item));
        Color areaColor = AREACOLORS[counter % LINECOLORS.length];

        graphDef.area(Integer.toString(counter), areaColor);
        graphDef.line(Integer.toString(counter), color, label, 2);
    }
}
 
Example #13
Source File: MetricsHistoryHandler.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
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;
}