Monitor interface traffic every five minutes

618 views
Skip to first unread message

Ajinkya Fotedar

unread,
Dec 10, 2014, 11:09:48 AM12/10/14
to junos-p...@googlegroups.com
Hello everyone,

I would like to monitor particular interfaces on our routers and display those on the console, every 5 minutes. Is there a way in PyEz that i can do this.

Something on the lines of the following:

1.
user@router> monitor interface xe-7/1/0 | display xml rpc 
    <message>
        xml rpc equivalent of this command is not available.
    </message>
    <cli>
        <banner>{master}</banner>
    </cli>
</rpc-reply>

or this:

2.
user@router> show interfaces statistics xe-7/1/0 | display xml rpc 
    <rpc>
        <get-interface-information>
                <statistics/>
                <interface-name>xe-7/1/0</interface-name>
        </get-interface-information>
    </rpc>
    <cli>
        <banner>{master}</banner>
    </cli>
</rpc-reply>


Any help appreciated. Thanks!

Rick Sherman

unread,
Dec 10, 2014, 5:26:41 PM12/10/14
to junos-p...@googlegroups.com
Hi Ajinkya,

I put together some proof of concept code for you.  Please keep in mind that this is not really production quality as it does not guarantee continuous execution, error handling, the decision to leave the connection to the device open or flapping, etc.

Long term you may want to look at something like Celery http://celery.readthedocs.org/en/latest/userguide/periodic-tasks.html

#!/usr/bin/python

from datetime import datetime

# Schedule library
from apscheduler.schedulers.blocking import BlockingScheduler

# PyEZ
from jnpr.junos import Device
from jnpr.junos.op.phyport import PhyPortStatsTable

sched = BlockingScheduler()

@sched.scheduled_job('interval', minutes=1)
def timed_job():
    dev = Device(host='dev', user='user', passwd='pass')
    dev.open()
    pst = PhyPortStatsTable(dev)    
    pst.get('ge-0/0/0')
    print "{0} - {1}".format(datetime.now(), pst.to_json())
    dev.close()
sched.start()


$python sched.py
2014-12-10 22:19:23.332000 - {"ge-0/0/0": {"rx_err_drops": 0, "rx_packets": 128285, "rx_bytes": 10211093, "tx_bytes": 17630052803, "rx_err_input": 0, "tx_packets": 94055427}}
2014-12-10 22:20:23.029000 - {"ge-0/0/0": {"rx_err_drops": 0, "rx_packets": 128629, "rx_bytes": 10230826, "tx_bytes": 17631773396, "rx_err_input": 0, "tx_packets": 94064361}}
2014-12-10 22:21:23.456000 - {"ge-0/0/0": {"rx_err_drops": 0, "rx_packets": 128793, "rx_bytes": 10244063, "tx_bytes": 17637601531, "rx_err_input": 0, "tx_packets": 94090092}}

-Rick
Reply all
Reply to author
Forward
0 new messages