Check diff for PFE drops – Multiple Devices

Motivation:

Many times we conclude path – which looks problematic but it takes immense time to narrow down that problem to Device and FPC. Some times even after knowing device, due to high number of FPCs – it is difficult to narrow down FPC. With this python program – we are login into list of devices and check for diff of pfe statistics drops and that to at same time with multithreading support.

Below is github link, to retrieve this program and explanation of functions. – please provide comments and suggest if any betterment needed.

github link for multithreaded_diff_pfediscard_list.py

fediscard:

Input: Device Pointer  (dev) and Online FPC list (fpclist)
Output: Array of each fpcs - Fabric Drops, Bad Route discard, Data Error, Timeout Discard, Truncated Key Discard, Bit-to-test Discard, Stack Underflow, Stack Overflow, Next-Hop Discard, Invalid IIF Error, Info Cell Discard, Input Checksum, Output MTU Errors
def fediscard(dev,fpclist):
 fpcs_fdiscard = []
 fpcs_brdiscard = []
 fpcs_derror = []
 fpcs_tdiscard = []
 fpcs_tkdiscard = []
 fpcs_bttdiscard = []
 fpcs_sudiscard = []
 fpcs_sodiscard = []
 fpcs_nhdiscard = []
 fpcs_iidiscard = []
 fpcs_icdiscard = []
 fpcs_ichecksum = []
 fpcs_omtu = []
 for num in fpclist:
 fpc_lxml_elements = dev.rpc.get_pfe_statistics(fpc=num)
 string = etree.tostring(fpc_lxml_elements)
 dom = parseString(string)
 #pfehwdiscard = dom.getElementsByTagName("pfe-hardware-discard-statistics")
 #for var in pfehwdiscard:
 fdiscard = int(dom.getElementsByTagName("fabric-discard")[0].firstChild.data)
 brdiscard = int(dom.getElementsByTagName("bad-route-discard")[0].firstChild.data)
 derror = int(dom.getElementsByTagName("data-error-discard")[0].firstChild.data)
 tdiscard = int(dom.getElementsByTagName("timeout-discard")[0].firstChild.data)
 tkdiscard = int(dom.getElementsByTagName("truncated-key-discard")[0].firstChild.data)
 bttdiscard = int(dom.getElementsByTagName("bits-to-test-discard")[0].firstChild.data)
 sudiscard = int(dom.getElementsByTagName("stack-underflow-discard")[0].firstChild.data)
 sodiscard = int(dom.getElementsByTagName("stack-overflow-discard")[0].firstChild.data)
 nhdiscard = int(dom.getElementsByTagName("nexthop-discard")[0].firstChild.data)
 iidiscard = int(dom.getElementsByTagName("invalid-iif-discard")[0].firstChild.data)
 icdiscard = int(dom.getElementsByTagName("info-cell-discard")[0].firstChild.data)
 ichecksum = int(dom.getElementsByTagName("input-checksum")[0].firstChild.data)
 omtu = int(dom.getElementsByTagName("output-mtu")[0].firstChild.data)
 fpcs_fdiscard.append(fdiscard)
 fpcs_brdiscard.append(brdiscard)
 fpcs_derror.append(derror)
 fpcs_tdiscard.append(tdiscard)
 fpcs_tkdiscard.append(tkdiscard)
 fpcs_bttdiscard.append(bttdiscard)
 fpcs_sudiscard.append(sudiscard)
 fpcs_sodiscard.append(sodiscard)
 fpcs_nhdiscard.append(nhdiscard)
 fpcs_iidiscard.append(iidiscard)
 fpcs_icdiscard.append(icdiscard)
 fpcs_ichecksum.append(ichecksum)
 fpcs_omtu.append(omtu)
 return fpcs_fdiscard,fpcs_brdiscard,fpcs_derror, fpcs_tdiscard, fpcs_tkdiscard, fpcs_bttdiscard, fpcs_sudiscard, fpcs_sodiscard, fpcs_nhdiscard, fpcs_iidiscard, fpcs_icdiscard, fpcs_ichecksum, fpcs_omtu

onlinefpcs:

Input: Device Pointer
Output: Array of Online FPCs
def onlinefpcs(dev):
 fpc_lxml_elements = dev.rpc.get_fpc_information()
 string_fpc = etree.tostring(fpc_lxml_elements)
 dom_fpc = parseString(string_fpc)
 cms = dom_fpc.getElementsByTagName("fpc")
 print 'Number of FPCs Sloat', len(cms)
 fpcsloat = []
 for cm in cms:
 state = str(cm.getElementsByTagName("state")[0].firstChild.data)
 fpcsn = cm.getElementsByTagName("slot")[0].firstChild.data
 fpc = re.match(r"Online", state)
 if fpc:
 fpcsloat.append(str(fpcsn))
 return fpcsloat

checkfedrops_devices:

Input: Dev Pointer,iteration and Wait time
Output: Print FE discard diff for each FPC for list of devices
print "Function been called %sdev" %(dev)
 dev = Device(host=dev.strip(), user="labroot", passwd="lab123")
 try:
 dev.open()
 warnings.filterwarnings('ignore')
 except Exception, e:
 print "Unable to connect to host:", e
 ts = time.time()
 st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
 print st 
 fpclist = onlinefpcs(dev)
 for count in xrange(iteration):
 print "Collecting first set of data %s" % (dev)
 fpcs_fdiscard,fpcs_brdiscard,fpcs_derror, fpcs_tdiscard, fpcs_tkdiscard, fpcs_bttdiscard, fpcs_sudiscard, fpcs_sodiscard, fpcs_nhdiscard, fpcs_iidiscard, fpcs_icdiscard, fpcs_ichecksum, fpcs_omtu = fediscard(dev,fpclist)
 print "Sleeping for %s second on device %s" % (wait,dev)
 time.sleep(wait)
 print "Collecting second set of data %s" % (dev)
 fpcs_fdiscard2,fpcs_brdiscard2,fpcs_derror2, fpcs_tdiscard2, fpcs_tkdiscard2, fpcs_bttdiscard2, fpcs_sudiscard2, fpcs_sodiscard2, fpcs_nhdiscard2, fpcs_iidiscard2, fpcs_icdiscard2, fpcs_ichecksum2, fpcs_omtu2 = fediscard(dev,fpclist) 
 i=0
 for fpc in fpclist:
 diff_fdiscard = fpcs_fdiscard2[i] - fpcs_fdiscard[i]
 diff_brdiscard = fpcs_brdiscard2[i] - fpcs_brdiscard[i]
 diff_derror = fpcs_derror2[i] - fpcs_derror[i]
 diff_tdiscard = fpcs_tdiscard2[i] - fpcs_tdiscard[i]
 diff_tkdiscard = fpcs_tkdiscard2[i] - fpcs_tkdiscard[i]
 diff_bttdiscard = fpcs_bttdiscard2[i] - fpcs_bttdiscard[i]
 diff_sudiscard = fpcs_sudiscard2[i] - fpcs_sudiscard[i]
 diff_sodiscard = fpcs_sodiscard2[i] - fpcs_sodiscard[i]
 diff_nhdiscard = fpcs_nhdiscard2[i] - fpcs_nhdiscard[i]
 diff_iidiscard = fpcs_iidiscard2[i] - fpcs_iidiscard[i]
 diff_icdiscard = fpcs_icdiscard2[i] - fpcs_icdiscard[i]
 diff_ichecksum = fpcs_ichecksum2[i] - fpcs_ichecksum[i]
 diff_omtu = fpcs_omtu2[i] - fpcs_omtu[i]
 if diff_fdiscard > 0:
 print "dev %s For FPC %s, Fabric Drop count increases %s" % (dev, fpc,diff_fdiscard)
 if diff_brdiscard > 0:
 print "dev %s For FPC %s, Bad Route Discard count increases %s" % (dev,fpc,diff_brdiscard)
 if diff_derror > 0:
 print "dev %s For FPC %s, Data Error count increases %s" % (dev,fpc,diff_derror) 
 if diff_tdiscard > 0:
 print "dev %s For FPC %s, Timeout Discard increases %s" % (dev,fpc,diff_tdiscard) 
 if diff_tdiscard > 0:
 print "dev %s For FPC %s, Timeout Discard increases %s" % (dev,fpc,diff_tdiscard) 
 if diff_tkdiscard > 0:
 print "dev %s For FPC %s, Truncated Key Discard increases %s" % (dev,fpc,diff_tkdiscard)
 if diff_bttdiscard > 0:
 print "dev %s For FPC %s, Bit to test Discard increases %s" % (dev,fpc,diff_bttdiscard)
 if diff_sudiscard > 0:
 print "dev %s For FPC %s, Stack Underflow Discard increases %s" % (dev,fpc,diff_sudiscard)
 if diff_sodiscard > 0:
 print "dev %s For FPC %s, Stack Overflow Discard increases %s" % (dev,fpc,diff_sodiscard)
 if diff_nhdiscard > 0:
 print "dev %s For FPC %s, Nexthop Discard increases %s" % (dev,fpc,diff_nhdiscard)
 if diff_iidiscard > 0:
 print "dev %s For FPC %s, Invalid iif Discard increases %s" % (dev,fpc,diff_iidiscard)
 if diff_icdiscard > 0:
 print "dev %s For FPC %s, Info Cell Discard increases %s" % (dev,fpc,diff_icdiscard)
 if diff_ichecksum > 0:
 print "dev %s For FPC %s, Input Checksum Drop increases %s" % (dev,fpc,diff_ichecksum)
 if diff_omtu > 0:
 print "dev %s For FPC %s, Output MTU Drop increases %s" % (dev,fpc,diff_omtu)
 i+=1
 count+=1
 dev.close()
 ts = time.time()
 st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
 print st

Class to create New thread:

Input:This function being called from main thread - where it initiates threads.
Output: It calls checkfedrops_devices based on specific device thread
class newthread (threading.Thread):
 def __init__(self,threadID,dev,nus,wait):
 threading.Thread.__init__(self)
 self.threadID = threadID
 self.dev = dev
 self.nus = nus
 self.wait = wait
 def run(self):
 checkfedrops_devices(self.dev,self.nus,self.wait)

Main Thread:

Input: Takes file name with list of devices. Have hardcoded some wait time and number of iteration - which can be modified based on need
Output: It creates thread per device listed to check for PFE Drops
if __name__ == '__main__':
 parser = argparse.ArgumentParser(description="Enter File Name for devices")
 parser.add_argument('-f', action='store',dest='devfile', help='Enter File Name for Device')
 result = parser.parse_args()
 dfile = open(result.devfile,'r')
 ts = time.time()
 st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
 print st
 nthread = 1
 nus = 1
 wait = 4
 threadfun = []
 iteration = 1
 nes = []
 for devices in dfile:
 dev = devices.strip()
 nes.append(dev)
 dfile.close()
 for ne in nes:
 thread = ne+str(nthread)
 print thread
 try:
 thread = newthread(nthread,ne,nus,wait)
 thread.start()
 except:
 print "Error: unable to start thread" 
 nthread+=1

Running Script:

% python multithread_diff_pfediscard_list.py -f devices
2016-09-12 13:12:28
a.b.c.d1
Function been called a.b.c.ddev
 p.q.r.s2
Function been called p.q.r.sdev

2016-09-12 13:12:30
2016-09-12 13:12:30
Number of FPCs Sloat 10
Collecting first set of data Device(p.q.r.s)
Number of FPCs Sloat 20
Collecting first set of data Device(a.b.c.d)
Sleeping for 4 second on device Device(p.q.r.s)
Sleeping for 4 second on device Device(a.b.c.d)
Collecting second set of data Device(p.q.r.s)
dev Device(p.q.r.s) For FPC 0, Fabric Drop count increases 95230285
dev Device(p.q.r.s) For FPC 8, Bad Route Discard count increases 2
dev Device(p.q.r.s) For FPC 9, Fabric Drop count increases 101731073
2016-09-12 13:12:37
Collecting second set of data Device(a.b.c.d)
2016-09-12 13:12:39

[insert_php]
if(function_exists(‘like_counter_p’)) { like_counter_p(‘Say WoW’); }
if(function_exists(‘dislike_counter_p’)) { dislike_counter_p(‘Any Suggestion’); }
[/insert_php]

1,835 thoughts on “Check diff for PFE drops – Multiple Devices”

  1. Проверенно на себе
    Капперы норм!
    купить прогноз на футбол
    Вот нашел сайт и просто купил,и вывел…. Да немного психанул но в плюсе!
    Суть в том что тут реально крутые Капперы и реально отвечают на вопросы!
    Не кидалово!
    Лучше самим по пробывать и убедиться!!!
    Аналитика на 80%

  2. Выездной мобильный шиномонтаж в Москве и МО круглосуточно!
    Мегафон: +7(495)908-97-71
    Мтс: +7(915)448-25-25
    Хранение шин.
    1. Шиномонтажные работы.
    2. Снятие секреток.
    3. Переобувка шин.
    4. Ремонт проколов и порезов.
    Выездной шиномонтаж 24 часа в Москве и МО.
    Звоните!

  3. It is quite fabulous that today I was looking for something to give me a put of happiness. The weird hang-up is that I found it in the firstly place. I was struggling to pocket folding money to get by my tear paid, and I could not somebody revealed what to do. Some friends gave me a scattering special options, but I alleviate was not dedicated to those solutions. No matter how, I at long last figured in that I just needed to return a look at this website to resolve all my problems: find out more

  4. It is quite amazing that today I was looking for something to submit me a put of happiness. The grotesque thing is that I set up it in the win initially place. I was struggling to pocket money to get my tear paid, and I could not representation forbidden what to do. Some friends gave me a few different options, but I noiseless was not dedicated to those solutions. However, I for good figured in that I just needed to return a look at this website to above all my problems: http://www.paydayloansonlinekey.com/

  5. It is wholly remarkable that today I was looking seeing that something to give me a jerk of happiness. The spooky gadget is that I bring about it in the senior place. I was struggling to get money to get by my hire paid, and I could not somebody forbidden what to do. Some friends gave me a occasional other options, but I still was not dedicated to those solutions. Anyhow, I at long last figured out that I righteous needed to return a look at this website to above all my problems: payday loans online

  6. Door Repair
    Are you looking for a Toronto & the GTA door service company near you? We are your trusted door and locksmith experts that you can count on. If you have a new door that needs installation or if you have a problem with your door and lock from a break-in, we will fix it on the spot. Our specialist provides a valuable and affordable service to our commercial and residential customers and offers a 1-year industry standard manufacturer warranty on any of our hardware products.

  7. Door Repair
    Are you looking for a Toronto & the GTA door service company near you? We are your trusted door and locksmith experts that you can count on. If you have a new door that needs installation or if you have a problem with your door and lock from a break-in, we will fix it on the spot. Our specialist provides a valuable and affordable service to our commercial and residential customers and offers a 1-year industry standard manufacturer warranty on any of our hardware products.

  8. The misery that see post allergic reactions can trigger is something with Extra resources which untold numbers of people are familiar with. The truth is, nevertheless, that there are solutions available for those who seek them. Start making use of the ideas and tips in this item, and you will certainly have the devices essential to dominate allergies, once and for all.
    Screen plant pollen projections and also plan accordingly. Several of the preferred weather forecasting websites have actually a section devoted to allergy projections consisting of both air quality as well as pollen counts if you have accessibility to the web. On days when the matter is mosting likely to be high, maintain your home windows closed and restrict your time outdoors.
    Pollen, dust, as well as other allergens can get entraped on your skin and also in your hair as you go with your day. If you normally bath in the morning, take into consideration changing to a night schedule.