Package org.opennms.netmgt.rrd.tcp
Class QueuingTcpRrdStrategy
- java.lang.Object
-
- org.opennms.netmgt.rrd.tcp.QueuingTcpRrdStrategy
-
- All Implemented Interfaces:
RrdStrategy<TcpRrdStrategy.RrdDefinition,String>
public class QueuingTcpRrdStrategy extends Object implements RrdStrategy<TcpRrdStrategy.RrdDefinition,String>
Provides a TCP socket-based implementation of RrdStrategy that pushes update commands out in a simple serialized format.The receiver of this strategy is not defined in any way. This is just a fire and forget strategy. There is no way to read data back into opennms.
- Version:
- $Id: $
- Author:
- ranger
-
-
Constructor Summary
Constructors Constructor Description QueuingTcpRrdStrategy(TcpRrdStrategy delegate, int queueSize)
Constructor for QueuingTcpRrdStrategy.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
closeFile(String rrd)
closeFileTcpRrdStrategy.RrdDefinition
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(TcpRrdStrategy.RrdDefinition rrdDef)
createFileInputStream
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.String
getDefaultFileExtension()
getDefaultFileExtensionint
getGraphLeftOffset()
getGraphLeftOffsetint
getGraphRightOffset()
getGraphRightOffsetint
getGraphTopOffsetWithText()
getGraphTopOffsetWithTextString
getStats()
getStatsString
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)
setConfigurationPropertiesvoid
updateFile(String fileName, String owner, String data)
Updates the supplied round robin database with the given timestamp:value point
-
-
-
Constructor Detail
-
QueuingTcpRrdStrategy
public QueuingTcpRrdStrategy(TcpRrdStrategy delegate, int queueSize)
Constructor for QueuingTcpRrdStrategy.
- Parameters:
delegate
- aTcpRrdStrategy
object.
-
-
Method Detail
-
setConfigurationProperties
public void setConfigurationProperties(Properties configurationParameters)
setConfigurationProperties
- Specified by:
setConfigurationProperties
in interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Parameters:
configurationParameters
- aProperties
object.
-
getDefaultFileExtension
public String getDefaultFileExtension()
getDefaultFileExtension
- Specified by:
getDefaultFileExtension
in interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Returns:
- a
String
object.
-
createDefinition
public TcpRrdStrategy.RrdDefinition 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 interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Parameters:
creator
- - A string representing who is creating this file for use in log msgsdirectory
- - The directory to create the file inrrdName
- - The name to use for the round robin databasestep
- - the step for the databasedataSources
- - the data sources to use for round robin databaserraList
- - a List of the round robin archives to create in the database. defines after which time the data is condensed to a defined lower step- Returns:
- an object representing the definition of an round robin database. Can be null if the database exists already.
- Throws:
Exception
- If an error occurs while creating the definition
-
createFile
public void createFile(TcpRrdStrategy.RrdDefinition rrdDef) throws Exception
createFile
- Specified by:
createFile
in interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Parameters:
rrdDef
- aTcpRrdStrategy.RrdDefinition
object.- Throws:
Exception
- if any.
-
openFile
public String 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- Specified by:
openFile
in interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- 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(String fileName, String owner, String data) throws Exception
Updates the supplied round robin database with the given timestamp:value point- Specified by:
updateFile
in interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Parameters:
fileName
- an rrd object created using openFileowner
- the owner of the rrddata
- a string of the form: - Throws:
Exception
- if an error occurs updating the file
-
closeFile
public void closeFile(String rrd) throws Exception
closeFile
- Specified by:
closeFile
in interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Parameters:
rrd
- aString
object.- Throws:
Exception
- if any.
-
fetchLastValue
public Double fetchLastValue(String rrdFile, String ds, int interval) throws NumberFormatException
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 interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Parameters:
rrdFile
- a name the represents a round robin databaseds
- a name the represents a data source to be usedinterval
- 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.
-
fetchLastValue
public Double fetchLastValue(String rrdFile, String ds, String consolidationFunction, int interval) throws NumberFormatException
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 interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Parameters:
rrdFile
- a name the represents a round robin databaseds
- a name the represents a data source to be usedconsolidationFunction
- aString
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)
- Throws:
NumberFormatException
- if any.
-
fetchLastValueInRange
public Double fetchLastValueInRange(String rrdFile, String ds, int interval, int range) throws NumberFormatException
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 interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Parameters:
rrdFile
- a name the represents a round robin databaseds
- a name the represents a data source to be usedinterval
- a step interval of the round robin databaserange
- 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.
-
createGraph
public InputStream createGraph(String command, File workDir) throws IOException
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 .- Specified by:
createGraph
in interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Parameters:
command
- the command needed to create the graphworkDir
- 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
-
createGraphReturnDetails
public RrdGraphDetails createGraphReturnDetails(String command, File workDir) throws IOException
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 interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Parameters:
command
- the command needed to create the graphworkDir
- 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
-
getGraphLeftOffset
public int getGraphLeftOffset()
getGraphLeftOffset
- Specified by:
getGraphLeftOffset
in interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Returns:
- a int.
-
getGraphRightOffset
public int getGraphRightOffset()
getGraphRightOffset
- Specified by:
getGraphRightOffset
in interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Returns:
- a int.
-
getGraphTopOffsetWithText
public int getGraphTopOffsetWithText()
getGraphTopOffsetWithText
- Specified by:
getGraphTopOffsetWithText
in interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Returns:
- a int.
-
getStats
public String getStats()
getStats
- Specified by:
getStats
in interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Returns:
- a
String
object.
-
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 interfaceRrdStrategy<TcpRrdStrategy.RrdDefinition,String>
- Parameters:
rrdFiles
- aCollection
object.
-
-