Monitoring Tower license usage

My team uses Ansible Tower (the RedHat licensed product) and we track the license usage change day-to-day with this python script. We have two environments, so the system will use the LOGIN_INFO dictionary to login and record each sites current instances. There’s also an example how to call it from a crontab. The script does send data to the screen (stdout) as well as the CSV file - in the future I might update this to be an option to disable for crontab usage.

If you have a single instance, update the “envs” variable to just note “Prod” like this:
envs = {'Prod', 'Sandbox', 'Total'}
and remove the corresponding LOGIN_INFO entry.

If you have three or more sites, add them to the envs:
envs = {'Prod', 'Sandbox', 'Lab', 'DMZ', 'Total'}

and add additional LOGIN_INFO entries.

I'd love feedback if this works to monitor server counts in the AWX project too.

Code is supplied "**AS-IS, NO WARRANTY**" but it should be safe enough once you've reviewed it for yourself.

`
#!/usr/bin/env python

Hey Dan,

This is neat, thanks for sharing.

You might want to check out a new feature we just merged into AWX (which will be in a future version of Ansible Tower):

https://github.com/ansible/awx/issues/1963

~ curl -ks “https://ryan:ryan@awx.example.org/api/v2/metrics/” | grep free_instances
awx_system_info{ansible_version=“2.7.10”,external_logger_enabled=“False”,external_logger_type=“None”,free_instances=“0”,insights_analytics=“True”,install_uuid=“95d325fc-43b1-4f72-8c4f-658c43ade26b”,license_expiry=“8516103533”,license_type=“enterprise”,pendo_tracking=“detailed”,tower_url_base=“https://yossarian:8043”,tower_version=“4.0.0-372-ge78ef8238”}