# Monitoring the device load factor

**URL:** <https://forum.inductiveautomation.com/t/monitoring-the-device-load-factor/17389>\
**Category:** Ignition\
**Created:** [March 16, 2018, 9:37am UTC](https://forum.inductiveautomation.com/t/monitoring-the-device-load-factor/17389 "2018-03-16T09:37:23Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 13, 2021, 2:10pm UTC](https://forum.inductiveautomation.com/t/monitoring-the-device-load-factor/17389/9 "2021-05-13T14:10:06Z")

</div>

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 ☹

```auto
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

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/monitoring-the-device-load-factor/17389)._
