Class MetricStreamDefinition


  • public class MetricStreamDefinition
    extends java.lang.Object
    Describes a MetricStream published by the MetricStreamJoiner. More specifically, it declares a set of input metric streams to be consumed and a join-function used to produce output values for the joined metric stream.
    See Also:
    MetricStreamJoinerConfig
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static com.elastisys.scale.commons.json.types.TimeInterval DEFAULT_MAX_TIME_DIFF  
    • Constructor Summary

      Constructors 
      Constructor Description
      MetricStreamDefinition​(java.lang.String id, java.lang.String metric, java.util.Map<java.lang.String,​java.lang.String> inputStreams, com.elastisys.scale.commons.json.types.TimeInterval maxTimeDiff, java.util.List<java.lang.String> joinScript)
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      javax.script.CompiledScript getCompiledJoinScript()
      Returns the joinScript as a compiled a JavaScript.
      java.lang.String getId()
      The id of the metric stream.
      java.util.Map<java.lang.String,​java.lang.String> getInputStreams()
      Declares the input metric streams that are to be joined by this metric stream.
      java.lang.String getJoinScript()
      A JavaScript for the join function.
      com.elastisys.scale.commons.json.types.TimeInterval getMaxTimeDiff()
      The maximum difference in time between observed metric stream values for the joined metric stream to apply its joinScript and produce a new value.
      java.lang.String getMetric()
      The name of the metric produced by this metric stream.
      int hashCode()  
      java.lang.String toString()  
      void validate()  
      static void validJavaScriptIdentifier​(java.lang.String identifier)
      Checks that an identifier is a valid JavaScript identifier.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEFAULT_MAX_TIME_DIFF

        public static final com.elastisys.scale.commons.json.types.TimeInterval DEFAULT_MAX_TIME_DIFF
    • Constructor Detail

      • MetricStreamDefinition

        public MetricStreamDefinition​(java.lang.String id,
                                      java.lang.String metric,
                                      java.util.Map<java.lang.String,​java.lang.String> inputStreams,
                                      com.elastisys.scale.commons.json.types.TimeInterval maxTimeDiff,
                                      java.util.List<java.lang.String> joinScript)
        Parameters:
        id - The id of the metric stream. This is the id that will be used by clients wishing to subscribe to this metric stream. Required.
        metric - The name of the metric produced by this metric stream. This is the metric that will be set for produced MetricValues. Optional. If left out, id is used.
        inputStreams - Declares the input metric streams that are to be joined by this metric stream. Keys are metric stream aliases and values are metric stream identifiers. The referenced metric streams must have been declared prior to this metric stream (note that this can be another joined metric stream). A metric stream alias needs to be a valid JavaScript identifier name, as these will be passed as variables to the joinScript. Required.
        maxTimeDiff - The maximum difference in time between observed metric stream values for the joined metric stream to apply its joinScript and produce a new value. If stream metrics are farther apart than this, no new metric value is produced on the joined stream. This value should be set so that values that are close enough to be considered relevant to each other can be joined. The default is 0 s, assuming that the input metric streams are scraped at the same instant. May be null.
        joinScript - An array of JavaScript code lines for the join function. The final statement/expression that the script executes must be a numerical value. The script can assume that, when executed, each of the metric stream aliases defined in the inputStreams section will be assigned a Number value. Required.
    • Method Detail

      • getId

        public java.lang.String getId()
        The id of the metric stream. This is the id that will be used by clients wishing to subscribe to this metric stream.
        Returns:
      • getMetric

        public java.lang.String getMetric()
        The name of the metric produced by this metric stream. This is the metric that will be set for produced MetricValues.
        Returns:
      • getInputStreams

        public java.util.Map<java.lang.String,​java.lang.String> getInputStreams()
        Declares the input metric streams that are to be joined by this metric stream. Keys are metric stream aliases and values are metric stream identifiers. The referenced metric streams must have been declared prior to this metric stream (note that this can be another joined metric stream). A metric stream alias needs to be a valid JavaScript identifier name, as these will be passed as variables to the joinScript.
        Returns:
      • getMaxTimeDiff

        public com.elastisys.scale.commons.json.types.TimeInterval getMaxTimeDiff()
        The maximum difference in time between observed metric stream values for the joined metric stream to apply its joinScript and produce a new value. If stream metrics are farther apart than this, no new metric value is produced on the joined stream. This value should be set so that values that are close enough to be considered relevant to each other can be joined.
        Returns:
      • getJoinScript

        public java.lang.String getJoinScript()
        A JavaScript for the join function. The final statement/expression that the script executes must be a numerical value. The script can assume that, when executed, each of the metric stream aliases defined in the inputStreams section will be assigned a Number value.
        Returns:
      • getCompiledJoinScript

        public javax.script.CompiledScript getCompiledJoinScript()
                                                          throws java.lang.IllegalArgumentException
        Returns the joinScript as a compiled a JavaScript. If invalid, an IllegalArgumentException is thrown.
        Parameters:
        javascript -
        Throws:
        java.lang.IllegalArgumentException
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • validate

        public void validate()
                      throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
      • validJavaScriptIdentifier

        public static void validJavaScriptIdentifier​(java.lang.String identifier)
                                              throws java.lang.IllegalArgumentException
        Checks that an identifier is a valid JavaScript identifier. Throws an IllegalArgumentException if it isn't.
        Parameters:
        identifier -
        Throws:
        java.lang.IllegalArgumentException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object