Gathering Troubleshooting Data Every N Seconds in Junos
First, this is not the way I would approach this task. My preferred approach is a programmatic, but sometimes you just don’t have access to the things you need (or you don’t yet have the necessary skills). Maybe you just need something now instead of spending time hacking up a Python or Ruby script.
Neat FreeBSD Shell Trick
Here’s something you might now have known. I sure didn’t until I decided I wanted to write this post and find the way to make it happen without a programmatic approach.
You know how you type
cli to start the Junos shell when you’re in the FreeBSD
shell? Did you know you can pass arguments to it? Check it out!
Let’s take it a step farther and (crudely) parse the output:
Now, there are obviously much better ways to get this type of information, but there are some things for which SNMP just isn’t a fit (or it’s too painful to parse).
What other interesting things can we do? How about getting the input rate of an interface every five seconds for 30 seconds?
You can’t see it here because this is a non-live lab, but rest assured that it works (try for yourself!).
There’s some overhead in this, so it won’t be entirely accurate. There are other commands (cprod, for example) but their syntax isn’t publicly documented.
Going a Step Further
With the knowledge we know have, we can implement a script such as this:
Create that file and SCP it to the target machine (or create it manually using
vi if you are comfortable with doing so). I named my script
to run the script, I type
sh get_rates xe-2/0/0. Here’s an example:
With this, you should be able to go forth and conquer!
Extra: The Programmatic Way
You can programmatically obtain this data, too. Below are two scripts, one in Ruby, and one in Python, that accomplish the same task with significantly more accuracy with regards to the original requirements.
The Ruby Way
This code could definitely be cleaned up. It’s very sloppy, and uses
ARGVinstead of something nicer like
trollop. You’ll also need the
The Python Way
If the Ruby code seems a bit more verbose, that’s because it is. I parameterized a bit more in the Ruby script than in the Python script.
I tried to maintain a decent amount of feature parity between everything without going overboard. The examples above are all extremely quick and didn’t take much though. I probably could have done a much better job, but I’ll leave refinement as an exercise to the reader (I’m lazy).
I hope this was at least moderately informative. Drop me a line if you have any questions.
This post is part of the #30in30 challenge.