java.lang.Object
org.rrd4j.core.FetchData

public class FetchDataextends Object
Class used to represent data fetched from the RRD. Object of this class is created when the method fetchData() is called on a FetchRequest object.

Data returned from the RRD is, simply, just one big table filled with timestamps and corresponding datasource values. Use getRowCount() method to count the number of returned timestamps (table rows).

The first table column is filled with timestamps. Time intervals between consecutive timestamps are guaranteed to be equal. Use getTimestamps() method to get an array of timestamps returned.

Remaining columns are filled with datasource values for the whole timestamp range, on a column-per-datasource basis. Use getColumnCount() to find the number of datasources and getValues(i) method to obtain all values for the i-th datasource. Returned datasource values correspond to the values returned with getTimestamps() method.

This data structure holds the fetched information.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final long
    The end time of the matching archive.
    private final long
    The step of the matching archive.
    private String[]
    The names of the data sources.
    private final Archive
    The archive that matched the request.
    private final FetchRequest
    The request that produced this data.
    private static final String
    The RPN compiler source name, anything funny will do.
    private long[]
    The timestamps of the fetched rows.
    private double[][]
    The fetched values, by row and source.
  • Constructor Summary

    Constructors
    Constructor
    Description
    FetchData(Archive matchingArchive, FetchRequest request)
    Bind the request to the archive that will satisfy it.
  • Method Summary

    Modifier and Type
    Method
    Description
    createDataProcessor(String rpnExpression)
    Builds the processor for an RPN expression.
    Dumps the content of the whole FetchData object.
    Dumps fetch data in XML format.
    void
    exportXml(OutputStream outputStream)
    /** Dumps fetch data to output stream in XML format.
    void
    exportXml(String filepath)
    Dumps fetch data to file in XML format.
    void
    Write this fetch result as a fetch_data element tree.
    long
    Returns the timestamp of the last populated slot in the corresponding RRA archive
    long
    Returns the step of the corresponding RRA archive
    int
    Returns the number of columns fetched from the corresponding RRD.
    int
    Retrieve the table index number of a datasource by name.
    Returns array of datasource names found in the corresponding RRD.
    long
    Returns the first timestamp in this FetchData object.
    long
    Returns the last timestamp in this FecthData object.
    Returns Archive object which is determined to be the best match for the timestamps specified in the fetch request.
    Returns FetchRequest object used to create this FetchData object.
    int
    Returns the number of rows fetched from the corresponding RRD.
    double[]
    getRpnValues(String rpnExpression)
    Returns a set of values created by applying RPN expression to the fetched data.
    long
    Returns the step with which this data was fetched.
    long[]
    Returns an array of timestamps covering the whole range specified in the FetchReguest object.
    double[][]
    Returns all archived values for all datasources.
    double[]
    getValues(int dsIndex)
    Returns all archived values for a single datasource.
    double[]
    getValues(String dsName)
    Returns all archived values for a single datasource.
    private static String
    padWithBlanks(String input, int width)
    Pads the text with blanks to the width.
    (package private) void
    setTimestamps(long[] timestamps)
    Sets the timestamps for the fetched data.
    (package private) void
    setValues(double[][] values)
    Sets the values for the fetched data.
    Returns string representing fetched data in a RRDTool-like form.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • RPN_SOURCE_NAME

      private static final String RPN_SOURCE_NAME
      The RPN compiler source name, anything funny will do.
      See Also:
    • request

      private final FetchRequest request
      The request that produced this data.
    • dsNames

      private String[] dsNames
      The names of the data sources.
    • timestamps

      private long[] timestamps
      The timestamps of the fetched rows.
    • values

      private double[][] values
      The fetched values, by row and source.
    • matchingArchive

      private final Archive matchingArchive
      The archive that matched the request.
    • arcStep

      private final long arcStep
      The step of the matching archive.
    • arcEndTime

      private final long arcEndTime
      The end time of the matching archive.
  • Constructor Details

    • FetchData

      FetchData(Archive matchingArchive, FetchRequest request) throws IOException
      Bind the request to the archive that will satisfy it.
      Parameters:
      matchingArchive - the archive selected for this request
      request - the fetch request, whose DS filter names the columns to read
      Throws:
      IOException - if the archive's data sources cannot be listed
  • Method Details

    • setTimestamps

      void setTimestamps(long[] timestamps)
      Sets the timestamps for the fetched data.
      Parameters:
      timestamps - array of timestamps
    • setValues

      void setValues(double[][] values)
      Sets the values for the fetched data.
      Parameters:
      values - 2D array of values
    • getRowCount

      public int getRowCount()
      Returns the number of rows fetched from the corresponding RRD. Each row represents datasource values for the specific timestamp.
      Returns:
      Number of rows.
    • getColumnCount

      public int getColumnCount()
      Returns the number of columns fetched from the corresponding RRD. This number is always equal to the number of datasources defined in the RRD. Each column represents values of a single datasource.
      Returns:
      Number of columns (datasources).
    • getTimestamps

      public long[] getTimestamps()
      Returns an array of timestamps covering the whole range specified in the FetchReguest object.
      Returns:
      Array of equidistant timestamps.
    • getStep

      public long getStep()
      Returns the step with which this data was fetched.
      Returns:
      Step as long.
    • getValues

      public double[] getValues(int dsIndex)
      Returns all archived values for a single datasource. Returned values correspond to timestamps returned with getTimestamps() method.
      Parameters:
      dsIndex - Datasource index, from 0 to getColumnCount() - 1
      Returns:
      Array of single datasource values.
    • getValues

      public double[][] getValues()
      Returns all archived values for all datasources. Returned values correspond to timestamps returned with getTimestamps() method.
      Returns:
      Two-dimensional aray of all datasource values.
    • getValues

      public double[] getValues(String dsName)
      Returns all archived values for a single datasource. Returned values correspond to timestamps returned with getTimestamps() method.
      Parameters:
      dsName - Datasource name, as it appears in the RRD
      Returns:
      Array of single datasource values.
    • getRpnValues

      public double[] getRpnValues(String rpnExpression)
      Returns a set of values created by applying RPN expression to the fetched data. For example, if you have two datasources named x and y in this FetchData and you want to calculate values for (x+y)/2 use something like:

      getRpnValues("x,y,+,2,/");

      Parameters:
      rpnExpression - RRDTool-like RPN expression
      Returns:
      Calculated values, one per timestamp this fetch returned
      Throws:
      IllegalArgumentException - Thrown if invalid RPN expression is supplied
    • getRequest

      public FetchRequest getRequest()
      Returns FetchRequest object used to create this FetchData object.
      Returns:
      Fetch request object.
    • getFirstTimestamp

      public long getFirstTimestamp()
      Returns the first timestamp in this FetchData object.
      Returns:
      The smallest timestamp.
    • getLastTimestamp

      public long getLastTimestamp()
      Returns the last timestamp in this FecthData object.
      Returns:
      The biggest timestamp.
    • getMatchingArchive

      public Archive getMatchingArchive()
      Returns Archive object which is determined to be the best match for the timestamps specified in the fetch request. All datasource values are obtained from round robin archives belonging to this archive.
      Returns:
      Matching archive, the one the datasource values were read from
    • getDsNames

      public String[] getDsNames()
      Returns array of datasource names found in the corresponding RRD. If the request was filtered (data was fetched only for selected datasources), only datasources selected for fetching are returned.
      Returns:
      Array of datasource names.
    • getDsIndex

      public int getDsIndex(String dsName)
      Retrieve the table index number of a datasource by name. Names are case sensitive.
      Parameters:
      dsName - Name of the datasource for which to find the index.
      Returns:
      Index number of the datasources in the value table.
    • dump

      public String dump()
      Dumps the content of the whole FetchData object. Useful for debugging.
      Returns:
      a String containing the contents of this object, for debugging.
    • toString

      public String toString()
      Returns string representing fetched data in a RRDTool-like form.
      Overrides:
      toString in class Object
      Returns:
      Fetched data as a string in a rrdfetch-like output form.
    • padWithBlanks

      private static String padWithBlanks(String input, int width)
      Pads the text with blanks to the width.
      Parameters:
      input - the text to pad
      width - the target width
      Returns:
      the padded text
    • exportXml

      public void exportXml(OutputStream outputStream)
      /** Dumps fetch data to output stream in XML format. A flush is issued at the end of the xml generation.
      Parameters:
      outputStream - Output stream to dump fetch data to
    • exportXml

      public void exportXml(XmlWriter writer)
      Write this fetch result as a fetch_data element tree.
      Parameters:
      writer - the XML writer that receives the fetch_data element tree; it is flushed but never closed, so the caller may append to it
    • exportXml

      public void exportXml(String filepath) throws IOException
      Dumps fetch data to file in XML format.
      Parameters:
      filepath - Path to destination file
      Throws:
      IOException - Thrown in case of I/O error
    • exportXml

      public String exportXml()
      Dumps fetch data in XML format.
      Returns:
      String containing XML formatted fetch data
    • getArcStep

      public long getArcStep()
      Returns the step of the corresponding RRA archive
      Returns:
      Archive step in seconds
    • getArcEndTime

      public long getArcEndTime()
      Returns the timestamp of the last populated slot in the corresponding RRA archive
      Returns:
      Timestamp in seconds
    • createDataProcessor

      private DataProcessor createDataProcessor(String rpnExpression)
      Builds the processor for an RPN expression.
      Parameters:
      rpnExpression - the expression to compile
      Returns:
      the processor for the expression