Package adams.flow.standalone
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MemoryMonitor.MemoryType
What type of memory to monitor.
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_MESSAGE_TEMPLATE
protected double
m_Coverage
the coverage percentage of samples reaching/exceeding the threshold (0-100).protected MemoryMonitor.MemoryType
m_MemoryType
the type of memory to monitor.protected BaseText
m_MessageTemplate
the notification message template.protected AbstractNotification
m_Notification
the notification scheme to use.protected int
m_NotificationWait
the wait time in seconds after sending out another notification.protected int
m_NumSamples
the number of samples to keep.protected int
m_SampleInterval
the sample interval in seconds.protected RunnableWithLogging
m_Sampler
the runnable performing the sampling.protected double
m_Threshold
the percentage threshold of max heap that the used heap will have to cross (0-100).static String
PH_COVERAGE_NUM
static String
PH_COVERAGE_PERC
static String
PH_MAX_BYTES
static String
PH_NUM_SAMPLES
static String
PH_THRESHOLD_BYTES
static String
PH_THRESHOLD_PERC
-
Fields inherited from class adams.flow.core.AbstractActor
m_Annotations, m_BackupState, m_DetectedObjectVariables, m_DetectedVariables, m_ErrorHandler, m_Executed, m_Executing, m_ExecutionListeningSupporter, m_FullName, m_LoggingPrefix, m_Name, m_Parent, m_ScopeHandler, m_Self, m_Silent, m_Skip, m_StopFlowOnError, m_StopMessage, m_Stopped, m_StorageHandler, m_VariablesUpdated
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from interface adams.flow.core.Actor
FILE_EXTENSION, FILE_EXTENSION_GZ
-
-
Constructor Summary
Constructors Constructor Description MemoryMonitor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
coverageTipText()
Returns the tip text for this property.void
defineOptions()
Adds options to the internal list of options.protected String
doExecute()
Executes the flow item.double
getCoverage()
Returns the percentage of samples that must reach/exceed the threshold.MemoryMonitor.MemoryType
getMemoryType()
Returns the type of memory to monitor.BaseText
getMessageTemplate()
Returns the message template to use.AbstractNotification
getNotification()
Returns the notification scheme in use.int
getNotificationWait()
Returns the number of seconds to wait before sending out another notification.int
getNumSamples()
Returns the number of samples.String
getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.int
getSampleInterval()
Returns the sample interval.double
getThreshold()
Returns the percentage of the maximum heap that the used heap must reach/exceed.String
globalInfo()
Returns a string describing the object.String
memoryTypeTipText()
Returns the tip text for this property.String
messageTemplateTipText()
Returns the tip text for this property.String
notificationTipText()
Returns the tip text for this property.String
notificationWaitTipText()
Returns the tip text for this property.String
numSamplesTipText()
Returns the tip text for this property.String
sampleIntervalTipText()
Returns the tip text for this property.void
setCoverage(double value)
Sets the percentage of samples that must reach/exceed the threshold.void
setMemoryType(MemoryMonitor.MemoryType value)
Sets the type of memory to monitor.void
setMessageTemplate(BaseText value)
Sets the message template to use.void
setNotification(AbstractNotification value)
Sets the notification scheme to use.void
setNotificationWait(int value)
Sets the number of seconds to wait before sending out another notification.void
setNumSamples(int value)
Sets the number of samples.void
setSampleInterval(int value)
Sets the sample interval.void
setThreshold(double value)
Sets the percentage of the maximum heap that the used heap must reach/exceed.void
stopExecution()
Stops the execution.String
thresholdTipText()
Returns the tip text for this property.void
wrapUp()
Cleans up after the execution has finished.-
Methods inherited from class adams.flow.standalone.AbstractStandalone
preExecute
-
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, backupState, canInspectOptions, canPerformSetUpCheck, cleanUp, compareTo, configureLogger, destroy, equals, execute, finalUpdateVariables, findVariables, findVariables, forceVariables, forCommandLine, forName, forName, getAdditionalInformation, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowActors, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, handleException, hasErrorHandler, hasStopMessage, index, initialize, isBackedUp, isExecuted, isExecuting, isFinished, isHeadless, isStopped, nameTipText, performSetUpChecks, performVariableChecks, postExecute, pruneBackup, pruneBackup, reset, restoreState, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setUp, setVariables, shallowCopy, shallowCopy, silentTipText, sizeOf, skipTipText, stopExecution, stopFlowOnErrorTipText, updateDetectedVariables, updatePrefix, updateVariables, variableChanged
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.flow.core.Actor
toCommandLine
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel, setLoggingLevel
-
Methods inherited from interface adams.core.logging.LoggingSupporter
getLogger, isLoggingEnabled
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager
-
-
-
-
Field Detail
-
PH_THRESHOLD_PERC
public static final String PH_THRESHOLD_PERC
- See Also:
- Constant Field Values
-
PH_THRESHOLD_BYTES
public static final String PH_THRESHOLD_BYTES
- See Also:
- Constant Field Values
-
PH_NUM_SAMPLES
public static final String PH_NUM_SAMPLES
- See Also:
- Constant Field Values
-
PH_COVERAGE_PERC
public static final String PH_COVERAGE_PERC
- See Also:
- Constant Field Values
-
PH_COVERAGE_NUM
public static final String PH_COVERAGE_NUM
- See Also:
- Constant Field Values
-
PH_MAX_BYTES
public static final String PH_MAX_BYTES
- See Also:
- Constant Field Values
-
DEFAULT_MESSAGE_TEMPLATE
public static final String DEFAULT_MESSAGE_TEMPLATE
- See Also:
- Constant Field Values
-
m_MemoryType
protected MemoryMonitor.MemoryType m_MemoryType
the type of memory to monitor.
-
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_Notification
protected AbstractNotification m_Notification
the notification scheme to use.
-
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.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractActor
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.- Specified by:
getQuickInfo
in interfaceActor
- Specified by:
getQuickInfo
in interfaceQuickInfoSupporter
- Overrides:
getQuickInfo
in classAbstractActor
- Returns:
- null if no info available, otherwise short string
-
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 classAbstractActor
- Returns:
- null if everything is fine, otherwise error message
-
stopExecution
public void stopExecution()
Stops the execution. No message set.- Specified by:
stopExecution
in interfaceActor
- Specified by:
stopExecution
in interfaceStoppable
- Overrides:
stopExecution
in classAbstractActor
-
wrapUp
public void wrapUp()
Cleans up after the execution has finished. Graphical output is left untouched.- Specified by:
wrapUp
in interfaceActor
- Overrides:
wrapUp
in classAbstractActor
-
-