Wednesday, October 13, 2010

How to find the exact instance with session id in Weblogic cluster using curl or lynx

Suppose we have 90 weblogic app server instances running behind the load balancers and AKAMAI.
If a user faces an error/exception in one scenario. If we have the user session id (For example: xGGwM2Hpq0lhCr!-1529204333)
Note: For each server we will have jvm id. The part after delimeter !- is jvmid or serverid which will not be changed until server restarts.

To find the exact server so that we directly jump to exact logs. Instead of going through all 90 instances.
Using lynx - findhost.sh
#!/bin/bash
# Iterate through each host
for i in {20..109};
do
  # get jvmid or server id the part after delimeter !- in session id
  jvmid=$(lynx -dump -head http://host$i:7001/business/ | grep -i session  | sed 's/^.*!\|^.*-\|;.*//g')
  echo "p2pre1c$i : $jvmid"
done
or
Using curl - findhost.sh
#!/bin/bash
# Iterate through each host
for i in {20..109};
do
  # get jvmid or server id the part after delimeter !- in session id
  jvmid=$(curl --head --silent http://host$i:7001/business/ | grep -i session  | sed 's/^.*!\|^.*-\|;.*//g')
  echo "p2pre1c$i : $jvmid"
done

Explanation:
curl --head  and lynx -dump -head
will dump the headers which will have session id
For example:
# lynx -dump -head http://host20:7001/business/
HTTP/1.1 200 OK
Cache-Control: no-cache="set-cookie"
Connection: close
Date: Thu, 14 Oct 2010 00:20:18 GMT
Content-Type: text/html; charset=UTF-8
X-ATG-Version: version=QVRHUGxhdGZvcm0vOS4xIFsgRFBTTGljZW5zZS8wIEIyQkxpY2Vuc2Uv
MCAgXQ==
Set-Cookie: DSESSIONID=FnHsM2MCR3ZpJj!233685404; path=/
Set-Cookie: browserid=A001287015618072FnHsM2MCR3ZpJj!233685404!1287015618064; d
omain=.wireless.att.com; expires=Friday, 14-Oct-2011 00:20:18 GMT; path=/
Set-Cookie: cust_type=b2b; domain=.wireless.att.com; expires=Thursday, 21-Oct-2
010 00:20:18 GMT; path=/
X-Powered-By: Servlet/2.5 JSP/2.1

$ ./findhost.sh
host20 : 233685404
host21 : 2060847712
host22 : 447882153
host23 : 1405278242
host24 : 2099132956
...

If user sessionid is FnHsM2MCR3ZpJj!233685404
the instance serving the above user session is host20.

No comments:

Post a Comment