I am trying to persist the current java heap size so I can try and track down the cause of java running out of memory on my OH 2.4 system. @rlkoshak helped tremendously by showing me how to set up passwordless logins to the karaf shell and extract the relevant value and I now have a script called from an exec command that stores the current heap size in a string item.
I’ve nearly cracked it but have been banging my head on the desk at the very last step which is converting the output of the ssh command from a string to a number item.
I have the following items:
String ShellCurrentHeapString "Current Heap Size (String)" {channel="exec:command:exec_shell_current_heap5:output"}
Number ShellCurrentHeapNumber "Current Heap Size" (gGraphing)
The number item is intended to store the value of the string item cast to a number by the following rule:
from core.triggers import when
from core.rules import rule
@rule("Karaf current heap size", description="This rule converts the string value of the current heap size to a number value", tags=["Example"])
@when("Item ShellCurrentHeapString received update")
def karaf_current_heap_size(event):
testvar = None
testvar = float(str(ir.getItem(event.itemName).getState))
(I need to store the current heap size as a number so I can persist it in InfluxDB and then graph it with Grafana.)
However, I can’t seem to get the syntax right to cast from string to int (or float), I thought that part would be the easy bit. Errors in the log are:
2019-09-06 20:44:35.769 [ERROR] [omation.core.internal.RuleEngineImpl] - Failed to execute rule '7595688b-2d1c-4777-ba36-31af43d15fcb': Fail to execute action: 1
2019-09-06 20:44:37.913 [ERROR] [sr223.jython.Karaf current heap size] - Traceback (most recent call last):
File "/etc/openhab2/automation/lib/python/core/log.py", line 43, in wrapper
return fn(*args, **kwargs)
File "<script>", line 9, in karaf_current_heap_size
ValueError: invalid literal for float: <bound method org.eclipse.smarthome.core.library.items.StringItem.getState of ShellCurrentHeapString (Type=StringItem, State=2019178, Label=Current Heap Size (String), Category=null)>
2019-09-06 20:44:37.913 [ERROR] [omation.core.internal.RuleEngineImpl] - Failed to execute rule '7595688b-2d1c-4777-ba36-31af43d15fcb': Fail to execute action: 1
Or if I try to convert to an integer:
2019-09-06 20:45:32.378 [ERROR] [sr223.jython.Karaf current heap size] - Traceback (most recent call last):
File "/etc/openhab2/automation/lib/python/core/log.py", line 43, in wrapper
return fn(*args, **kwargs)
File "<script>", line 9, in karaf_current_heap_size
ValueError: invalid literal for int() with base 10: '<bound method org.eclipse.smarthome.core.library.items.StringItem.getState of ShellCurrentHeapString (Type=StringItem, State=2020605, Label=Current Heap Size (String), Catego
ry=null)>'
2019-09-06 20:45:32.378 [ERROR] [omation.core.internal.RuleEngineImpl] - Failed to execute rule '030dc9c7-769b-4ea4-88fb-e7dd2377350c': Fail to execute action: 1
I thought converting from a string to an integer would be the easy part!