# Users count, Machines Count, Tag Count

**URL:** <https://forum.inductiveautomation.com/t/users-count-machines-count-tag-count/70059>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [February 20, 2023, 10:28am UTC](https://forum.inductiveautomation.com/t/users-count-machines-count-tag-count/70059 "2023-02-20T10:28:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [February 20, 2023, 10:28am UTC](https://forum.inductiveautomation.com/t/users-count-machines-count-tag-count/70059/1 "2023-02-20T10:28:38Z")

</div>

Hi ,

I would like to display the below values in a vision window,

1. Active OPC connections
2. Users count from default user source.
3. Users count for AD/Internal hybrid
4. Parameters count that has been historized

would like to hear your ideas to retrieve the above info

---

<div class="post-metadata">

**Author:** ![mcgheeiv](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@mcgheeiv](https://forum.inductiveautomation.com/u/mcgheeiv)\
**Post date:** [February 20, 2023, 10:43am UTC](https://forum.inductiveautomation.com/t/users-count-machines-count-tag-count/70059/2 "2023-02-20T10:43:24Z")

</div>

Which version of Ignition?

For 2 and 3, do you want the total users in those sources or just the logged in users?

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [February 20, 2023, 10:44am UTC](https://forum.inductiveautomation.com/t/users-count-machines-count-tag-count/70059/3 "2023-02-20T10:44:04Z")

</div>

I am using 8.1.25.  
I require total users count with specific role.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 20, 2023, 11:11am UTC](https://forum.inductiveautomation.com/t/users-count-machines-count-tag-count/70059/4 "2023-02-20T11:11:19Z")

</div>

OPC connections or devices?

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [February 20, 2023, 11:12am UTC](https://forum.inductiveautomation.com/t/users-count-machines-count-tag-count/70059/5 "2023-02-20T11:12:11Z")

</div>

OPC UA connections as in Status-\> Connections-\> OPC Connections

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 20, 2023, 11:45am UTC](https://forum.inductiveautomation.com/t/users-count-machines-count-tag-count/70059/6 "2023-02-20T11:45:39Z")

</div>

```python
from collections import Counter
from itertools import chain

# OPC connections
opcConnections = Counter([system.opc.getServerState(opcServer) for opcServer in system.opc.getServers(includeDisabled = True)])
print opcConnections

# user source
userSource = 'myUserSource'
users = system.user.getUsers(userSource)
roles = Counter(list(chain.from_iterable(user.roles for user in users)))
print roles

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 20, 2023, 12:22pm UTC](https://forum.inductiveautomation.com/t/users-count-machines-count-tag-count/70059/7 "2023-02-20T12:22:25Z")

</div>

```python
# Count tags with history turned on 
filters =	{
			'tagType'	: 'AtomicTag',
			'recursive'	: True
			}			
provider = '[Test]'
historyCount = 0
for tag in system.tag.browse(provider, filters).getResults():
	if 'history' in str(dict(tag).get('attributes', '')):
		 #print str(tag['fullPath'])
		 historyCount += 1
print historyCount

```

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [February 21, 2023, 4:19am UTC](https://forum.inductiveautomation.com/t/users-count-machines-count-tag-count/70059/8 "2023-02-21T04:19:16Z")

</div>

Thanks Jordan.  
I have achieved the results by modifying the code as below,

```auto
	#To get the count of historized tag
	filters =	{
				'tagType'	: 'AtomicTag',
				'recursive'	: True
				}			
	provider = '[default]'
	historyCount = 0
	for tag in system.tag.browse(provider, filters).getResults():
		if 'history' in str(dict(tag).get('attributes', '')):
			 #print str(tag['fullPath'])
			 historyCount += 1
	vTotal = historyCount
	system.tag.writeBlocking("[.]Parameters",[vTotal])
	
	#To get the Total no of AD users
	userSource = 'XYZ.COM'
	users = system.user.getUsers(userSource)
	viewer_count = sum(1 for user in users if 'Viewer' in user.roles)
	system.tag.writeBlocking("[.]Users",[viewer_count])
	
	#To get the Total no of Local users
	userSource1 = 'default'
	users1 = system.user.getUsers(userSource1)
	viewer_count1 = sum(1 for user in users1 if 'Viewer' in user.roles)
	system.tag.writeBlocking("[.]Operators",[viewer_count1])	
	
	#To get the Total no of OPC connections
	from collections import Counter
	from itertools import chain
	
	# OPC connections
	
	opcConnections = Counter([system.opc.getServerState(opcServer) for opcServer in system.opc.getServers(includeDisabled=True)])
	connected_count = opcConnections['CONNECTED']
	system.tag.writeBlocking("[.]OPCConnections",[connected_count])	

```
