org.opennms.netmgt.rrd.rrdtool
Class JniRrdStrategy

java.lang.Object
  extended by org.opennms.netmgt.rrd.rrdtool.JniRrdStrategy
All Implemented Interfaces:
RrdStrategy<String,StringBuffer>

public class JniRrdStrategy
extends Object
implements RrdStrategy<String,StringBuffer>

Provides an rrdtool based implementation of RrdStrategy. It uses the existing JNI based single-threaded interface to write the rrdtool compatibile RRD files. The JNI interface takes command-like arguments and doesn't provide open files so the the Objects used to represent open files are really partial command strings See the individual methods for more details

Version:
$Id: $
Author:
ranger

Constructor Summary
JniRrdStrategy()
          Initialized the JNI Interface
 
Method Summary
 void closeFile(StringBuffer rrd)
          The 'closes' the rrd file.
 String createDefinition(String creator, String directory, String rrdName, int step, List<RrdDataSource> dataSources, List<String> rraList)
          Create a round robin database definition from the supplied parameters.
 void createFile(String rrdDef)
          Creates a the rrd file from the rrdDefinition.
 InputStream createGraph(String command, File workDir)
          Creates an InputStream representing the bytes of a graph created from round robin data.
 RrdGraphDetails createGraphReturnDetails(String command, File workDir)
          Creates an RrdGraphDetails object representing the graph created from round robin data.
 Double fetchLastValue(String rrdFile, String ds, int interval)
          Fetches the last value from the round robin database with the given name.
 Double fetchLastValue(String rrdFile, String ds, String consolidationFunction, int interval)
          Fetches the last value from the round robin database with the given name.
 Double fetchLastValueInRange(String rrdFile, String ds, int interval, int range)
          Fetches the last value from the round robin database with the given name within a time range.
 Properties getConfigurationProperties()
          getConfigurationProperties
 String getDefaultFileExtension()
          getDefaultFileExtension
 int getGraphLeftOffset()
          getGraphLeftOffset
 int getGraphRightOffset()
          getGraphRightOffset
 int getGraphTopOffsetWithText()
          getGraphTopOffsetWithText
 String getStats()
          No stats are kept for this implementation.
 ThreadCategory log()
          log
 StringBuffer openFile(String fileName)
          Opens the round robin database with the supplied name.
 void promoteEnqueuedFiles(Collection<String> rrdFiles)
          In the event that this is a queuing implementation of the RrdStrategy.
 void setConfigurationProperties(Properties configurationParameters)
          setConfigurationProperties
 void updateFile(StringBuffer rrd, String owner, String data)
          Updates the supplied round robin database with the given timestamp:value point
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JniRrdStrategy

public JniRrdStrategy()
               throws Exception
Initialized the JNI Interface

Throws:
Exception - if any.
Method Detail

getConfigurationProperties

public Properties getConfigurationProperties()

getConfigurationProperties

Returns:
a Properties object.

setConfigurationProperties

public void setConfigurationProperties(Properties configurationParameters)

setConfigurationProperties

Specified by:
setConfigurationProperties in interface RrdStrategy<String,StringBuffer>
Parameters:
configurationParameters - a Properties object.

closeFile

public void closeFile(StringBuffer rrd)
               throws Exception
The 'closes' the rrd file. This is where the actual work of writing the RRD files takes place. The passed in rrd is actually an rrd command string containing updates. This method executes this command.

Specified by:
closeFile in interface RrdStrategy<String,StringBuffer>
Parameters:
rrd - a StringBuffer object.
Throws:
Exception - if any.

createDefinition

public String createDefinition(String creator,
                               String directory,
                               String rrdName,
                               int step,
                               List<RrdDataSource> dataSources,
                               List<String> rraList)
                        throws Exception
Create a round robin database definition from the supplied parameters. This definition is used in the createFile call to create the actual file.

Specified by:
createDefinition in interface RrdStrategy<String,StringBuffer>
Parameters:
creator - - A string representing who is creating this file for use in log msgs
directory - - The directory to create the file in
rrdName - - The name to use for the round robin database
step - - the step for the database
dataSources - - the data sources to use for round robin database
rraList - - a List of the round robin archives to create in the database
Returns:
an object representing the definition of an round robin database
Throws:
Exception - If an error occurs while creating the definition

createFile

public void createFile(String rrdDef)
                throws Exception
Creates a the rrd file from the rrdDefinition. Since this definition is really just the create command string it just executes it.

Specified by:
createFile in interface RrdStrategy<String,StringBuffer>
Parameters:
rrdDef - a String object.
Throws:
Exception - if any.

openFile

public StringBuffer openFile(String fileName)
                      throws Exception
Opens the round robin database with the supplied name. It is assumed the name refers to a round robin database appropriate for this strategy implementation The 'opens' the given rrd file. In actuality since the JNI interface does not provide files that may be open, this constructs the beginning portion of the rrd command to update the file.

Specified by:
openFile in interface RrdStrategy<String,StringBuffer>
Parameters:
fileName - the name of the associated rrd file
Returns:
an open rrd reference that can by used in calls to updateFile and closeFile
Throws:
Exception - if an error occurs opening the file

updateFile

public void updateFile(StringBuffer rrd,
                       String owner,
                       String data)
                throws Exception
Updates the supplied round robin database with the given timestamp:value point This 'updates' the given rrd file by providing data. Since the JNI interface does not provide files that can be open, this just appends the data to the command string constructed so far. The data is not immediately written to the file since this would eliminate the possibility of getting performance benefit by doing more than one write per open. The updates are all performed at once in the closeFile method.

Specified by:
updateFile in interface RrdStrategy<String,StringBuffer>
Parameters:
rrd - an rrd object created using openFile
owner - the owner of the rrd
data - a string of the form :
Throws:
Exception - if an error occurs updating the file

fetchLastValue

public Double fetchLastValue(String rrdFile,
                             String ds,
                             int interval)
                      throws NumberFormatException,
                             RrdException
Fetches the last value from the round robin database with the given name. The interval passed in should be the interval associated with the round robin database. Fetches the last value directly from the rrd file using the JNI Interface.

Specified by:
fetchLastValue in interface RrdStrategy<String,StringBuffer>
Parameters:
rrdFile - a name the represents a round robin database
ds - a name the represents a data source to be used
interval - a step interval of the round robin database
Returns:
The last value as a Double (if the last value didn't exist returns a Double.NaN)
Throws:
NumberFormatException - if any.
RrdException - if any.

fetchLastValue

public Double fetchLastValue(String rrdFile,
                             String ds,
                             String consolidationFunction,
                             int interval)
Fetches the last value from the round robin database with the given name. The interval passed in should be the interval associated with the round robin database.

Specified by:
fetchLastValue in interface RrdStrategy<String,StringBuffer>
Parameters:
rrdFile - a name the represents a round robin database
ds - a name the represents a data source to be used
consolidationFunction - a String object.
interval - a step interval of the round robin database
Returns:
The last value as a Double (if the last value didn't exist returns a Double.NaN)

fetchLastValueInRange

public Double fetchLastValueInRange(String rrdFile,
                                    String ds,
                                    int interval,
                                    int range)
                             throws NumberFormatException,
                                    RrdException
Fetches the last value from the round robin database with the given name within a time range. The interval passed in should be the interval associated with the round robin database. The range should be the amount of "lag" acceptable for an update to be considered valid. Range must be a multiple of the RRD interval.

Specified by:
fetchLastValueInRange in interface RrdStrategy<String,StringBuffer>
Parameters:
rrdFile - a name the represents a round robin database
ds - a name the represents a data source to be used
interval - a step interval of the round robin database
range - an acceptable range for which the last value will be returned
Returns:
The last value as a Double (if the last value didn't exist returns a Double.NaN)
Throws:
NumberFormatException - if any.
RrdException - if any.

createGraph

public 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 . Executes the given graph command as process with workDir as the current directory. The output stream of the command (a PNG image) is copied to a the InputStream returned from the method.

Specified by:
createGraph in interface RrdStrategy<String,StringBuffer>
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

getStats

public String getStats()
No stats are kept for this implementation.

Specified by:
getStats in interface RrdStrategy<String,StringBuffer>
Returns:
a String object.

log

public ThreadCategory log()

log

Returns:
a ThreadCategory object.

getGraphLeftOffset

public int getGraphLeftOffset()

getGraphLeftOffset

Specified by:
getGraphLeftOffset in interface RrdStrategy<String,StringBuffer>
Returns:
a int.

getGraphRightOffset

public int getGraphRightOffset()

getGraphRightOffset

Specified by:
getGraphRightOffset in interface RrdStrategy<String,StringBuffer>
Returns:
a int.

getGraphTopOffsetWithText

public int getGraphTopOffsetWithText()

getGraphTopOffsetWithText

Specified by:
getGraphTopOffsetWithText in interface RrdStrategy<String,StringBuffer>
Returns:
a int.

getDefaultFileExtension

public String getDefaultFileExtension()

getDefaultFileExtension

Specified by:
getDefaultFileExtension in interface RrdStrategy<String,StringBuffer>
Returns:
a String object.

createGraphReturnDetails

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

Specified by:
createGraphReturnDetails in interface RrdStrategy<String,StringBuffer>
Parameters:
command - the command needed to create the graph
workDir - the directory that all referenced files are relative to
Returns:
details for the graph including an InputStream, any PRINTed lines, and graph dimensions.
Throws:
IOException - if an IOError occurs
RrdException - if an RRD error occurs

promoteEnqueuedFiles

public void promoteEnqueuedFiles(Collection<String> rrdFiles)
In the event that this is a queuing implementation of the RrdStrategy. This method causes all queued but not yet written data to be to the rrd files as soon as possible.

Specified by:
promoteEnqueuedFiles in interface RrdStrategy<String,StringBuffer>
Parameters:
rrdFiles - a Collection object.


Copyright © 2011. All Rights Reserved.