Building network automation solutions

9 module online course

Start now!

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.


  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 ;)
  2. Thanks mate, Cool :)
  3. @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.
  4. 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)
  5. @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.
  6. You're absolutely right ... various could also mean two :))

    I learn something new every day ;)
  7. "terminal exec prompt timestamp" is also interesting to know the CPU utilization each time a command is typed.
  8. Tassos, does the <show> have any impact on the routers performance?</show>
  9. 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 :)
  10. The "terminal international" command is needed to enable router to send the escape character (chr(27)) as one character, not as ^[ sequence.
Add comment