Hi ~
As in the attached file.
I want to implement a screen with cpu, memory, threads, cpu trend, memory trend, etc. in Performance on the web as it is from a perspective, what should I do?
Hi ~
As in the attached file.
I want to implement a screen with cpu, memory, threads, cpu trend, memory trend, etc. in Performance on the web as it is from a perspective, what should I do?
I know how to get the counts of the categories (timed waiting, running, blocked,.. One other one) of threads? Or do you want the details of the threads as in your screenshot?
Could you tell me both ways you said?
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
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', metrics['ignition.performance.threads.blocked']['value']])
tags.append(['[default]Gateway/Threads/Running', metrics['ignition.performance.threads.running']['value']])
tags.append(['[default]Gateway/Threads/Timed_Waiting', metrics['ignition.performance.threads.timed-waiting']['value']])
tags.append(['[default]Gateway/Threads/Waiting', metrics['ignition.performance.threads.waiting']['value']])
tags.append(['[default]Gateway/GAN/Incoming Connections (1min Avg)', metrics['GANConnection.Incoming._0:0:{your ignition gateway system name}']['value_1min']])
tags.append(['[default]Gateway/GAN/Outgoing Connections (1min Avg)', metrics['GANConnection.Outgoing._0:0:{your ignition gateway system name}']['value_1min']])
# this metric appears to have been removed in > 8.1.5
#tags.append(['[default]Gateway/GAN/Activity Level', metrics['i:GAN_Activity_Info_Service/getActivityLevel']['value_1min']])
system.tag.writeBlocking([tag for tag,val in tags], [val for tag,val in tags])
except:
# do some error logging
pass
You can get the gateway metrics which include the categorised thread counts using the above functions. writeMetricsTags
will write various metrics into tags. You'll need to add these tags for it to be able to write into them.
Edit:
Note: you'll need to run this in the gateway scope
Thanks for letting me know.
But I don't know how to use the method you told me.
Should I use the method you taught me in gateway events?
Or should I use it for the project library?
And I told you to make a tag, but how do I make a tag?
I don't know how to use it because it's my first time using it...
Can you tell me the details?
Firstly, it needs to be run in the gateway context.
I would suggest you run the script within a gateway scheduled event script which runs every x seconds. (I added the script into a function in a script library and then called the library function from the GW scheduled event).
The tagpaths you need to create are contained in the script. These should be integer memory tags (apart from maybe the 1min averaged values) i.e.
tags.append(['[default]Gateway/Threads/Blocked', metrics['ignition.performance.threads.blocked']['value']])
tags.append(['[default]Gateway/Threads/Running', metrics['ignition.performance.threads.running']['value']])
tags.append(['[default]Gateway/Threads/Timed_Waiting', metrics['ignition.performance.threads.timed-waiting']['value']])
tags.append(['[default]Gateway/Threads/Waiting', metrics['ignition.performance.threads.waiting']['value']])
tags.append(['[default]Gateway/GAN/Incoming Connections (1min Avg)', metrics['GANConnection.Incoming._0:0:{your ignition gateway system name}']['value_1min']])
tags.append(['[default]Gateway/GAN/Outgoing Connections (1min Avg)', metrics['GANConnection.Outgoing._0:0:{your ignition gateway system name}']['value_1min']])
ㅇ