java.lang.Object
org.rrd4j.core.Archive
All Implemented Interfaces:
RrdUpdater<Archive>

public class Archiveextends Object implements RrdUpdater<Archive>
Class to represent single RRD archive in a RRD with its internal state. Normally, you don't need methods to manipulate archive objects directly because Rrd4j framework does it automatically for you.

Each archive object consists of three parts: archive definition, archive state objects (one state object for each datasource) and round robin archives (one round robin for each datasource). API (read-only) is provided to access each of these parts.

  • Field Details

    • parentDb

      private final RrdDb parentDb
      The database the archive belongs to.
    • consolFun

      private final RrdEnum<Archive, ConsolFun> consolFun
      How raw values are consolidated, from the definition.
    • xff

      protected final RrdDouble<Archive> xff
      X-files factor
    • steps

      protected final RrdInt<Archive> steps
      Number of archive steps
    • rows

      protected final RrdInt<Archive> rows
      Number of archive rows
    • robins

      private final Robin[] robins
      The stored values, one ring per data source.
    • states

      private final ArcState[] states
      Consolidation state, one per data source.
  • Constructor Details

    • Archive

      Archive(RrdDb parentDb, ArcDef arcDef) throws IOException
      Create an archive with the given definition.
      Parameters:
      parentDb - the parent RRD database
      arcDef - archive definition, or null for uninitialized
      Throws:
      IOException - if an I/O error occurs
    • Archive

      Archive(RrdDb parentDb, DataImporter reader, int arcIndex) throws IOException
      Create an archive by importing from XML data.
      Parameters:
      parentDb - the parent RRD database
      reader - data importer for XML restore
      arcIndex - which archive definition in the XML to import
      Throws:
      IOException - if an I/O error occurs
  • Method Details

    • getArcStep

      public long getArcStep() throws IOException
      Returns archive time step in seconds. Archive step is equal to RRD step multiplied with the number of archive steps.
      Returns:
      Archive time step in seconds
      Throws:
      IOException - Thrown in case of I/O error.
    • dump

      String dump() throws IOException
      Returns a string representation of the archive information.
      Returns:
      a string containing archive information
      Throws:
      IOException - if an I/O error occurs
    • getParentDb

      RrdDb getParentDb()
      Returns the parent RRD database.
      Returns:
      the parent RRD database
    • archive

      void archive(int dsIndex, double value, long numUpdates) throws IOException
      Archives a value for the specified datasource.
      Parameters:
      dsIndex - index of the datasource
      value - value to archive
      numUpdates - number of updates to perform
      Throws:
      IOException - if an I/O error occurs
    • accumulate

      private void accumulate(ArcState state, double value) throws IOException
      Folds one sample into the archive's state.
      Parameters:
      state - the state to update
      value - the sample's value
      Throws:
      IOException - if the state cannot be written
    • finalizeStep

      private void finalizeStep(ArcState state, Robin robin) throws IOException
      Writes the consolidated value at the end of a step.
      Parameters:
      state - the state to consolidate
      robin - where the value is stored
      Throws:
      IOException - if the value cannot be written
    • getConsolFun

      public ConsolFun getConsolFun() throws IOException
      Returns archive consolidation function ("AVERAGE", "MIN", "MAX", "FIRST", "LAST" or "TOTAL").
      Returns:
      Archive consolidation function.
      Throws:
      IOException - Thrown in case of I/O error.
    • getXff

      public double getXff() throws IOException
      Returns archive X-files factor.
      Returns:
      Archive X-files factor (between 0 and 1).
      Throws:
      IOException - Thrown in case of I/O error.
    • getSteps

      public int getSteps() throws IOException
      Returns the number of archive steps.
      Returns:
      Number of archive steps.
      Throws:
      IOException - Thrown in case of I/O error.
    • getRows

      public int getRows() throws IOException
      Returns the number of archive rows.
      Returns:
      Number of archive rows.
      Throws:
      IOException - Thrown in case of I/O error.
    • getStartTime

      public long getStartTime() throws IOException
      Returns current starting timestamp. This value is not constant.
      Returns:
      Timestamp corresponding to the first archive row
      Throws:
      IOException - Thrown in case of I/O error.
    • getEndTime

      public long getEndTime() throws IOException
      Returns current ending timestamp. This value is not constant.
      Returns:
      Timestamp corresponding to the last archive row
      Throws:
      IOException - Thrown in case of I/O error.
    • getArcState

      public ArcState getArcState(int dsIndex)
      Returns the underlying archive state object. Each datasource has its corresponding ArcState object (archive states are managed independently for each RRD datasource).
      Parameters:
      dsIndex - which datasource's archive state to return
      Returns:
      Underlying archive state object
    • getRobin

      public Robin getRobin(int dsIndex)
      Returns the underlying round robin archive. Robins are used to store actual archive values on a per-datasource basis.
      Parameters:
      dsIndex - Index of the datasource in the RRD.
      Returns:
      Underlying round robin archive for the given datasource.
    • fetchData

      FetchData fetchData(FetchRequest request) throws IOException
      Fetch data from the archive.
      Parameters:
      request - the fetch request
      Returns:
      fetch data result
      Throws:
      IOException - if an I/O error occurs
    • appendXml

      void appendXml(XmlWriter writer) throws IOException
      Append the archive data as XML.
      Parameters:
      writer - the XML writer
      Throws:
      IOException - if an I/O error occurs
    • copyStateTo

      public void copyStateTo(Archive arc) throws IOException

      Copies object's internal state to another Archive object.

      Specified by:
      copyStateTo in interface RrdUpdater<Archive>
      Parameters:
      arc - a RrdUpdater object.
      Throws:
      IOException - if the state cannot be read from the backend
    • setXff

      public void setXff(double xff) throws IOException
      Sets X-files factor to a new value.
      Parameters:
      xff - New X-files factor value. Must be >= 0 and < 1.
      Throws:
      IOException - Thrown in case of I/O error
    • getRrdBackend

      public RrdBackend getRrdBackend()
      Returns the underlying storage (backend) object which actually performs all I/O operations.
      Specified by:
      getRrdBackend in interface RrdUpdater<Archive>
      Returns:
      I/O backend object
    • getRrdAllocator

      public RrdAllocator getRrdAllocator()
      Required to implement RrdUpdater interface. You should never call this method directly.
      Specified by:
      getRrdAllocator in interface RrdUpdater<Archive>
      Returns:
      Allocator object