Exemple #1
0
 private void parseGPrint(String word) {
   String[] tokens = new ColonSplitter(word).split();
   if (tokens.length != 4) {
     throw new IllegalArgumentException("Invalid GPRINT specification: " + word);
   }
   gdef.gprint(tokens[1], ConsolFun.valueOf(tokens[2]), tokens[3]);
 }
Exemple #2
0
 private void parseDef(String word) {
   String[] tokens1 = new ColonSplitter(word).split();
   if (tokens1.length != 4) {
     throw new IllegalArgumentException("Invalid DEF specification: " + word);
   }
   String[] tokens2 = tokens1[1].split("=");
   if (tokens2.length != 2) {
     throw new IllegalArgumentException("Invalid DEF specification: " + word);
   }
   gdef.datasource(tokens2[0], tokens2[1], tokens1[2], ConsolFun.valueOf(tokens1[3]));
 }
Exemple #3
0
 private void parseRra(String word) {
   // RRA:cfun:xff:steps:rows
   String[] tokens = new ColonSplitter(word).split();
   if (tokens.length < 5) {
     throw new IllegalArgumentException("Invalid RRA definition: " + word);
   }
   ConsolFun cf = ConsolFun.valueOf(tokens[1]);
   double xff = parseDouble(tokens[2]);
   int steps = parseInt(tokens[3]);
   int rows = parseInt(tokens[4]);
   rrdDef.addArchive(cf, xff, steps, rows);
 }
  @GET
  @Produces({MediaType.APPLICATION_JSON})
  public Response getChartSeries(
      @Context HttpHeaders headers,
      @QueryParam("rrd") String itemName,
      @QueryParam("ds") String consFunction,
      @QueryParam("start") String start,
      @QueryParam("end") String end,
      @QueryParam("res") long resolution) {
    if (logger.isDebugEnabled()) {
      logger.debug("Received GET request at '{}' for rrd '{}'.", uriInfo.getPath(), itemName);
    }
    String responseType = MediaType.APPLICATION_JSON;

    // RRD specific: no equivalent in PersistenceService known
    ConsolFun consilidationFunction = ConsolFun.valueOf(consFunction);

    // read the start/end time as they are provided in the RRD-way, we use
    // the RRD4j to read them
    long[] times = Util.getTimestamps(start, end);
    Date startTime = new Date();
    startTime.setTime(times[0] * 1000L);
    Date endTime = new Date();
    endTime.setTime(times[1] * 1000L);

    if (itemName.endsWith(".rrd")) {
      itemName = itemName.substring(0, itemName.length() - 4);
    }
    String[] parts = itemName.split(":");
    String service = "rrd4j";

    if (parts.length == 2) {
      itemName = parts[1];
      service = parts[0];
    }

    Item item;
    try {
      item = itemRegistry.getItem(itemName);
      logger.debug("item '{}' found ", item);

      // Prefer RRD-Service
      QueryablePersistenceService persistenceService = getPersistenceServices().get(service);
      // Fallback to first persistenceService from list
      if (persistenceService == null) {
        Iterator<Entry<String, QueryablePersistenceService>> pit =
            getPersistenceServices().entrySet().iterator();
        if (pit.hasNext()) {
          persistenceService = pit.next().getValue();
        } else {
          throw new IllegalArgumentException("No Persistence service found.");
        }
      }
      Object data = null;
      if (persistenceService.getId().equals("rrd4j")) {
        data =
            getRrdSeries(
                persistenceService, item, consilidationFunction, startTime, endTime, resolution);
      } else {
        data = getPersistenceSeries(persistenceService, item, startTime, endTime, resolution);
      }
      return Response.ok(data, responseType).build();
    } catch (ItemNotFoundException e1) {
      logger.error("Item '{}' not found error while requesting series data.", itemName);
    }
    return Response.serverError().build();
  }
Exemple #5
0
  /**
   * Add a plot, but only uses String as parameters, for the GraphFactory
   *
   * @param name Name of the plot
   * @param dsName the datastore to use
   * @param rpn The RPN, used instead of the datastore
   * @param graphType
   * @param color
   * @param legend
   * @param consFunc
   * @param reversed
   * @param host
   * @param probe
   * @param subDsName
   */
  public void add(
      String name,
      String rpn,
      String graphType,
      String color,
      String legend,
      String consFunc,
      String reversed,
      String percentile,
      // The path to an external datastore
      String host,
      String probe,
      String dsName) {
    if (logger.isTraceEnabled())
      logger.trace(
          "Adding " + name + ", " + rpn + ", " + graphType + ", " + color + ", " + legend + ", "
              + consFunc + ", " + reversed + ", " + host + ", " + probe);
    GraphType gt = null;
    if (graphType == null || "".equals(graphType)) {
      if (legend != null) gt = GraphType.COMMENT;
      else gt = GraphType.NONE;
    } else gt = GraphType.valueOf(graphType.toUpperCase());

    ConsolFun cf = null;
    if (gt != GraphType.COMMENT) {
      cf = DEFAULTCF;
      if (consFunc != null && !"".equals(consFunc)) cf = ConsolFun.valueOf(consFunc.toUpperCase());
    }

    Color c = null;
    if (gt.toPlot()) {
      c = Color.WHITE;
      if (color != null && color.toUpperCase().matches("^#[0-9A-F]{6}")) {
        int r = Integer.parseInt(color.substring(1, 3), 16);
        int g = Integer.parseInt(color.substring(3, 5), 16);
        int b = Integer.parseInt(color.substring(5, 7), 16);
        c = new Color(r, g, b);
      } else if (color != null && !"".equals(color)) {
        c = Colors.valueOf(color.toUpperCase()).getColor();
        if (c == null) c = Color.getColor(color);
        if (c == null) {
          logger.error("Cannot read color " + color);
          c = Color.white;
        }
      } else {
        c = Colors.resolveIndex(lastColor);
        if (gt.toPlot()) lastColor++;
      }
    }
    if (name != null) {
      // If not a rpn, it must be a datastore
      if (gt.datasource() && rpn == null && dsName == null) {
        dsName = name;
      }
    }
    // If the name is missing, generate one ?
    else {
      name = Integer.toHexString((int) (Math.random() * Integer.MAX_VALUE));
    }
    // Auto generated legend
    if (legend == null && name != null && gt.legend()) legend = name;

    Integer valPercentile = null;
    if (percentile != null && !"".equals(percentile)) {
      valPercentile = jrds.Util.parseStringNumber(percentile, Integer.valueOf(0));
    }
    add(name, dsName, rpn, gt, c, legend, cf, reversed != null, valPercentile, host, probe);
  }