get last 30 days lost and latency

Solved
amabt
Building a reputation

get last 30 days lost and latency

I'm trying to get the last 30 days lost and latency of WAN1 on the MX. https://developer.cisco.com/meraki/api-v1/#!get-device-loss-and-latency-history


Using below give me the last day's no issue:

 

 

 

device_loss_latency_history = dashboard.devices.getDeviceLossAndLatencyHistory(serial, ip)

 

 

However trying to get the last 30 day at 60 seconds interval does not work.

 

#Get data for last 31 days
kwargs = {"timespan" : 2678400, "resolution" : 60, "uplink" : "wan1"}

device_loss_latency_history = dashboard.devices.getDeviceLossAndLatencyHistory(serial, ip, kwargs)

 

 


It's giving me error:

 

TypeError: Devices.getDeviceLossAndLatencyHistory() takes 3 positional arguments but 4 were given

 

 

Not sure how I'm meant to provide the argument?

 

The code here indicate it accepts up to 5 arguments.

https://github.com/meraki/dashboard-api-python/blob/ff7b5063a4a1be1cf61e729da36ca654b483c6f3/meraki/...

 

What am I doing wrong here?

Thanks

1 Accepted Solution
sungod
Head in the Cloud

Try...

 

device_loss_latency_history = dashboard.devices.getDeviceLossAndLatencyHistory(serial, ip, timespan=2678400, resolution=60, uplink="wan1")

 

View solution in original post

5 Replies 5
sungod
Head in the Cloud

Try...

 

device_loss_latency_history = dashboard.devices.getDeviceLossAndLatencyHistory(serial, ip, timespan=2678400, resolution=60, uplink="wan1")

 

amabt
Building a reputation

That works. Thank you.

 

In case it help others. Base on above. If I do it in this format it works.

timespan = 2678400 #Time to look back in seconds
device_loss_latency_history = dashboard.devices.getDeviceLossAndLatencyHistory(serial, ip, timespan=timespan, resolution=60, uplink="wan1")

 

Note the "timespan=timespan"

 

The paramater has to be named.

 

amabt
Building a reputation

Full working code

 

 

import meraki
import os
import pandas as pd
from datetime import datetime

"""
Script to extract the last 30 days of packet loss and latency for a Meraki Gateway device (by serial) and save to a CSV
"""

# Get environment variables API Key
API_KEY = os.getenv('MERAKI_API_KEY')

dashboard = meraki.DashboardAPI(API_KEY, output_log=False, suppress_logging=True)

serial = 'XXXX-XXXX-XXXX'  #Serial of the device we need to get the information for
ip = '8.8.8.8' #P being monitored by Meraki Dashboard
#Get data for last 31 days for wan1 with 60 seconds resolution
timespan = 2678400 #period (31 days in seconds) to get the information for. Max of 31 days.

#Get packet loss and latency history at 60 seconds resolution
device_loss_latency_history = dashboard.devices.getDeviceLossAndLatencyHistory(serial, ip, timespan=timespan, resolution=60, uplink="wan1")

#Uncomment below line to print the result to console.
#print(response_loss_latency_history)

current_time_str = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
filename = f"lost-latency-history-{serial}--{current_time_str}.csv"

#Convert to DataFrame
df_loss_latency_history = pd.DataFrame(device_loss_latency_history)

#Export it to a CSV
df_loss_latency_history.to_csv(filename, index=False, header=True)

print(f"Exported [{serial}] Packet Loss History ==> {filename}")

#Now we have a CSV file with the packet loss and latency info

 

to_excel via Pandas is a nice format as well. 
amabt
Building a reputation

Yup, you can definately do to Excell as well if that work better.

 

What would be better is being able to graph the output (using python) like how the Dashboard does it, with the higher resolution. My python skill is lacking in this area.

Get notified when there are additional replies to this discussion.
Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.