Class JRobinRrdStrategy

  • All Implemented Interfaces:
    RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>

    public class JRobinRrdStrategy
    extends java.lang.Object
    implements RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
    Provides a JRobin based implementation of RrdStrategy. It uses JRobin 1.4 in FILE mode (NIO is too memory consuming for the large number of files that we open)
    Version:
    $Id: $
    Author:
    ranger
    • Constructor Summary

      Constructors 
      Constructor Description
      JRobinRrdStrategy()
      Initialized the RrdDb to use the FILE factory because the NIO factory uses too much memory for our implementation.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addVdefDs​(org.jrobin.graph.RrdGraphDef graphDef, java.lang.String sourceName, java.lang.String[] rhs, double start, double end, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> defs)  
      void closeFile​(org.jrobin.core.RrdDb rrdFile)
      Closes the JRobin RrdDb.
      org.jrobin.core.RrdDef createDefinition​(java.lang.String creator, java.lang.String directory, java.lang.String rrdName, int step, java.util.List<RrdDataSource> dataSources, java.util.List<java.lang.String> rraList)
      Create a round robin database definition from the supplied parameters.
      void createFile​(org.jrobin.core.RrdDef rrdDef)
      Creates the JRobin RrdDb from the def by opening the file and then closing.
      java.io.InputStream createGraph​(java.lang.String command, java.io.File workDir)
      Creates an InputStream representing the bytes of a graph created from round robin data.
      protected org.jrobin.graph.RrdGraphDef createGraphDef​(java.io.File workDir, java.lang.String[] inputArray)
      createGraphDef
      RrdGraphDetails createGraphReturnDetails​(java.lang.String command, java.io.File workDir)
      Creates an RrdGraphDetails object representing the graph created from round robin data.
      static char[] escapeIfNotPathSepInDEF​(char encountered, char escaped, java.lang.StringBuffer currToken)
      escapeIfNotPathSepInDEF
      java.lang.Double fetchLastValue​(java.lang.String fileName, java.lang.String ds, int interval)
      Fetches the last value from the round robin database with the given name.
      java.lang.Double fetchLastValue​(java.lang.String fileName, java.lang.String ds, java.lang.String consolidationFunction, int interval)
      Fetches the last value from the round robin database with the given name.
      java.lang.Double fetchLastValueInRange​(java.lang.String fileName, java.lang.String ds, int interval, int range)
      Fetches the last value from the round robin database with the given name within a time range.
      java.util.Properties getConfigurationProperties()
      getConfigurationProperties
      java.lang.String getDefaultFileExtension()
      getDefaultFileExtension
      int getGraphLeftOffset()
      getGraphLeftOffset
      int getGraphRightOffset()
      getGraphRightOffset
      int getGraphTopOffsetWithText()
      getGraphTopOffsetWithText
      java.lang.String getStats()
      This implementation does not track any stats.
      org.jrobin.core.RrdDb openFile​(java.lang.String fileName)
      Opens the round robin database with the supplied name.
      void promoteEnqueuedFiles​(java.util.Collection<java.lang.String> rrdFiles)
      In the event that this is a queuing implementation of the RrdStrategy.
      void setConfigurationProperties​(java.util.Properties configurationParameters)
      setConfigurationProperties
      static java.lang.String[] tokenizeWithQuotingAndEscapes​(java.lang.String line, java.lang.String delims, boolean processQuoted)
      tokenizeWithQuotingAndEscapes
      static java.lang.String[] tokenizeWithQuotingAndEscapes​(java.lang.String line, java.lang.String delims, boolean processQuoted, java.lang.String tokens)
      Tokenize a String into an array of Strings.
      void updateFile​(org.jrobin.core.RrdDb rrdFile, java.lang.String owner, java.lang.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

      • JRobinRrdStrategy

        public JRobinRrdStrategy()
                          throws java.lang.Exception
        Initialized the RrdDb to use the FILE factory because the NIO factory uses too much memory for our implementation.
        Throws:
        java.lang.Exception - if any.
    • Method Detail

      • getConfigurationProperties

        public java.util.Properties getConfigurationProperties()

        getConfigurationProperties

        Returns:
        a Properties object.
      • setConfigurationProperties

        public void setConfigurationProperties​(java.util.Properties configurationParameters)

        setConfigurationProperties

        Specified by:
        setConfigurationProperties in interface RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        Parameters:
        configurationParameters - a Properties object.
      • closeFile

        public void closeFile​(org.jrobin.core.RrdDb rrdFile)
                       throws java.lang.Exception
        Closes the JRobin RrdDb.
        Specified by:
        closeFile in interface RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        Parameters:
        rrdFile - a RrdDb object.
        Throws:
        java.lang.Exception - if any.
      • createDefinition

        public org.jrobin.core.RrdDef createDefinition​(java.lang.String creator,
                                                       java.lang.String directory,
                                                       java.lang.String rrdName,
                                                       int step,
                                                       java.util.List<RrdDataSource> dataSources,
                                                       java.util.List<java.lang.String> rraList)
                                                throws java.lang.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<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        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. 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:
        java.lang.Exception - If an error occurs while creating the definition
      • createFile

        public void createFile​(org.jrobin.core.RrdDef rrdDef)
                        throws java.lang.Exception
        Creates the JRobin RrdDb from the def by opening the file and then closing.
        Specified by:
        createFile in interface RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        Parameters:
        rrdDef - a RrdDef object.
        Throws:
        java.lang.Exception - if any.
      • openFile

        public org.jrobin.core.RrdDb openFile​(java.lang.String fileName)
                                       throws java.lang.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 Opens the JRobin RrdDb by name and returns it.
        Specified by:
        openFile in interface RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        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:
        java.lang.Exception - if an error occurs opening the file
      • updateFile

        public void updateFile​(org.jrobin.core.RrdDb rrdFile,
                               java.lang.String owner,
                               java.lang.String data)
                        throws java.lang.Exception
        Updates the supplied round robin database with the given timestamp:value point Creates a sample from the JRobin RrdDb and passes in the data provided.
        Specified by:
        updateFile in interface RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        Parameters:
        rrdFile - an rrd object created using openFile
        owner - the owner of the rrd
        data - a string of the form :
        Throws:
        java.lang.Exception - if an error occurs updating the file
      • fetchLastValue

        public java.lang.Double fetchLastValue​(java.lang.String fileName,
                                               java.lang.String ds,
                                               int interval)
                                        throws java.lang.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. Fetch the last value from the JRobin RrdDb file.
        Specified by:
        fetchLastValue in interface RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        Parameters:
        fileName - 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:
        java.lang.NumberFormatException - if any.
        RrdException - if any.
      • fetchLastValue

        public java.lang.Double fetchLastValue​(java.lang.String fileName,
                                               java.lang.String ds,
                                               java.lang.String consolidationFunction,
                                               int interval)
                                        throws 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.
        Specified by:
        fetchLastValue in interface RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        Parameters:
        fileName - 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)
        Throws:
        RrdException - if any.
      • fetchLastValueInRange

        public java.lang.Double fetchLastValueInRange​(java.lang.String fileName,
                                                      java.lang.String ds,
                                                      int interval,
                                                      int range)
                                               throws java.lang.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<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        Parameters:
        fileName - 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:
        java.lang.NumberFormatException - if any.
        RrdException - if any.
      • createGraph

        public java.io.InputStream createGraph​(java.lang.String command,
                                               java.io.File workDir)
                                        throws java.io.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 .
        Specified by:
        createGraph in interface RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        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:
        java.io.IOException - if an IOError occurs
        RrdException - if an RRD error occurs
      • createGraphReturnDetails

        public RrdGraphDetails createGraphReturnDetails​(java.lang.String command,
                                                        java.io.File workDir)
                                                 throws java.io.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 . This constructs a graphDef by parsing the rrdtool style command and using the values to create the JRobin graphDef. It does not understand the 'AT style' time arguments however. Also there may be some rrdtool parameters that it does not understand. These will be ignored. The graphDef will be used to construct an RrdGraph and a PNG image will be created. An input stream returning the bytes of the PNG image is returned.
        Specified by:
        createGraphReturnDetails in interface RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        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:
        java.io.IOException - if an IOError occurs
        RrdException - if an RRD error occurs
      • promoteEnqueuedFiles

        public void promoteEnqueuedFiles​(java.util.Collection<java.lang.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<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        Parameters:
        rrdFiles - a Collection object.
      • createGraphDef

        protected org.jrobin.graph.RrdGraphDef createGraphDef​(java.io.File workDir,
                                                              java.lang.String[] inputArray)
                                                       throws org.jrobin.core.RrdException

        createGraphDef

        Parameters:
        workDir - a File object.
        commandArray - an array of String objects.
        Returns:
        a RrdGraphDef object.
        Throws:
        org.jrobin.core.RrdException - if any.
      • getStats

        public java.lang.String getStats()
        This implementation does not track any stats.
        Specified by:
        getStats in interface RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        Returns:
        a String object.
      • getGraphLeftOffset

        public int getGraphLeftOffset()

        getGraphLeftOffset

        Specified by:
        getGraphLeftOffset in interface RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        Returns:
        a int.
      • getGraphRightOffset

        public int getGraphRightOffset()

        getGraphRightOffset

        Specified by:
        getGraphRightOffset in interface RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        Returns:
        a int.
      • getGraphTopOffsetWithText

        public int getGraphTopOffsetWithText()

        getGraphTopOffsetWithText

        Specified by:
        getGraphTopOffsetWithText in interface RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        Returns:
        a int.
      • getDefaultFileExtension

        public java.lang.String getDefaultFileExtension()

        getDefaultFileExtension

        Specified by:
        getDefaultFileExtension in interface RrdStrategy<org.jrobin.core.RrdDef,​org.jrobin.core.RrdDb>
        Returns:
        a String object.
      • tokenizeWithQuotingAndEscapes

        public static java.lang.String[] tokenizeWithQuotingAndEscapes​(java.lang.String line,
                                                                       java.lang.String delims,
                                                                       boolean processQuoted)

        tokenizeWithQuotingAndEscapes

        Parameters:
        line - a String object.
        delims - a String object.
        processQuoted - a boolean.
        Returns:
        an array of String objects.
      • tokenizeWithQuotingAndEscapes

        public static java.lang.String[] tokenizeWithQuotingAndEscapes​(java.lang.String line,
                                                                       java.lang.String delims,
                                                                       boolean processQuoted,
                                                                       java.lang.String tokens)
        Tokenize a String into an array of Strings.
        Parameters:
        line - the string to tokenize
        delims - a string containing zero or more characters to treat as a delimiter
        processQuoted - whether or not to process escaped values inside quotes
        tokens - custom escaped tokens to pass through, escaped. For example, if tokens contains "lsg", then \l, \s, and \g will be passed through unescaped.
        Returns:
        an array of String objects.
      • escapeIfNotPathSepInDEF

        public static char[] escapeIfNotPathSepInDEF​(char encountered,
                                                     char escaped,
                                                     java.lang.StringBuffer currToken)

        escapeIfNotPathSepInDEF

        Parameters:
        encountered - a char.
        escaped - a char.
        currToken - a StringBuffer object.
        Returns:
        an array of char.
      • addVdefDs

        protected void addVdefDs​(org.jrobin.graph.RrdGraphDef graphDef,
                                 java.lang.String sourceName,
                                 java.lang.String[] rhs,
                                 double start,
                                 double end,
                                 java.util.Map<java.lang.String,​java.util.List<java.lang.String>> defs)
                          throws org.jrobin.core.RrdException
        Throws:
        org.jrobin.core.RrdException