org.opennms.netmgt.rrd
Class RrdUtils

java.lang.Object
  extended by org.opennms.netmgt.rrd.RrdUtils

public abstract class RrdUtils
extends Object

Provides static methods for interacting with round robin files. Supports JNI and JRobin based files and provides queuing for managing differences in collection speed and disk write speed. This behaviour is implemented using the Strategy pattern with a different RrdStrategy for JRobin and JNI as well as a Strategy that provides Queueing on top of either one. The following System properties select which strategy is in use.


  org.opennms.rrd.usejni: (defaults to true)
   true - use the existing RRDTool code via the JNI interface @see JniRrdStrategy
   false - use the pure java JRobin interface @see JRobinRrdStrategy

  org.opennms.rrd.usequeue: (defaults to true)
    use the queueing that allows collection to occur even though the disks are
    keeping up. @see QueuingRrdStrategy


 

Version:
$Id: $
Author:
ranger

Nested Class Summary
static class RrdUtils.StrategyName
           
 
Constructor Summary
RrdUtils()
           
 
Method Summary
static InputStream createGraph(String command, File workDir)
          Creates an InputStream representing the bytes of a graph created from round robin data.
static boolean createRRD(String creator, String directory, String rrdName, int step, List<RrdDataSource> dataSources, List<String> rraList)
          createRRD
static boolean createRRD(String creator, String directory, String dsName, int step, String dsType, int dsHeartbeat, String dsMin, String dsMax, List<String> rraList)
          Create a round robin database file.
static Double fetchLastValue(String rrdFile, String ds, int interval)
          This method issues an round robin fetch command to retrieve the last value of the datasource stored in the specified RRD file.
static Double fetchLastValueInRange(String rrdFile, String ds, int interval, int range)
          This method issues an round robing fetch command to retrieve the last value of the datasource stored in the specified RRD file within given tolerance (which should be a multiple of the RRD interval).
static String getExtension()
          getExtension
static RrdStrategy getSpecificStrategy(RrdUtils.StrategyName strategy)
          getSpecificStrategy
static RrdStrategy getStrategy()
          getStrategy
static void promoteEnqueuedFiles(Collection<String> files)
          promoteEnqueuedFiles
static void setStrategy(RrdStrategy strategy)
          setStrategy
static void updateRRD(String owner, String repositoryDir, String rrdName, long timestamp, String val)
          Add datapoints to a round robin database.
static void updateRRD(String owner, String repositoryDir, String rrdName, String val)
          Add datapoints to a round robin database using the current system time as the timestamp for the values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RrdUtils

public RrdUtils()
Method Detail

getStrategy

public static RrdStrategy getStrategy()

getStrategy

Returns:
a RrdStrategy object.

getSpecificStrategy

public static RrdStrategy getSpecificStrategy(RrdUtils.StrategyName strategy)

getSpecificStrategy

Parameters:
strategy - a RrdUtils.StrategyName object.
Returns:
a RrdStrategy object.

setStrategy

public static void setStrategy(RrdStrategy strategy)

setStrategy

Parameters:
strategy - a RrdStrategy object.

createRRD

public static boolean createRRD(String creator,
                                String directory,
                                String dsName,
                                int step,
                                String dsType,
                                int dsHeartbeat,
                                String dsMin,
                                String dsMax,
                                List<String> rraList)
                         throws RrdException
Create a round robin database file. See the man page for rrdtool create for definitions of each of these.

Parameters:
creator - - A string representing who is creating this file for use in log msgs
directory - - The directory to create the file in
dsName - - The datasource name for use in the round robin database
step - - the step for the database
dsType - - the type for the datasource
dsHeartbeat - - the heartbeat for the datasouce
dsMin - - the minimum allowable value for the datasource
dsMax - - the maximum allowable value for the datasouce
rraList - - a List of the round robin archives to create in the database
Returns:
true if the file was actually created, false otherwise
Throws:
RrdException - if any.

createRRD

public static boolean createRRD(String creator,
                                String directory,
                                String rrdName,
                                int step,
                                List<RrdDataSource> dataSources,
                                List<String> rraList)
                         throws RrdException

createRRD

Parameters:
creator - a String object.
directory - a String object.
rrdName - a String object.
step - a int.
dataSources - a List object.
rraList - a List object.
Returns:
a boolean.
Throws:
RrdException - if any.

updateRRD

public static void updateRRD(String owner,
                             String repositoryDir,
                             String rrdName,
                             String val)
                      throws RrdException
Add datapoints to a round robin database using the current system time as the timestamp for the values

Parameters:
owner - the owner of the file. This is used in log messages
repositoryDir - the directory the file resides in
rrdName - the name for the rrd file.
val - a colon separated list of values representing the updates for datasources for this rrd
Throws:
RrdException - if any.

updateRRD

public static void updateRRD(String owner,
                             String repositoryDir,
                             String rrdName,
                             long timestamp,
                             String val)
                      throws RrdException
Add datapoints to a round robin database.

Parameters:
owner - the owner of the file. This is used in log messages
repositoryDir - the directory the file resides in
rrdName - the name for the rrd file.
timestamp - the timestamp in millis to use for the rrd update (this gets rounded to the nearest second)
val - a colon separated list of values representing the updates for datasources for this rrd
Throws:
RrdException - if any.

fetchLastValue

public static Double fetchLastValue(String rrdFile,
                                    String ds,
                                    int interval)
                             throws NumberFormatException,
                                    RrdException
This method issues an round robin fetch command to retrieve the last value of the datasource stored in the specified RRD file. The retrieved value returned to the caller. NOTE: This method assumes that each RRD file contains a single datasource.

Parameters:
rrdFile - RRD file from which to fetch the data.
interval - Thresholding interval (should equal RRD step size)
ds - Name of the Data Source to be used
Returns:
Retrived datasource value as a java.lang.Double
Throws:
NumberFormatException - if the retrieved value fails to convert to a double
RrdException - if any.

fetchLastValueInRange

public static Double fetchLastValueInRange(String rrdFile,
                                           String ds,
                                           int interval,
                                           int range)
                                    throws NumberFormatException,
                                           RrdException
This method issues an round robing fetch command to retrieve the last value of the datasource stored in the specified RRD file within given tolerance (which should be a multiple of the RRD interval). This is useful If you are not entirely sure when an RRD might have been updated, but you want to retrieve the last value which is not NaN NOTE: This method assumes that each RRD file contains a single datasource.

Parameters:
rrdFile - RRD file from which to fetch the data.
interval - Thresholding interval (should equal RRD step size)
ds - Name of the Data Source to be used
range - a int.
Returns:
Retrived datasource value as a java.lang.Double
Throws:
NumberFormatException - if the retrieved value fails to convert to a double
RrdException - if any.

createGraph

public static InputStream createGraph(String command,
                                      File workDir)
                               throws IOException,
                                      RrdException
Creates an InputStream representing the bytes of a graph created from round robin data. It accepts an rrdtool graph command. The underlying implementation converts this command to a format appropriate for it .

Parameters:
command - the command needed to create the graph
workDir - the directory that all referenced files are relative to
Returns:
an input stream representing the bytes of a graph image as a PNG file
Throws:
IOException - if an IOError occurs
RrdException - if an RRD error occurs

getExtension

public static String getExtension()

getExtension

Returns:
a String object.

promoteEnqueuedFiles

public static void promoteEnqueuedFiles(Collection<String> files)

promoteEnqueuedFiles

Parameters:
files - a Collection object.


Copyright © 2011. All Rights Reserved.