Showing posts with label eclipse. Show all posts
Showing posts with label eclipse. Show all posts

Monday, December 3, 2012

Monitoring Tomcat with VisualVM

VisualVM is great tool that you can use to monitor and profile java applications. In this post I will explain how to use VisualVM to monitor Tomcat. You should never reconfigure Tomcat memory setup without first checking where is the problem.

Installing VisualVM

Download zip from website.  Unzip content into desired directory and run visualvm.exe

Monitoring Tomcat in Eclipse

Open launch configuration of Server that you wish to monitor and to VM Arguments add:
 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false   

Now if you start Tomcat can connect to it with VisualVM.

Monitoring Tomcat as a Windows Service

You should open Configuration Editor with:
 tomcat7w.exe //MS//  
and add:
 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false   
to Java Options

Monitoring Tomcat in standalone mode

Open catalina.bat or catalina.sh (depending on the environment) and add:
 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false   
to JAVA_OPTS.

Final Comment on VisualVM

If you want to monitor common java programs from eclipse you can install VisualVM launcher in eclipse. Details are described here.

Useful links

When problems with memory arise you can debug them using next two links:
http://www.skill-guru.com/blog/2010/09/23/how-to-increase-heap-size-in-tomcat-6/
http://www.skill-guru.com/blog/2010/10/05/increasing-permgen-size-in-your-server/

Monday, November 26, 2012

Creating Tomcat application on OpenShift - Take two

So..., my first post on creating Tomcat installation on OpenShift had some "bugs". In this post I will describe better way of initializing Tomcat.

First change is that I installed client tools as instructed in this link. While installing GIT I choose using ssh2 and not Putty plink.

Second change is that I used template from GitHub  (https://github.com/lulinqing/openshift-tomcat-quickstart)

So this is the steps that I used:
  • Creating DIY application: rhc app create -a tomcat -t diy-0.1
You should be positioned in directory where you want local git repo to be.
  • Go into created directory: cd tomcat
  • Add another remote git repo: git remote add upstream -m master git://github.com/lulinqing/openshift-tomcat-quickstart.git
  • Pull changes from repo: git pull -s recursive -X theirs upstream master
After I pulled configuration I have changed file /.openshift/action_hooks/deploy. This file is script that executes every time that you push to OpenShift repo. Default script will only copy files if tomcat directory doesn't exist, I have changed script to copy complete tomcat on every git push.

/.openshift/action_hooks/deploy:
 #!/bin/bash   
 # This deploy hook gets executed after dependencies are resolved and the   
 # build hook has been run but before the application has been started back   
 # up again. This script gets executed directly, so it could be python, php,   
 # ruby, etc.   
 set -x   
 if [ -d $OPENSHIFT_DATA_DIR/tomcat ] then   
    rm -rf $OPENSHIFT_DATA_DIR/tomcat/   
 fi   
 cp -rf $OPENSHIFT_REPO_DIR/diy/tomcat $OPENSHIFT_DATA_DIR   
 cd $OPENSHIFT_DATA_DIR/tomcat   
 rm -rf logs   
 ln -s $OPENSHIFT_DIY_LOG_DIR logs   
 sed -ig 's/OPENSHIFT_APP_DNS/'$OPENSHIFT_APP_DNS'/' conf/server.xml   

I have also changed password in file tomcat-users.xml.

That's it, now you can commit changes and push them to Openshift: git push
And wait few moments to propagate changes and you can log in to your new tomcat installation.

I have created GitHub fork with my changes at https://github.com/McNullty/openshift-tomcat-quickstart so you can use this repo as remote stream if you don't want to manually change anything.

Next post will be on connecting to database, I promise :-).

Monday, November 5, 2012

Creating Tomcat application on OpenShift

OpenShift

OpenShift is JBoss Cloud solution. I like OpenShift better than Google App Engine because it provides real RDBS if you select MySQL or PostgreSQL, so you can develop simple applications that could be later transferred to some other server.
OpenShift doesn't provide Tomcat out of the box like it does for JBoss AS, PHP or Ruby, but you can install it trough DIY cartridge.

Connecting to OpenShift

Opening account on OpenShift is trivial, I used TOMCAT promo code but you can find a lot of other codes (I don't know what promo code exactly do but - whatever)
 
I have followed tutorial for installing Tomcat on OpenShift with few differences that I will describe here.
First of all, I didn't install RHC client tool because I created application using web interface and all other actions were done trough Eclipse (with git), SSH (Putty) and WinSCP.
Instructions for setting connection with Putty is described here, and WinSCP setup is almost identical.

After I confirmed my account, I opened Create Application tab and selected Do-It-Yourself web cartridge. Configuring application  name and namespace is trivial and you shouldn't have trouble there.  

Shutting Down default Ruby application

We can check what application is running with command ps x

> ps x

PID TTY STAT TIME COMMAND
4682 ? S 0:00 sshd: 6e35702606914790aaddacd6e3eeb7ca@pts/0
4683 ? Ss 0:00 /bin/bash --init-file /usr/bin/rhcsh -i
10884 ? S 0:00 sshd: 6e35702606914790aaddacd6e3eeb7ca@notty
10885 ? Ss 0:00 /usr/libexec/openssh/sftp-server
24328 ? S 0:00 ruby /var/lib/stickshift/6e35702606914790aaddacd6e3eeb7ca/app-root/runtime/repo//diy/testrubyserver.rb 127.8.212.129 /var/lib/stickshift/6e357026069147
24341 ? R+ 0:00 ps x


We can then stop running server by going into directory app-root/repo/.openshift/action_hooks and running script stop or just by killing ruby process.
./stop

Installing and configuring Tomcat

After we have stopped server this way we can continue following tutorial for installing Tomcat.

I made all changes directly trough Putty, but you should be able to do everything with Eclipse and git plugin

My start script:
#!/bin/bash
# The logic to start up your application should be put in this
# script. The application will work only if it binds to
# $OPENSHIFT_INTERNAL_IP:8080
set -x
cd ~/tomcat/data/apache-tomcat-7.0.32/
sed -ig 's/OPENSHIFT_INTERNAL_IP/'$OPENSHIFT_INTERNAL_IP'/g' conf/server.xml
bin/startup.sh


My stop script:
#!/bin/bash
# The logic to stop your application should be put in this script.
~/tomcat/data/apache-tomcat-7.0.32/bin/shutdown.sh


You can now start and stop tomcat server by going into ~/tomcat directory and running:
[tomcat-javafiend.rhcloud.com tomcat]\> ./tomcat_ctl.sh start
or
[tomcat-javafiend.rhcloud.com tomcat]\> ./tomcat_ctl.sh stop

That's it! You can start your Java fun with Tomcat!