Wednesday, July 23, 2014

Capturing network packets using "tcpdump"

tcpdump is used for packet analyzer which allows the user to intercept and display TCP/IP and other packets being transmitted or received over a network to which the computer is attached.

Installation of tcpdump on Solaris/Linux:
   pkgutil is similar utility for Solaris compared to yum in Linux and apt-get in Ubuntu.
First let's install pkgutil using following command:
   /usr/sfw/bin/wget http://mirror.opencsw.org/opencsw/pkgutil.pkg
   pkgutil install at /opt/csw/bin/pkgutil on Solaris

Use below command to install tcpdump on Solaris:
pkgutil -i coreutils [This installs tcpdump at /usr/sbin/tcpdump]


Usage of tcpdump:
    tcpdump -w [output-file]  -i  [physical-interface] port [port]
    I noticed that capturing of the packets is only limited to 96 bytes. Checking manual of tcpdump I found that there is an option to disable the 96 bytes limitation by using the option "-s 0".  
Use the following command to capture 65535 bytes of packets.
    tcpdump -w [output-file] -i [physical-interface] port [port] -s 0

Example: tcpdump -w p001.pcap -i eth0 port 8080 -s 0
The above command captures any packet transfered on "physical-interface" on port 8080.

Analysis:
   The output file can be analyzed using "Wireshark" GUI application available for free.

Friday, April 18, 2014

Taking Thread Dumps At Regular Interval From CLI In Unix

Good to see posting some article on my blog after a long gap :)

Today I will explain on a very simple but important area needed for performance monitoring and analysis. This article is related to thread dump collection during performance execution in unix.

Topic: "How to collect thread dumps from CLI in Unix at regular interval"

Uuh... looks very simple post.. isn't it...!!! YES IT IS...

Use below command to capture thread dumps every 5 min:
nohup ./get_jstack  [Output-Log-Dir]  300  > /dev/null 2>&1 &

Now let's see what are the content of "get_jstack" file:

#!/bin/bash
LOGDIR=$1
WAIT=$2
mkdir $LOGDIR/serverjstack; mkdir $LOGDIR/muxjstack; mkdir $LOGDIR/wdjstack;
i=1
while [ $i -gt 0 ]
do
   PID1=`cat $LOGDIR/xmppd.pid`
   /usr/jdk/latest/bin/jstack $PID1 > $LOGDIR/serverjstack/jstack$i
   PID2=`cat $LOGDIR/mux.pid`
   /usr/jdk/latest/bin/jstack $PID2 > $LOGDIR/muxjstack/jstack$i
   PID3=`cat $LOGDIR/wd.pid`
   /usr/jdk/latest/bin/jstack $PID3 > $LOGDIR/wdjstack/jstack$i
    sleep $WAIT
    echo $i
    i=`expr $i + 1`
done

Make sure you provide the absolute path of jstack file. serverjstack, muxjstack and wdjstack are the folders for 3 processes which are running on the unix machine. 

here you go.. jstack will be created in the folder that you pass from command line. 
Enjoy Analyzing Thread Dumps For Performance Bottlenecks...

More to come soon.... :)