Hi,
I am currently working to build alerting based on the threads or heap memory.
Can some one help me to get the performance values likes total threads, waiting threads, heap memory etc using scripting in project...
Thanks in advance ....
Hi,
I am currently working to build alerting based on the threads or heap memory.
Can some one help me to get the performance values likes total threads, waiting threads, heap memory etc using scripting in project...
Thanks in advance ....
Start here:
If you get a GatewayContext (search here on the forums), you can also pull out some Ignition specific metrics from the MetricRegistry:
https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.22/com/inductiveautomation/ignition/gateway/model/GatewayContext.html
thanks for ur response, am new to ignition customization and its great help post with example.
How to get the data "getRunningThreadsCount() from PerformanceMonitor class"
This is what I use
def getGatewayMetrics():
fn = 'getGatewayMetrics'
from com.inductiveautomation.ignition.gateway import IgnitionGateway
try:
context = IgnitionGateway.get()
registry = context.getMetricRegistry()
metrics = {}
items = registry.getCounters()
for item in items:
#LOGGER.info('{}: {}'.format(fn, ', '.join(d for d in dir(item))))
o = items.get(item)
metrics[item] = {'type': 'counter',
'value': o.getCount()
}
items = registry.getMeters()
for item in items:
o = items.get(item)
metrics[item] = {'type': 'meter',
'value_1min': o.getOneMinuteRate(),
'value_5min': o.getFiveMinuteRate(),
'value_15min': o.getFifteenMinuteRate()
}
items = registry.getGauges()
for item in items:
o = items.get(item)
metrics[item] = {'type': 'gauge',
'value': o.getValue()
}
# for item in registry.getHistograms():
items = registry.getTimers()
for item in items:
o = items.get(item)
metrics[item] = {'type': 'timer',
'value_1min': o.getOneMinuteRate(),
'value_5min': o.getFiveMinuteRate(),
'value_15min': o.getFifteenMinuteRate()
}
except:
import traceback
LOGGER.error('{}: {}'.format(fn, traceback.format_exc()))
return {}
return metrics
To write the thread count metrics to tags, I use:
def writeMetricsTags():
fn = 'writeMetricsTags'
try:
metrics = getGatewayMetrics()
if metrics != {}:
tags = []
# updated the metrics keys after upgrading from 8.1.5 to 8.1.18 as these changed
tags.append(['[default]Gateway/{}/Threads/Blocked'.format(THIS_GATEWAY_HOSTNAME), metrics['ignition.performance.threads.blocked']['value']])
tags.append(['[default]Gateway/{}/Threads/Running'.format(THIS_GATEWAY_HOSTNAME), metrics['ignition.performance.threads.running']['value']])
tags.append(['[default]Gateway/{}/Threads/Timed_Waiting'.format(THIS_GATEWAY_HOSTNAME), metrics['ignition.performance.threads.timed-waiting']['value']])
tags.append(['[default]Gateway/{}/Threads/Waiting'.format(THIS_GATEWAY_HOSTNAME), metrics['ignition.performance.threads.waiting']['value']])
system.tag.writeBlocking([tag for tag,val in tags], [val for tag,val in tags])
except:
import traceback
LOGGER.error('{}: {}'.format(fn, traceback.format_exc()))
Aw, Nick, c'mon
system.tag.writeBlocking(*zip(*tags))
Surely this is more readable
Better-throughout-Ignition access to these system metrics is something on our short-to-medium-term to do list; in particular, better alarming.
It's funny, I actually looked at that part of my script when I posted it and thought, "I know there's a more succinct way to do this... "
I thought I'd be kind though and let you fix it
Hey,
Thanks for your reply, am getting error "cannot import name IgnitionGateway".
Kindly pls share the process to get things done...
Thanks in advance
That import is deliberately undocumented because you can do dangerous things with it. If you cannot figure out how to use that import,and where you can use it, it might be too dangerous for you. But examples are scattered around this forum, if you really must. Paul (an IA employee) very deliberately did not give you an example.
Whatever you do, don't bother IA support with any trouble you run into as a consequence.
The link I posted is for bog-standard and safe java functionality.
As a hint, you can only run this from the gateway scope. And if you don't edit my script too much, you won't get yourself into trouble