Getting top 50 devices with most clients using Meraki API

Za
New here

Getting top 50 devices with most clients using Meraki API

Hi there,

As the title suggests, I am trying to pull the top 50 devices with most clients in our organization, using the Meraki API with Python. I've been trying to iterate through every device, find the number of clients (with the code as follows)

len(dashboard.devices.getDeviceClients(serial))

and then add it to a dictionary where the key is a serial number and this the number of clients is the key.

 

However, our organization is quite large and so this code (specifically the line I pasted above) takes a very long time to run and present my results.

 

I was wondering if there's any way to speed up this process?

Thanks!

4 Replies 4
sungod
Kind of a big deal

If you use the async IO version of the library to run the API call on all devices 'at once' (not really at once, there's rate limiting) you should see a significant speed up.

 

I've got scripts getting stats this way across hundreds of networks, thousands of Meraki devices, and getting end-user device data usage for tens of thousands of clients,

 

It's way faster than iterating through one by one. I do wrap the calls in some extra detect/back-off/retry as the built-in rate limit detect and retry is not always enough.

 

Bear in mind that Python itself is not the fastest - the same scripts run on a powerful server go a lot faster than the Macbook Pro I develop on, even though the server has much slower Internet access - so another option is develop using something that'll go faster (but maybe lacking the ease of Python.)

LearningIsFun
Getting noticed

Would you be willing/able to share some of your scripts as examples?  I would love to learn more on the async processes.  Feel free to direct message if needed.  Thanks!

sungod
Kind of a big deal

Best place to start is probably the examples on github, for instance...

 

https://github.com/meraki/dashboard-api-python/blob/master/examples/aio_org_wide_clients_v1.py

 

This is the line that sets off running the function on all networks at once...

 

 

networkClientsTasks = [listNetworkClients(aiomeraki, folder_name, net) for net in networks]

 

 

Then in that function, this is the API call being made...

 

# Get list of clients on network, filtering on timespan of last 14 days
clients = await aiomeraki.networks.getNetworkClients(
    network["id"],
    timespan=60 * 60 * 24 * 14,
    perPage=1000,
    total_pages="all",
)

 

 

 

PhilipDAth
Kind of a big deal
Kind of a big deal

I'm with @sungod , using asyncio will be substantially faster.

https://github.com/meraki/dashboard-api-python#asyncio 

Get notified when there are additional replies to this discussion.