Tuesday, November 2, 2010

How to Set up The Grinder 3 for Load Testing

Basic Requirement
  1. Download and install Jython
  2. Install Jython by running this command:
    java -jar jython_installer-2.5.1.jar

How to Start The Grinder

  1. Create a grinder.properties file. (You could simply copy from grinder/examples/grinder.properties.)
  2. Set CLASSPATH to include grinder.jar
  3. Start the Console:
        java net.grinder.Console
    
  4. For each test machine, do Steps 1 and 2, and then start the Agent process:
        java net.grinder.Grinder [grinder.properties]
    
If you are getting this warning message: "can't create package cache dir", make changes to grinder.properties to look like this:
    grinder.jvm.arguments: -Dpython.cachedir=/tmp

Use command line for developing

Edit grinder.properties with these settings:
    grinder.runs = 1
    grinder.useConsole = false

TCPProxy

To find out the default proxy settings in TCPProxy:
$ export CLASSPATH=/opt/grinder/lib/grinder.jar

$ java net.grinder.TCPProxy
12/7/10 2:02:58 PM (tcpproxy): Initialising as an HTTP/HTTPS proxy with the
parameters:
   Request filters:    EchoFilter
   Response filters:   EchoFilter
   Local address:      localhost:8001
12/7/10 2:02:58 PM (tcpproxy): Engine initialised, listening on port 8001

Now, set your browser to use proxy with the above port settings.

To start the TCPProxy Console:
$ java net.grinder.TCPProxy -console -http > grinder.py

Sunday, October 10, 2010

Analyse Disk Activities in Linux

To see disk activities, you can simply issue this command:
# e.g. on /dev/sda
$ cat /sys/block/sda/stat
626485464 806972148 28053848010 1557001361 853157995 3445307000 34392097768 2090234158        0 444939685 3653907428

Using iostat:
# Display every 5 seconds
$ iostat -xm -d 5

# Display on one disk
$ iostat -p /dev/sda -d 5

Sunday, October 3, 2010

Helpful Diagnostic Non-Responsive Server Comandlines

How many HTTP connections?
$ netstat -n | grep :80 | wc -l

How many HTTPS connections?
$ netstat -n | grep :443 | wc -l

How many connections are from an IP?
$ netstat -n | grep XXX.XXX.XXX.XXX

Monday, September 20, 2010

Bash if

Syntax

if [ <condition expression> ]
then
<commands>
elif [ <condition expression> ]
then
<commands>
else
<commands>
fi
One liner
if [ <condition expression> ]; then <commands>; fi
Variations
[ <condition expression> ] && (<commands>)
test <condition expression> && (<command>; ... <command>; exit;)
&& means 'and' while || means 'or'.
If you invoke exit at the end of a sub-shell means it will not pass the return value back to parent shell.
Use {...} instead of (...) to avoid creating a sub-shell.

Condition expression operators

[ -a FILE ] True if FILE exists.
[ -b FILE ] True if FILE exists and is a block-special file.
[ -c FILE ] True if FILE exists and is a character-special file.
[ -d FILE ] True if FILE exists and is a directory.
[ -e FILE ] True if FILE exists.
[ -f FILE ] True if FILE exists and is a regular file.
[ -g FILE ] True if FILE exists and its SGID bit is set.
[ -h FILE ] True if FILE exists and is a symbolic link.
[ -k FILE ] True if FILE exists and its sticky bit is set.
[ -p FILE ] True if FILE exists and is a named pipe (FIFO).
[ -r FILE ] True if FILE exists and is readable.
[ -s FILE ] True if FILE exists and has a size greater than zero.
[ -t FD ] True if file descriptor FD is open and refers to a terminal.
[ -u FILE ] True if FILE exists and its SUID (set user ID) bit is set.
[ -w FILE ] True if FILE exists and is writable.
[ -x FILE ] True if FILE exists and is executable.
[ -O FILE ] True if FILE exists and is owned by the effective user ID.
[ -G FILE ] True if FILE exists and is owned by the effective group ID.
[ -L FILE ] True if FILE exists and is a symbolic link.
[ -N FILE ] True if FILE exists and has been modified since it was last read.
[ -S FILE ] True if FILE exists and is a socket.
[ FILE1 -nt FILE2 ] True if FILE1 has been changed more recently than FILE2, or if FILE1 exists and FILE2 does not.
[ FILE1 -ot FILE2 ] True if FILE1 is older than FILE2, or is FILE2 exists and FILE1 does not.
[ FILE1 -ef FILE2 ] True if FILE1 and FILE2 refer to the same device and inode numbers.
[ -o OPTIONNAME ] True if shell option "OPTIONNAME" is enabled.
[ -z STRING ] True of the length if "STRING" is zero.
[ -n STRING ] or [ STRING ] True if the length of "STRING" is non-zero.
[ STRING1 == STRING2 ] True if the strings are equal. "=" may be used instead of "==" for strict POSIX compliance.
[ STRING1 != STRING2 ] True if the strings are not equal.
[ STRING1 < STRING2 ] True if "STRING1" sorts before "STRING2" lexicographically in the current locale.
[ STRING1 > STRING2 ] True if "STRING1" sorts after "STRING2" lexicographically in the current locale.
[ ARG1 OP ARG2 ] "OP" is one of -eq, -ne, -lt, -le, -gt or -ge. These arithmetic binary operators return true if "ARG1" is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to "ARG2", respectively. "ARG1" and "ARG2" are integers.

Combined expressions
[ ! EXPR ] True if EXPR is false.
[ ( EXPR ) ] Returns the value of EXPR. This may be used to override the normal precedence of operators.
[ EXPR1 -a EXPR2 ] True if both EXPR1 and EXPR2 are true.
[ EXPR1 -o EXPR2 ] True if either EXPR1 or EXPR2 is true.


Ref: http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html

Differences with brackets

Using double brackets, [[...]], means:
  • If variable values is a string with spaces, it will not be splitted, so you could leave out the double quotes. So, instead of
    $ FOO="I am a foo"
    $ [ "$FOO" == "I am a foo" ] && echo "Indeed, I am a foo."
    
    you can do
    $ [[ $FOO == "I am a foo" ]] && echo "Indeed, I am a foo."
    
  • Wildcards do not expand to filenames, e.g.
    $ ls
    index.html
    $ FOO="index.*"
    $ echo $FOO
    index.html
    $ echo "$FOO"
    index.*
    $ echo '$FOO'
    $FOO
    
    Single bracket examples
    $ [ $FOO == index.html ] && echo "This is true"
    This is true
    $ [ $FOO == "index.html" ] && echo "This is true"
    This is true
    $ [ $FOO == index.* ] && echo "This is true"
    This is true
    $ [ $FOO == "index.*" ] || echo "This is false"
    This is false
    
    #c.f. this with double bracket examples
    $ [ "$FOO" == index.html ] || echo "This is false"
    This is false
    $ [ "$FOO" == "index.html" ] || echo "This is false"
    This is false
    $ [ "$FOO" == index.* ] || echo "This is false"
    This is false
    $ [ "$FOO" == "index.*" ] && echo "This is true"
    This is true
    
    Double bracket examples
    $ [[ $FOO == index.html ]] || echo "This is false"
    This is false
    $ [[ $FOO == "index.html" ]] || echo "This is false"
    This is false
    $ [[ $FOO == index.* ]] && echo "This is true"
    This is true
    $ [[ $FOO == "index.*" ]] && echo "This is true"
    This is true
    

Saturday, August 14, 2010

Useful IP commands in Linux

Display NIC's configurations:
# for all NIC's
$ ifconfig

# Just for eth0
$ ifconfig eth0

Assign an IP to a NIC:
$ ifconfig eth0 192.168.0.1

# assign multiple IPs
$ ifconfig eth0:0 192.168.0.1
$ ifconfig eth0:1 192.168.0.2

# assign subnet
$ ifconfig eth0 192.168.0.1 netmask 255.255.255.0

Disable/Enable NICs:
# enable
$ ifconfig eth0 up

# disable
$ ifconfig eth0 down

IP/hostname Lookup:
# look up hostname
$ host 192.168.0.1
# for more info
$ dig -x 192.168.0.1

# trace route
$ traceroute www.example.com

# trace path
$ tracepath www.example.com

# DNS test
$ host www.example.com

Friday, April 9, 2010

How to Prevent Files from Being Used by Other Website?

Added these lines to your .htaccess file.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?askapache.com/.*$ [NC]
RewriteRule \.(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]

Wednesday, March 10, 2010

Microsoft Office 2010 Opens for Beta Testing!

Microsoft is inviting IT professionals around the world to test Office 2010 and reflect feedbacks. This is a pre-release version of Office Professional Plus 2010, so take your pre-caution before installing.

To register and download this beta version, click here.

Make sure you have the following:
Internet access (to download Office Professional Plus 2010 Beta and get updates)

A PC with these minimum recommended specifications:
  • 500 MHz 32-bit or 64-bit processor or higher
  • 256 MB of system memory or more
  • 3.5 GB of available disk space
  • 1024x768 or higher resolution monitor
  • DVD-R/W Drive
Supported Operating Systems:
  • Windows XP with Service Pack (SP) 3 (32-bit)
  • Windows Vista with SP1 (32-bit or 64-bit)
  • Windows Server 2003 R2 (32-bit or 64-bit)
  • Windows Server 2008 with SP2 (32-bit or 64-bit)
  • Windows 7 (32-bit or 64-bit)

Friday, February 5, 2010

Keyboard Shortcuts for Google Search Results

I've always wonder why can't I navigate through the Google search result using my keyboard. There are plugins and Firefox extensions that add keyboard shortcuts to web pages but wouldn't it be nice if the webpage itself just equips this feature? Finally Google is running an experiment on this idea.

To enable Keyboard Shortcuts in Google search results, go here and be part of their experiment.

Wednesday, January 20, 2010

Initial Setup for CentOS

Set up users and groups

Create staff group with gid 123
$ /usr/sbin/groupadd -g 123 staff

Create users (with uid 1234, with user gid 123)
$ /usr/sbin/useradd -c "John Doe" -d /home/jdoe -u 1234 -s /bin/bash -g 123 jdoe

To see useradd default: $ useradd -D

Force user to change password upon login
$ passwd -e jdoe

# If not available, just expire the account by
$ chage -d0 jdoe

Add user to wheel group
# Enabled sudo for wheel group
$ visudo

# uncomment this line:
# %wheel ALL=(ALL) ALL

# Add user to wheel group
$ usermod -G10 jdoe

Set hosts.allow to allow ssh (port 22) for specific network (e.g. 123.456.789.* with subnet 255.255.255.0) and hosts.deny to deny everywhere else.
$ cat /etc/hosts.allow
#
# hosts.allow   This file contains access rules which are used to
#               allow or deny connections to network services that
#               either use the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#
sshd: 123.456.789.0/255.255.255.0

$ cat /etc/hosts.deny
#
# hosts.deny    This file contains access rules which are used to
#               deny connections to network services that either use
#               the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               The rules in this file can also be set up in
#               /etc/hosts.allow with a 'deny' option instead.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#
All:All


Disallow root login in via ssh by uncomment the following line.
$ vi /etc/ssh/sshd_config

#PermitRootLogin no

$ /etc/init.d/sshd restart