def GetStatsPy( getStatsBy='Flow Statistics', csvFile=None, csvEnableFileTimestamp=False): ''' Description: This API will return you a Python Dict of all the stats based on your specified stats. The exact stat name could be found on your IxNetwork GUI statistic tablets. Parameters: getStatsBy = The exact name of the stat that could be found on the IxNetwork GUI. csvFile = The name of the CSV file that you want to store stats in. csvEnableFileTimestamp = Append a timestamp to the CSV file so they don't get overwritten. This should only be used for getting the final stat result such as when the traffic has completely stopped. getStatsBy options (case sensitive): "Port Statistics" "Tx-Rx Frame Rate Statistics" "Port CPU Statistics" "Global Protocol Statistics" "Protocols Summary" "Port Summary" "OSPFv2-RTR Drill Down" "OSPFv2-RTR Per Port" "IPv4 Drill Down" "L2-L3 Test Summary Statistics" "Flow Statistics" "Traffic Item Statistics" ''' viewList = ixNet.getList(ixNet.getRoot()+'/statistics', 'view') statViewSelection = getStatsBy try: statsViewIndex = viewList.index('::ixNet::OBJ-/statistics/view:"' + getStatsBy +'"') except Exception, errMsg: sys.exit('\nNo such statistic name: %s' % getStatsBy) # ::ixNet::OBJ-/statistics/view:"Flow Statistics" view = viewList[statsViewIndex] columnList = ixNet.getAttribute(view+'/page', '-columnCaptions') #print '\n', columnList if csvFile != None: import csv csvFileName = csvFile.replace(' ', '_') if csvEnableFileTimestamp: import datetime timestamp = datetime.datetime.now().strftime('%H%M%S') if '.' in csvFileName: csvFileNameTemp = csvFileName.split('.')[0] csvFileNameExtension = csvFileName.split('.')[1] csvFileName = csvFileNameTemp+'_'+timestamp+'.'+csvFileNameExtension else: csvFileName = csvFileName+'_'+timestamp csvFile = open(csvFileName, 'w') csvWriteObj = csv.writer(csvFile) csvWriteObj.writerow(columnList) startTime = 1 stopTime = 30 for timer in xrange(startTime, stopTime + 1): totalPages = ixNet.getAttribute(view+'/page', '-totalPages') if totalPages == 'null': print 'GetStatView: Getting total pages for %s is not ready: %s/%s' % (getStatsBy, startTime, stopTime) time.sleep(2) else: break row = 0 statDict = {} print '\nPlease wait for all the stats to be queried ...' for currentPage in xrange(1, int(totalPages)+1): ixNet.setAttribute(view+'/page', '-currentPage', currentPage) ixNet.commit() whileLoopStopCounter = 0 while (ixNet.getAttribute(view+'/page', '-isReady')) != 'true': if whileLoopStopCounter == 5: print'\nGetStatView: Could not get stats' return 1 if whileLoopStopCounter < 5: print'\nGetStatView: Not ready yet. Waiting %s/5 seconds ...' % whileLoopStopCounter time.sleep(1) whileLoopStopCounter += 1 pageList = ixNet.getAttribute(view+'/page', '-rowValues') totalFlowStatistics = len(pageList) for pageListIndex in xrange(0, totalFlowStatistics): rowList = pageList[pageListIndex] if csvFile != None: csvWriteObj.writerow(rowList[0]) for rowIndex in xrange(0, len(rowList)): row += 1 cellList = rowList[rowIndex] statDict[row] = {} # CellList: ['Ethernet - 002', 'Ethernet - 001', 'OSPF T1 to T2', '206.27.0.0-201.27.0.0', 'OSPF T1 to T2-FlowGroup-1 - Flow Group 0002', '1225', '1225', '0', '0', '0', '0', '0', '0', '156800', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '00:00:00.781', '00:00:00.849'] index = 0 for statValue in cellList: statDict[row].update({columnList[index]: statValue}) index += 1 if csvFile != None: csvFile.close() return statDict