Class MetricStreamJoiner

  • All Implemented Interfaces:
    com.elastisys.autoscaler.core.api.Configurable<MetricStreamJoinerConfig>, com.elastisys.autoscaler.core.api.Service<MetricStreamJoinerConfig>, com.elastisys.autoscaler.core.monitoring.metricstreamer.api.MetricStreamer<MetricStreamJoinerConfig>

    public class MetricStreamJoiner
    extends java.lang.Object
    implements com.elastisys.autoscaler.core.monitoring.metricstreamer.api.MetricStreamer<MetricStreamJoinerConfig>
    A MetricStreamJoiner is a "meta metric streamer", which consumes one or more metric streams and produces a single new metric stream by applying a join script to the consumed stream values. The `MetricStreamJoiner`'s operation can be illustrated by the following schematical image:

     
     MetricStream a -> |
                       |
     MetricStream b -> | MetricStreamJoiner d: joinScript(${a}, ${b}, ${c})
                       |
     MetricStream c -> |
     
     
    MetricStreamJoiner listens for values from existing MetricStreams `a`, `b`, `c` and whenever a new value is received from either stream (and at least one value has been observed on every stream and their timestamps are within `maxTimeDifference` distance of each other) the joiner stream `d` produces a new metric value being its "join function" applied to the most recently observed value from every stream.

    The `joinScript` can be an arbitrary JavaScript expression like

     
       a + b + c
     
     
    or
     
       if (a + b > c) {
         a + b;
       } else {
         c;
       }
     
     
    The only requirement that the `joinScript` must satisfy is that the end result of executing the last script statement/expression must be a single numerical value.
    • Constructor Detail

      • MetricStreamJoiner

        @Inject
        public MetricStreamJoiner​(org.slf4j.Logger logger,
                                  com.elastisys.scale.commons.eventbus.EventBus eventBus,
                                  java.util.List<com.elastisys.autoscaler.core.monitoring.metricstreamer.api.MetricStreamer<?>> priorDeclaredMetricStreamers)
        Parameters:
        logger - Logger instance.
        eventBus - EventBus on which to listen for metrics.
        priorDeclaredMetricStreamers - The list of MetricStreamers declared prior to this MetricStreamer and which can be used as references in input streams. May be null, which is interpreted as an empty list.
    • Method Detail

      • validate

        public void validate​(MetricStreamJoinerConfig configuration)
                      throws java.lang.IllegalArgumentException
        Specified by:
        validate in interface com.elastisys.autoscaler.core.api.Configurable<MetricStreamJoinerConfig>
        Throws:
        java.lang.IllegalArgumentException
      • configure

        public void configure​(MetricStreamJoinerConfig newConfig)
                       throws java.lang.IllegalArgumentException
        Specified by:
        configure in interface com.elastisys.autoscaler.core.api.Configurable<MetricStreamJoinerConfig>
        Throws:
        java.lang.IllegalArgumentException
      • start

        public void start()
                   throws java.lang.IllegalStateException
        Specified by:
        start in interface com.elastisys.autoscaler.core.api.Service<MetricStreamJoinerConfig>
        Throws:
        java.lang.IllegalStateException
      • stop

        public void stop()
        Specified by:
        stop in interface com.elastisys.autoscaler.core.api.Service<MetricStreamJoinerConfig>
      • getStatus

        public com.elastisys.autoscaler.core.api.types.ServiceStatus getStatus()
        Specified by:
        getStatus in interface com.elastisys.autoscaler.core.api.Service<MetricStreamJoinerConfig>
      • getMetricStreams

        public java.util.List<com.elastisys.autoscaler.core.monitoring.metricstreamer.api.MetricStream> getMetricStreams()
        Specified by:
        getMetricStreams in interface com.elastisys.autoscaler.core.monitoring.metricstreamer.api.MetricStreamer<MetricStreamJoinerConfig>
      • getMetricStream

        public com.elastisys.autoscaler.core.monitoring.metricstreamer.api.MetricStream getMetricStream​(java.lang.String id)
                                                                                                 throws java.lang.IllegalArgumentException
        Specified by:
        getMetricStream in interface com.elastisys.autoscaler.core.monitoring.metricstreamer.api.MetricStreamer<MetricStreamJoinerConfig>
        Throws:
        java.lang.IllegalArgumentException
      • fetch

        public void fetch()
                   throws com.elastisys.autoscaler.core.monitoring.metricstreamer.api.MetricStreamException,
                          java.lang.IllegalStateException
        Specified by:
        fetch in interface com.elastisys.autoscaler.core.monitoring.metricstreamer.api.MetricStreamer<MetricStreamJoinerConfig>
        Throws:
        com.elastisys.autoscaler.core.monitoring.metricstreamer.api.MetricStreamException
        java.lang.IllegalStateException