Java Code Examples for org.rrd4j.graph.RrdGraphDef#setTitle()

The following examples show how to use org.rrd4j.graph.RrdGraphDef#setTitle() . 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
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 2
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 3
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;
}