Class MemoryMonitor

  • All Implemented Interfaces:
    AdditionalInformationHandler, CleanUpHandler, Destroyable, GlobalInfoSupporter, LoggingLevelHandler, LoggingSupporter, OptionHandler, QuickInfoSupporter, ShallowCopySupporter<Actor>, SizeOfHandler, Stoppable, StoppableWithFeedback, VariablesInspectionHandler, VariableChangeListener, Actor, ErrorHandler, Serializable, Comparable

    public class MemoryMonitor
    extends AbstractStandalone
    Monitors the memory (used/committed heap vs maximum heap).Every number of seconds ('sampleInterval'), the memory consumption, i.e., 'heap used', is sampled, keeping the specified number of latest samples ('numSamples').
    Once the specified number of samples have been reached, it is checked whether the specified percentage of samples ('coverage') reaches or exceeds the threshold percentage of the maximum heap has been exceeded ('threshold'). If that should be the case, a notification is sent.
    After a notification has been sent out, a minimum wait time in seconds is imposed before sending out another one ('notificationWait').
    Also skips coverage tests, if the number if samples reaching/exceeding the threshold is in decline.
    Available placeholders for the message template:
    - {threshold_perc}: user-provided parameter
    - {threshold_bytes}: calculated bytes
    - {num_samples}: user-provided parameter
    - {coverage_perc}: user-provided parameter
    - {coverage_num}: calculated number
    - {max_bytes}: obtained from running system

    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -name <java.lang.String> (property: name)
        The name of the actor.
        default: MemoryMonitor
     
    -annotation <adams.core.base.BaseAnnotation> (property: annotations)
        The annotations to attach to this actor.
        default:
     
    -skip <boolean> (property: skip)
        If set to true, transformation is skipped and the input token is just forwarded
        as it is.
        default: false
     
    -stop-flow-on-error <boolean> (property: stopFlowOnError)
        If set to true, the flow execution at this level gets stopped in case this
        actor encounters an error; the error gets propagated; useful for critical
        actors.
        default: false
     
    -silent <boolean> (property: silent)
        If enabled, then no errors are output in the console; Note: the enclosing
        actor handler must have this enabled as well.
        default: false
     
    -memory-type <HEAP_USED|HEAP_COMMITTED> (property: memoryType)
        The type of memory to monitor.
        default: HEAP_USED
     
    -sample-interval <int> (property: sampleInterval)
        The sample interval in seconds.
        default: 10
        minimum: 1
     
    -num-samples <int> (property: numSamples)
        The number of samples to use for making a decision.
        default: 100
        minimum: 1
     
    -threshold <double> (property: threshold)
        The percentage of the maximum heap that the used heap must reach/exceed
        (0-100).
        default: 80.0
        minimum: 0.0
        maximum: 100.0
     
    -coverage <double> (property: coverage)
        The percentage of samples that reach/exceed the threshold (0-100).
        default: 75.0
        minimum: 0.0
        maximum: 100.0
     
    -notification <adams.flow.sink.sendnotification.AbstractNotification> (property: notification)
        The notification to use.
        default: adams.flow.sink.sendnotification.Null
     
    -message-template <adams.core.base.BaseText> (property: messageTemplate)
        The message template to use.
        default: {coverage_perc}% of {num_samples} samples have exceeded the threshold of {threshold_perc}% (= {threshold_bytes}) of the maximum heap of {max_bytes}.
     
    -notification-wait <int> (property: notificationWait)
        The number of seconds to wait before sending out another notification.
        default: 86400
        minimum: 1
     
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_SampleInterval

        protected int m_SampleInterval
        the sample interval in seconds.
      • m_NumSamples

        protected int m_NumSamples
        the number of samples to keep.
      • m_Threshold

        protected double m_Threshold
        the percentage threshold of max heap that the used heap will have to cross (0-100).
      • m_Coverage

        protected double m_Coverage
        the coverage percentage of samples reaching/exceeding the threshold (0-100).
      • m_MessageTemplate

        protected BaseText m_MessageTemplate
        the notification message template.
      • m_NotificationWait

        protected int m_NotificationWait
        the wait time in seconds after sending out another notification.
      • m_Sampler

        protected transient RunnableWithLogging m_Sampler
        the runnable performing the sampling.
    • Constructor Detail

      • MemoryMonitor

        public MemoryMonitor()
    • Method Detail

      • setMemoryType

        public void setMemoryType​(MemoryMonitor.MemoryType value)
        Sets the type of memory to monitor.
        Parameters:
        value - the type
      • getMemoryType

        public MemoryMonitor.MemoryType getMemoryType()
        Returns the type of memory to monitor.
        Returns:
        the type
      • memoryTypeTipText

        public String memoryTypeTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setSampleInterval

        public void setSampleInterval​(int value)
        Sets the sample interval.
        Parameters:
        value - the interval in seconds
      • getSampleInterval

        public int getSampleInterval()
        Returns the sample interval.
        Returns:
        the interval in seconds
      • sampleIntervalTipText

        public String sampleIntervalTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setNumSamples

        public void setNumSamples​(int value)
        Sets the number of samples.
        Parameters:
        value - the number of samples
      • getNumSamples

        public int getNumSamples()
        Returns the number of samples.
        Returns:
        the number of samples
      • numSamplesTipText

        public String numSamplesTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setThreshold

        public void setThreshold​(double value)
        Sets the percentage of the maximum heap that the used heap must reach/exceed.
        Parameters:
        value - the threshold (0-100)
      • getThreshold

        public double getThreshold()
        Returns the percentage of the maximum heap that the used heap must reach/exceed.
        Returns:
        the threshold (0-100)
      • thresholdTipText

        public String thresholdTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setCoverage

        public void setCoverage​(double value)
        Sets the percentage of samples that must reach/exceed the threshold.
        Parameters:
        value - the coverage (0-1)
      • getCoverage

        public double getCoverage()
        Returns the percentage of samples that must reach/exceed the threshold.
        Returns:
        the coverage (0-100)
      • coverageTipText

        public String coverageTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setNotification

        public void setNotification​(AbstractNotification value)
        Sets the notification scheme to use.
        Parameters:
        value - the notification
      • getNotification

        public AbstractNotification getNotification()
        Returns the notification scheme in use.
        Returns:
        the notification
      • notificationTipText

        public String notificationTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setMessageTemplate

        public void setMessageTemplate​(BaseText value)
        Sets the message template to use.
        Parameters:
        value - the template
      • getMessageTemplate

        public BaseText getMessageTemplate()
        Returns the message template to use.
        Returns:
        the template
      • messageTemplateTipText

        public String messageTemplateTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setNotificationWait

        public void setNotificationWait​(int value)
        Sets the number of seconds to wait before sending out another notification.
        Parameters:
        value - the number of seconds
      • getNotificationWait

        public int getNotificationWait()
        Returns the number of seconds to wait before sending out another notification.
        Returns:
        the number of seconds
      • notificationWaitTipText

        public String notificationWaitTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • doExecute

        protected String doExecute()
        Executes the flow item.
        Specified by:
        doExecute in class AbstractActor
        Returns:
        null if everything is fine, otherwise error message
      • wrapUp

        public void wrapUp()
        Cleans up after the execution has finished. Graphical output is left untouched.
        Specified by:
        wrapUp in interface Actor
        Overrides:
        wrapUp in class AbstractActor