vmstat [pamam1] [param2]
shows the server statics along with swap space, cache,io and cpu utilization.
this stats are shown [param2] number of times with [param1] duration in between.
top
this command also shows the server statistics in detail with
contribution from each process.
This also shows the memory used,cpu utilization and command used for each thread.
finger
Shows the user who are currently logged into the node.
Friday, August 1, 2008
Some useful unix commands i came across today
Simplest way to Configure Logging using Log4j
Ensure the log4j.jar & log4j.properties are in the classpath
Add the following into the required classes where logging is needed , so that log shows file name for each logger statement .
private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger([classname].class);
folowed by logger.[info,debug,error,fatal etc]("logger message");
Contents in Log 4j.properties
log4j.rootLogger=ON, ROOT[enabling the root logger]
log4j.appender.ROOT=org.apache.log4j.DailyRollingFileAppender[saving logs on the daily basis with date appended]
log4j.appender.ROOT.File=/a/b/c.log[root log file path]
log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout
log4j.appender.ROOT.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss } %-5p [%t] %c{2} - %m%n [pattern for display in each line]
#FILE APPENDER [another logger file ]
log4j.appender.F2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.F2.File=/a/b/d.log
log4j.appender.F2.layout=org.apache.log4j.PatternLayout
log4j.appender.F2.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss } %-5p [%t] %c{2} - %m%n
log4j.logger.org.apache=ERROR[apache specific errors to be shown on both logger files]
log4j.logger.com.example=DEBUG,F2[for com.example modules debug status messages to be shown in second logger file]
For Log4j debugging
Append -Dlog4j.debug in JAVA_OPTS in catalina.sh which will enable detailed logs in catalina.out showing the logger configerations.
Thursday, July 31, 2008
Apache Basics
Apache Restart
sudo /etc/rc.d/init.d/httpd restart
All requests with port :8080 are caught by tomcat as apache is listening at port 80
requests without ports are heard by apache which listens at port 80 and later redirects through 8009
Directory Structure
etc/httpd/
conf/ conf.d/ logs/ modules/ run/
conf/
httpd.conf ssl.crl ssl.crt ssl.csr ssl.key ssl.prm workers.properties
conf.d/
authz_ldap.conf jk.conf perl.conf php.conf python.conf README ssl.conf webalizer.conf welcome.conf
1. etc/httpd/conf/httpd.conf
Attributes include
DocumentRoot "/home/partyaccount/website/htdocs"
DirectoryIndex index.jsp index.html inde
DefaultType text/plain
ErrorLog logs/error_log
AddEncoding x-compress Z
ErrorDocument 500 "The server made a boo boo."
2. worker/properties
worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
[uri:/ws/*]
worker=ajp13:localhost:80
3. etc/httpd/conf.d/jk.conf
worker assighnments with respective .jsp,.html etc
4. etc/httpd/conf.d/ssl.conf
will have virtual hosts configured here ex:pa112 etc
document root
server admin
servername
Rewrite rules per vhost klike
RewriteEngine on
RewriteRule ^(.*)/.jsp$ $1.do [L]
Friday, July 25, 2008
Overwriting Struts Resouce Bundle Handling
Care needs to be taken when we overwrite the struts resource bundle handling,especially while overwriting the get text method in struts
This is because , if the customised gettext copies this statment
ResourceBundle bundle = LocalizedTextUtil.findResourceBundle(bundleName, resourceLocale);
where bundlename is the bundle in which property is expected
and if the property does not exist in that bundle, Struts internally looks for the entire set of bundles and searches the key. This is not what is expected
and it consumes a lot of time for each literal check and chokes the server.
A quick fix to this would be to search for the expected bundle and then check if the key which is expected is present.This can be done by using bundle.containskey() and later if it exists then by using the above statement. This reduces a lot of time wasted checking for the entire set of bundle for each property.
Your Kit : A CPU and memory Java Profiler
This is a simple kit with 15 day trial period licence which can be got from http://www.yourkit.com/.
It has both windows and linux versions.For the linux version just copy the
1. copy the libyjpagent.so into tomcat/bin
2. set the path by typing export LD_LIBRARY_PATH=/tomcat/bin
3. Add -agentlib:yjpagent to Tomcat JVM startup params as
JAVA_OPTS=" -agentlib:yjpagent -server -Xms512m -Xmx768m ......" in catalina.sh
To connect for the same from Windows
1 Install the windos version
2 Click on connect remotely . Enter the ip of the profiling machine
3 This gives most of the stats. For time wise distibution of thread on the running methods
click start profiling.
It also gives snapshots for the required time duration.
Wednesday, July 23, 2008
Adding Logger interceptor in Struts
When i had a requirement to add user name and session id to every logger statement for debugging purposes i did not think it would be so easy. I came across sites which suggested adding some extra modules and configurations into the log4j.
But i realized there was a much simpler way which was to modify the thread name appending application specific user name and session id into it. As anyways log4j will print the thread name at every logger statement . Thus with minimal changes my cause was served. I added this functionality into every request by making it as a interceptor and adding it into the basic stack.
I have attached the interceptor code for reference.
Tasks get easy when seen for different perspectives.
Friday, April 18, 2008
Sample WorkFlow Engine Using Enhydra Shark - Struts 2
You can download the sample code(Unzip the war) from
http://www.esnips.com/doc/2d2cc8a2-d336-454b-bb76-5950a22714b9/Enyhydra
.jpg)