Blogs

Scripting How-To: srx-monitor script

By Erdem posted 08-14-2015 16:18

  

Overview

This script is for performance monitoring on the SRX. This applies to SLAX version 1.0 and higher.

 

Description

 

It makes a clean table to see all the performance of the SRX.

 

Source Code

 

GitHub Links

The source code below is also available from GitHub at the following locations:

 

Example Output

01 This script is for performance monitoring on the SRX.
02  
03 It makes a clean table to see all the performance of the SRX See below:
04 root@SRX5800-1> op srx-monitor
05 Route Engine
06 Slot Mem Size Mem Used CPU Avg CPU User CPU Bkgd CPU Krnl CPU Intpt CPU Idle
07 ----------------------------------------------------------------------------
08    0    2048        15       4        0        0        4         0       96
09 SPUs
10 FPC PIC CPU Mem  Flow Sess Cur   Flow Ses Max     CP Ses Cur     CP Ses Max
11 ----------------------------------------------------------------------------
12   0   0   0  66              0              0              0        4194304
13   0   1   0  49              0         524288              0              0
14   1   0   0  49              0         524288              0              0
15   1   1   0  49              0         524288              0              0
16   2   0   0  49              0         524288              0              0
17   2   1   0  49              0         524288              0              0
18   3   0   0  49              0         524288              0              0
19   3   1   0  49              0         524288              0              0
20   4   0   0  49              0         524288              0              0
21   4   1   0  49              0         524288              0              0

SLAX Script Contents

001 /* Machine Crafted with Care (tm) by slaxWriter */ 

002 version 1.0; 

003   

004 ns junos = "http://xml.juniper.net/junos/*/junos"; 

005 ns xnm = "http://xml.juniper.net/xnm/1.1/xnm"; 

006 ns ext = "http://xmlsoft.org/XSLT/namespace"; 

007 ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0"; 

008   

009 /* 

010  * This op-script is for performance monitoring on the SRX 

011  */ 

012   

013 import "../import/junos.xsl"; 

014 var $connection = jcs:open(); 

015   

016 template monitor-fpc ($fpc-number) { 

017     var $rpc-security-monitor-fpc = <rpc> { 

018         <command> { 

019             expr "show security monitor fpc "; 

020             expr $fpc-number; 

021             expr " no-forwarding"; 

022         } 

023     } 

024     var $security-monitor-results = jcs:execute($connection, $rpc-security-monitor-fpc); 

025       

026     for-each ($security-monitor-results//spu-utilization-statistics) { 

027         var $fpc-number = ./fpc-number[1]; 

028         var $pic-number0 = ./pic-number[1]; 

029         var $spu-cpu-utilization0 = ./spu-cpu-utilization[1]; 

030         var $spu-memory-utilization0 = ./spu-memory-utilization[1]; 

031         var $spu-current-flow-session0 = ./spu-current-flow-session[1]; 

032         var $spu-max-flow-session0 = ./spu-max-flow-session[1]; 

033         var $spu-current-cp-session0 = ./spu-current-cp-session[1]; 

034         var $spu-max-cp-session0 = ./spu-max-cp-session[1]; 

035         var $pic-number1 = ./pic-number[2]; 

036         var $spu-cpu-utilization1 = ./spu-cpu-utilization[2]; 

037         var $spu-memory-utilization1 = ./spu-memory-utilization[2]; 

038         var $spu-current-flow-session1 = ./spu-current-flow-session[2]; 

039         var $spu-max-flow-session1 = ./spu-max-flow-session[2]; 

040         var $spu-current-cp-session1 = ./spu-current-cp-session[2]; 

041         var $spu-max-cp-session1 = ./spu-max-cp-session[2]; 

042         <output> { 

043             expr jcs:printf("%3d %3d %3d %3d %14d %14d %14d %14d 

044 ", $fpc-number, $pic-number0, $spu-cpu-utilization0, $spu-memory-utilization0, $spu-current-flow-session0, $spu-max-flow-session0, $spu-current-cp-session0, $spu-max-cp-session0); 

045             expr jcs:printf("%3d %3d %3d %3d %14d %14d %14d %14d 

046 ", $fpc-number, $pic-number1, $spu-cpu-utilization1, $spu-memory-utilization1, $spu-current-flow-session1, $spu-max-flow-session1, $spu-current-cp-session1, $spu-max-cp-session1); 

047         } 

048     } 

049 } 

050   

051 template get-srx-spcs () { 

052     var $rpc-show-chassis-hardware = <rpc> { 

053         <command> "show chassis hardware no-forwarding"; 

054     } 

055     var $show-chassis-hardware-results = jcs:execute($connection, $rpc-show-chassis-hardware); 

056     <output> { 

057         expr jcs:printf("%4s 

058 ", "SPUs"); 

059         expr jcs:printf("%-3s %-3jcs %-3jcs %-3jcs %14s %14s %14s %14s 

060 ", "FPC", "PIC", "CPU", "Mem", "Flow Sess Cur", "Flow Ses Max", "CP Ses Cur", "CP Ses Max"); 

061         expr jcs:printf("%-80j1s 

062 ", "--------------------------------------------------------------------------------"); 

063     } 

064     var $fpc-regex = "(FPC )([0-9]+)"; 

065       

066     for-each ($show-chassis-hardware-results//chassis/chassis-module) { 

067         if (contains(./description, "SPC")) { 

068             var $fpc-number = jcs:regex($fpc-regex, ./name); 

069               

070             call monitor-fpc($fpc-number = $fpc-number[3]); 

071         } 

072     } 

073 } 

074   

075 template get-srx-re () { 

076     var $rpc-show-chassis-routing-engine = <rpc> { 

077         <command> "show chassis routing-engine no-forwarding"; 

078     } 

079     var $show-chassis-routing-engine-results = jcs:execute($connection, $rpc-show-chassis-routing-engine); 

080     <output> { 

081         expr jcs:printf("%12s 

082 ", "Route Engine"); 

083         expr jcs:printf("%-4s %-7jcs %-7jcs %-7jcs %8s %8s %8s %9s %8s 

084 ", "Slot", "Mem Size", "Mem Used", "CPU Avg", "CPU User", "CPU Bkgd", "CPU Krnl", "CPU Intpt", "CPU Idle"); 

085         expr jcs:printf("%-80j1s 

086 ", "--------------------------------------------------------------------------------"); 

087           

088         for-each ($show-chassis-routing-engine-results//route-engine) { 

089             expr jcs:printf("%4d %7d %9d %7d %8d %8d %8d %9d %8d 

090 ", ./slot, ./memory-dram-size, ./memory-buffer-utilization,(./cpu-user + ./cpu-background + ./cpu-system+ ./cpu-interrupt) , ./cpu-user, ./cpu-background, ./cpu-system, ./cpu-interrupt, ./cpu-idle); 

091         } 

092     } 

093 } 

094   

095 match / { 

096     <op-script-results> { 

097         call get-srx-re(); 

098         call get-srx-spcs(); 

099     } 

100 } 

XML Script Contents

 
01 <?xml version="1.0"?>
02 <script>
03 <title>srx-monitor.slax</title>
04 <author>rcameron</author>
05 <synopsis>
06 This script is for performance monitoring on the SRX
07 </synopsis>
08 <coe>op</coe>
09 <type>display</type>
10  
11 <description>
12 It makes a clean table to see all the performance of the SRX
13 </description>
14  
15  <example>
16  <title>Example</title>
17  <output>example-1.output</output>
18  </example>
19  
20 <xhtml:script xmlns:xhtml="http://www.w3.org/1999/xhtml"
21 src="../../../../../web/leaf.js"
22 type="text/javascript"/>
23 </script>

#display
#SRX
#ScriptingHow-To
#Slax
#opscript
#How-To