For those not at 8.1.6 yet though, I got this from Travis (modified to be a function).
Bonus points if you can tell me how to get the number of tags subscribed to a Device… or how I can find out how to do this using the SDK doco. I couldn’t see the IgnitionGateway class within the javadocs
def getDeviceLoadFactor(deviceName):
"""
Description:
Gets the load factors for each Device/PLC and writes these into a dataset tag within each PLC's UDT instances.
This function must be called from the gateway context. It will not run in any other context (i.e. Designer or Client)
Arguments:
deviceName: the name of the device to get the load factor(s) for
Return:
A dictionary of device name and metrics which is a dictionary of scan rates and load factors
"""
from com.inductiveautomation.ignition.gateway import IgnitionGateway
import traceback
context = IgnitionGateway.get()
dm = context.getModule("com.inductiveautomation.opcua").getClass().getClassLoader().loadClass("com.inductiveautomation.ignition.gateway.opcua.OpcUaModule").server.getDeviceManager()
deviceObj = dm.getDevice(deviceName)
metrics = deviceObj.getPollingMetrics().get()
cr = metrics.concurrentRequests
rsl = metrics.rateStatsList
loadFactors = {}
for r in rsl:
hg = r.histogram.getMedian() / 1000000
rq = r.requestCount
rate = r.rate
loadFactor = round(((hg * rq / cr) / rate) * 100)
loadFactors[rate] = loadFactor
deviceMetrics = {'device': deviceName,
'metrics': loadFactors}
return deviceMetrics