Continuous display of top CPU processes

When you have to monitor which processes consume router's CPU over a period of time, a Tcl script that emulates the Unix top command might come handy. Download it, install it and enjoy the view :)

If anyone has discovered a reliable technique that detects a keypress event (= character available on stdin) in the Tcl loop, please let me know. The Ctrl/C solution is a kludge.

You can find more Tclsh-related information in the Tclsh on Cisco IOS tutorial. Sample Tclsh scripts are available in the Tclsh script library. If you need expert help in planning, developing or deploying Tclsh scripts in your network, contact the author.

10 comments:

  1. Ivan, in latest IOS (12.2(33)SRC) you can use the "monitor" keyword in various show commands to accomplish the same thing: monitor something continuously.

    router#sh proc cpu monitor interval 5


    But i always enjoy your tcl (& eem) approaches ;)

    ReplyDelete
  2. @Tassos: I've only found the "monitor" keyword in the "show proc cpu" and "show int" command. Check with show parser dump exec | inc show.*[a-z]+.*monitor interval.

    ReplyDelete
  3. Tassos,
    I can't find anything like monitor interval in my routers.. :)

    Mr Ivan,
    Well, I would love to replace your show process command with this

    set lines [split [exec "show process cpu sorted $arg | exc 0.00%__0.00%__0.00% "] "\n"];

    This way you can list only the process being used for Router instead of all (long list)

    ReplyDelete
  4. @Ivan : I guess "various" got interpreted as more than 2 ;)
    At least these 2 commands are the most used when referring to a continuous "show" operation.

    @massood, you need the latest 12.2(31)SB or 12.2(33)SRC to see it. Not all platforms support these releases.

    ReplyDelete
  5. You're absolutely right ... various could also mean two :))

    I learn something new every day ;)

    ReplyDelete
  6. "terminal exec prompt timestamp" is also interesting to know the CPU utilization each time a command is typed.

    ReplyDelete
  7. Tassos, does the <show> have any impact on the routers performance?</show>

    ReplyDelete
  8. Ivan, your script is very useful - I've been using it on 12.4(12c). But on 15.0(1r)M9 it does not clear the screen. If I execute "terminal international" and "terminal escape 3" BEFORE I start the script than it's ok. Any idea why?

    Also, if numbers under "Invoked" get too big the lines wrap so I modified output to:

    ...
    set curline [lindex $lines $lc];
    # if { [string length $curline] > 0 } { puts "$curline"; }
    set cutline "[string range $curline 0 78]"
    if { [string length $curline] > 0 } { puts "$cutline"; }
    ...

    Hope you don't mind :)

    ReplyDelete
  9. Ivan Pepelnjak10 June, 2011 16:31

    The "terminal international" command is needed to enable router to send the escape character (chr(27)) as one character, not as ^[ sequence.

    ReplyDelete

You don't have to log in to post a comment, but please do provide your real name/URL. Anonymous comments might get deleted.

Ivan Pepelnjak, CCIE#1354, is the chief technology advisor for NIL Data Communications. He has been designing and implementing large-scale data communications networks as well as teaching and writing books about advanced technologies since 1990. See his full profile, contact him or follow @ioshints on Twitter.