Package com.microej.kf.util.monitoring
Class ResourceMonitoringServiceImpl
- java.lang.Object
-
- com.microej.kf.util.monitoring.ResourceMonitoringServiceImpl
-
- All Implemented Interfaces:
ResourceMonitoringService,ej.kf.FeatureStateListener
public class ResourceMonitoringServiceImpl extends java.lang.Object implements ResourceMonitoringService, ej.kf.FeatureStateListener
This class represents the implementation for the ResourceMonitoringService.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classResourceMonitoringServiceImpl.MonitoringTaskThis class represents the monitoring task ran at regular interval.
-
Constructor Summary
Constructors Constructor Description ResourceMonitoringServiceImpl(ej.bon.Timer timer, long intervalMillis, boolean runGcBeforeCollecting)Instantiates the resource monitoring service.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetFreeMemory()Returns the free memory.longgetMaxMemory()Returns the max memory.longgetTotalMemory()Returns the total memory.ej.basictool.map.PackedMap<java.lang.String,java.lang.Float>getUsedCpuPercentPerModule()Retrieves the CPU usage for each module from the previous monitoring cycle, expressed as a percentage.ej.basictool.map.PackedMap<java.lang.String,java.lang.Float>getUsedMemoryPercentPerModule()Retrieves the RAM usage values expressed as a percentage (a value between 0 and 1.0).ej.basictool.map.PackedMap<java.lang.String,java.lang.Long>getUsedMemoryPerModule()Retrieves the current RAM usage for each module.voidstart()Starts the resource monitoring task by enabling monitoring on each module.voidstateChanged(ej.kf.Feature app, ej.kf.Feature.State state)voidstop()Stops resource monitoring by disabling monitoring on each module.
-
-
-
Constructor Detail
-
ResourceMonitoringServiceImpl
public ResourceMonitoringServiceImpl(ej.bon.Timer timer, long intervalMillis, boolean runGcBeforeCollecting)Instantiates the resource monitoring service.- Parameters:
timer- the timer.intervalMillis- the timer interval read from the kernel properties.runGcBeforeCollecting- the boolean read from kernel properties to run GC before collecting monitoring data.
-
-
Method Detail
-
start
public void start()
Starts the resource monitoring task by enabling monitoring on each module.
-
stop
public void stop()
Stops resource monitoring by disabling monitoring on each module.
-
stateChanged
public void stateChanged(ej.kf.Feature app, @Nullable ej.kf.Feature.State state)- Specified by:
stateChangedin interfaceej.kf.FeatureStateListener
-
getUsedCpuPercentPerModule
public ej.basictool.map.PackedMap<java.lang.String,java.lang.Float> getUsedCpuPercentPerModule()
Description copied from interface:ResourceMonitoringServiceRetrieves the CPU usage for each module from the previous monitoring cycle, expressed as a percentage.- Specified by:
getUsedCpuPercentPerModulein interfaceResourceMonitoringService- Returns:
- a map where each entry contains a module name as the key and its CPU usage percentage (0.0 to 1.0) as the value.
-
getUsedMemoryPerModule
public ej.basictool.map.PackedMap<java.lang.String,java.lang.Long> getUsedMemoryPerModule()
Description copied from interface:ResourceMonitoringServiceRetrieves the current RAM usage for each module.- Specified by:
getUsedMemoryPerModulein interfaceResourceMonitoringService- Returns:
- a map where each entry contains a module identifier as the key and its current RAM usage in bytes as the value.
-
getUsedMemoryPercentPerModule
public ej.basictool.map.PackedMap<java.lang.String,java.lang.Float> getUsedMemoryPercentPerModule()
Description copied from interface:ResourceMonitoringServiceRetrieves the RAM usage values expressed as a percentage (a value between 0 and 1.0).The percentage indicates the ratio between a module's current heap consumption and the total heap.
- Specified by:
getUsedMemoryPercentPerModulein interfaceResourceMonitoringService- Returns:
- a map where each entry contains the module name as the key and its current RAM usage percentage as the value.
-
getFreeMemory
public long getFreeMemory()
Description copied from interface:ResourceMonitoringServiceReturns the free memory.- Specified by:
getFreeMemoryin interfaceResourceMonitoringService- Returns:
- the free memory.
-
getMaxMemory
public long getMaxMemory()
Description copied from interface:ResourceMonitoringServiceReturns the max memory.- Specified by:
getMaxMemoryin interfaceResourceMonitoringService- Returns:
- the max memory.
-
getTotalMemory
public long getTotalMemory()
Description copied from interface:ResourceMonitoringServiceReturns the total memory.- Specified by:
getTotalMemoryin interfaceResourceMonitoringService- Returns:
- the total memory.
-
-