[systeminfo] Add 2 new channels for Java heap (#11322)
* Add heap measuring. * refactor to remove apache.commons Signed-off-by: Matthew Skinner <matt@pcmus.com>
This commit is contained in:
@@ -81,6 +81,16 @@ public class SysteminfoBindingConstants {
|
||||
*/
|
||||
public static final String CHANNEL_MEMORY_USED_PERCENT = "memory#usedPercent";
|
||||
|
||||
/**
|
||||
* Percents of the used heap
|
||||
*/
|
||||
public static final String CHANNEL_MEMORY_USED_HEAP_PERCENT = "memory#usedHeapPercent";
|
||||
|
||||
/**
|
||||
* Bytes used in the heap
|
||||
*/
|
||||
public static final String CHANNEL_MEMORY_HEAP_AVAILABLE = "memory#availableHeap";
|
||||
|
||||
/**
|
||||
* Total size of swap memory
|
||||
*/
|
||||
|
||||
@@ -28,6 +28,9 @@ import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.systeminfo.internal.model.DeviceNotFoundException;
|
||||
import org.openhab.binding.systeminfo.internal.model.SysteminfoInterface;
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
import org.openhab.core.library.unit.Units;
|
||||
import org.openhab.core.thing.Channel;
|
||||
import org.openhab.core.thing.ChannelUID;
|
||||
import org.openhab.core.thing.Thing;
|
||||
@@ -106,12 +109,9 @@ public class SysteminfoHandler extends BaseThingHandler {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
logger.debug("Start initializing!");
|
||||
|
||||
if (instantiateSysteminfoLibrary() && isConfigurationValid() && updateProperties()) {
|
||||
groupChannelsByPriority();
|
||||
scheduleUpdates();
|
||||
logger.debug("Thing is successfully initialized!");
|
||||
updateStatus(ThingStatus.ONLINE);
|
||||
} else {
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR,
|
||||
@@ -290,6 +290,13 @@ public class SysteminfoHandler extends BaseThingHandler {
|
||||
|
||||
try {
|
||||
switch (channelID) {
|
||||
case CHANNEL_MEMORY_HEAP_AVAILABLE:
|
||||
state = new QuantityType<>(Runtime.getRuntime().freeMemory(), Units.BYTE);
|
||||
break;
|
||||
case CHANNEL_MEMORY_USED_HEAP_PERCENT:
|
||||
state = new DecimalType((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()) * 100
|
||||
/ Runtime.getRuntime().maxMemory());
|
||||
break;
|
||||
case CHANNEL_DISPLAY_INFORMATION:
|
||||
state = systeminfo.getDisplayInformation(deviceIndex);
|
||||
break;
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
@@ -339,7 +338,10 @@ public class OSHISysteminfo implements SysteminfoInterface {
|
||||
@Override
|
||||
public @Nullable DecimalType getSensorsFanSpeed(int index) throws DeviceNotFoundException {
|
||||
int[] fanSpeeds = sensors.getFanSpeeds();
|
||||
int speed = getDevice(ArrayUtils.toObject(fanSpeeds), index);
|
||||
int speed = 0;// 0 means unable to measure speed
|
||||
if (index < fanSpeeds.length) {
|
||||
speed = fanSpeeds[index];
|
||||
}
|
||||
return speed > 0 ? new DecimalType(speed) : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
<channel id="used" typeId="used"/>
|
||||
<channel id="availablePercent" typeId="availablePercent"/>
|
||||
<channel id="usedPercent" typeId="usedPercent"/>
|
||||
<channel id="availableHeap" typeId="availableHeap"/>
|
||||
<channel id="usedHeapPercent" typeId="usedHeapPercent"/>
|
||||
</channels>
|
||||
</channel-group-type>
|
||||
|
||||
@@ -125,6 +127,22 @@
|
||||
</channels>
|
||||
</channel-group-type>
|
||||
|
||||
<channel-type id="availableHeap" advanced="true">
|
||||
<item-type>Number:DataAmount</item-type>
|
||||
<label>Available Heap</label>
|
||||
<description>How much data is available in the Java heap.</description>
|
||||
<state pattern="%.1f %unit%" readOnly="true"/>
|
||||
<config-description-ref uri="channel-type:systeminfo:mediumpriority"/>
|
||||
</channel-type>
|
||||
|
||||
<channel-type id="usedHeapPercent">
|
||||
<item-type>Number:Dimensionless</item-type>
|
||||
<label>Used Heap Percent</label>
|
||||
<description>How much data in percent has been used from the max size the Java heap can grow to.</description>
|
||||
<state pattern="%.1f %%" readOnly="true"/>
|
||||
<config-description-ref uri="channel-type:systeminfo:mediumpriority"/>
|
||||
</channel-type>
|
||||
|
||||
<channel-type id="path_process">
|
||||
<item-type>String</item-type>
|
||||
<label>Path</label>
|
||||
|
||||
Reference in New Issue
Block a user