Java

HowTo: Setup javameloy for watching J2EE application server activities

Posted on Updated on

Javamelody is a tool to monitor J2EE application servers, I has capability for showing real-time statistics,  I have integrated this tool with nearly 40 servers which connected with Javamelody collector server . It is the good choice for debugging and fine tunning J2EE applications by statistics history. Once you connected the java melody to an collector server it role it to collect all the data from the connected server for every 1 min. it will be avoid storing GBs of statistics data in the application server.

For more details Please check this https://code.google.com/p/javamelody/wiki/UserGuide#Introduction

I followed the given steps for deploying in Tomcat containers,

Packages:

https://javamelody.googlecode.com/files/javamelody-1.49.0.jar
https://pastockscanner.googlecode.com/files/iText-2.1.7.jar
http://sourceforge.net/projects/jrobin/files/jrobin/1.5.9/jrobin-1.5.9.1.jar/download

Installation,

1, Copy the jars to the lib dir of the applications

cp -rpf javamelody-1.49.0.jar iText-2.1.7.jar jrobin-1.5.9.1.jar <webapps>/ROOT/WEB-INF/lib

2, Modify  web.xml

cp -rpf web.xml web.xml_$(date +%F)
vi <webapps>/ROOT/WEB-INF/web.xml
<context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>
 /WEB-INF/application-context.xml
 classpath:net/bull/javamelody/monitoring-spring-datasource.xml
 </param-value>
 </context-param>
 <!--====================== Monitoring ===================================-->
 <!-- Custom CSS -->
 <filter>
 <filter-name>customResourceFilter</filter-name>
 <filter-class>net.bull.javamelody.CustomResourceFilter</filter-class>
 </filter>
 <filter-mapping>
 <filter-name>customResourceFilter</filter-name>
 <url-pattern>/monitoring</url-pattern>
 </filter-mapping>
 <!-- Monitor filter -->
 <filter>
 <filter-name>monitoring</filter-name>
 <filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
 <init-param>
 <param-name>storage-directory</param-name>
 <param-value>logs/monitoring</param-value>
 </init-param>
 <init-param>
 <param-name>url-exclude-pattern</param-name>
 <param-value>(/images/.*|/js/.*|/styles/.*)</param-value>
 </init-param>
 <init-param>
 <param-name>admin-emails</param-name>
 <param-value>first.last@example.com</param-value>
 </init-param>
 <init-param>
 <param-name>mail-session</param-name>
 <param-value>MailSession</param-value>
 </init-param>
 <init-param>
 <param-name>mail-periods</param-name>
 <param-value>week,month</param-value>
 </init-param>
 </filter>
 <filter-mapping>
 <filter-name>monitoring</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>
 <listener>
 <listener-class>net.bull.javamelody.SessionListener</listener-class>
 </listener>
<security-constraint>
 <web-resource-collection>
 <web-resource-name> monitoring URL </web-resource-name>
 <url-pattern> /monitoring/* </url-pattern>
 <http-method> GET </http-method>
 <http-method> POST </http-method>
 </web-resource-collection>
<auth-constraint>
 <!-- the same like in your tomcat-users.conf file -->
 <role-name> watcher </role-name>
 </auth-constraint>
 </security-constraint>
<login-config>
 <auth-method> BASIC </auth-method>
 <realm-name> Password please !!! </realm-name>
 </login-config>
<security-role>
 <description> </description>
 <role-name> watcher </role-name>
 </security-role>

2, Modify security.xml if needed

cp -rpf security.xml security.xml_$(date +%F)
vi  <webapps>/ROOT/WEB-INF/security.xml
<sec:http pattern="/monitoring/**" security="none"></sec:http>

3, Add the credential for basic auth

cp -rpf tomcat-users.xml tomcat-users.xml_$(date +%F)
vi $CATALIAN_HOME/conf/tomcat-users.xml
<user username="user" password="password" roles=watcher"/>

Now restart the tomcat.

URL : http://my-applicationserver.com/monitoring

This is only for those who deployed more than one Javamelody.

JavaMelody collector server installation:

Download and Deploy the collector application in the webserver

https://javamelody.googlecode.com/files/javamelody-1.49.0.war

From the browser you can see the application like below

Monitoring JavaMelody on Beijing stg2 web3 BeijingInternal

 

Name of application to monitor : Just a name to identify the application it can be any thing

eg : mywebserver1 , mywebserver2

URL(s): Valid monitoring URL without “/monitoring”, provide basic authentication if enabled.

eg : http://<username&gt;:<password>@mywebserver1.com

It can be add many javamelody instances like below:

Server

 

Advertisements

Error: /lib/ld-linux.so.2: bad ELF interpreter

Posted on Updated on

While Using java application, a common error is raised due to some missing library. I installed the below packages for fixing the error.

# yum provides */ld-linux.so.2
glibc-2.12-1.149.el6.i686 : The GNU libc libraries
Repo : base
Matched from:
Filename : /lib/ld-linux.so.2

# yum -y install glibc-2.12-1.149.el6.i686

Once the installation is over, Java is working well in the server

 

 

 

HowTo: Tomcat Logging – log customized with {X-Forwarded-For}

Posted on Updated on

Tomcat is allowing us to track back logs with enamours of information by customizing the log pattern. There is preset patten is available, we can also implement is in single line

I enabled few more information like execution time , request size , cookies etc..

Default tag should be like this

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
               prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>

Common : %{X-Forwarded-For}i %l %u %t “%r” %s %b
Combined : %{X-Forwarded-For}i %l %u %t %r %s %b %{User-Agent}i %{Referer}i %{Cookie}i

You can change either Common or Combined

I have implemented my own pattern like below, so it should more detailed

pattern="%h %{X-Forwarded-For}i %l %u %t  &quot;%r&quot; %s %b  &quot;%{User-Agent}i&quot; &quot;%{Referer}i&quot; &quot;%{Cookie}i&quot; %T"

Access Log pattern new look

-----------------------------
192.168.1.185 - - - [18/Mar/2014:10:52:06 +0530]  "GET /ajax/norm/list/status?ids=23%2C11%2C9%2C7%2C6%2C5%2C2%2C1%2C HTTP/1.1" 200 42  "Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0" "http://192.168.1.188/norm/list" "JSESSIONID=4FD1DBEB911CD2E19AA4798F9A26DCA8" 0.007
-----------------------------
Log Details : 192.168.1.185 : Remote host name (or IP address if resolveHosts is false)
– : X-Forwarded-For – : Remote logical username
– : Remote user that was authenticated
[18/Mar/2014:10:52:06 +0530]  : Date and time, in Common Log Format
GET /ajax/norm/list/…… : First line of the request (method and request URI)
HTTP/1.1 : Request protocol
200 : HTTP status code of the response
42 : Bytes sent, excluding HTTP headers (Content size)
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0: User Agent
http://192.168.1.188/norm/list : Referer
JSESSIONID=4FD1DBEB911CD2E19AA4798F9A26DCA8 : Cookie header
0.007 : Time taken to process the request, in seconds

Once every thing has been done you can restart the tomcat to make it effect, more options are given below

%a – Remote IP address
%A – Local IP address
%b – Bytes sent, excluding HTTP headers, or ‘-‘ if zero
%B – Bytes sent, excluding HTTP headers
%h – Remote host name (or IP address if resolveHosts is false)
%H – Request protocol
%l – Remote logical username from identd (always returns ‘-‘)
%m – Request method (GET, POST, etc.)
%p – Local port on which this request was received
%q – Query string (prepended with a ‘?’ if it exists)
%r – First line of the request (method and request URI)
%s – HTTP status code of the response
%S – User session ID
%t – Date and time, in Common Log Format
%u – Remote user that was authenticated (if any), else ‘-‘
%U – Requested URL path
%v – Local server name
%D – Time taken to process the request, in millis
%T – Time taken to process the request, in seconds
%I – current request thread name (can compare later with stacktraces)
%f – X-Forwarded-For IP address
%F – X-Forwarded-For address

info: How to install java on Ubuntu.

Posted on Updated on

JAVAJava is a object-oriented computer programming language developed by James Gosling  at Sun Microsystems and released in 1995 lated it has been migrated to

Oracle systems. The code that can runs on one platform does not need to be recompiled.

Ubuntu

Install oracle java 7 in ubuntu 12.04
Here I have described about one of the easiest installation method of Oracle-JAVA on Ubuntu using JAVA repository. for more information : http://en.wikipedia.org/wiki/Java_(programming_language)

Open the terminal and run the following commands

# java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (6b24-1.11.5-0ubuntu1~12.04.1)
OpenJDK Server VM (build 20.0-b12, mixed mode)

# sudo add-apt-repository ppa:webupd8team/java
# sudo apt-get update
# sudo apt-get install oracle-java7-installer

Now check the new updated verison

# java -version
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) Server VM (build 23.21-b01, mixed mode)

 

sdf

Check the installation directory:

anand@desktop:~$ ll /usr/lib/jvm/java-7-oracle/
total 19720
drwxr-xr-x 8 root root 4096 May 3 09:32 .
drwxr-xr-x 6 root root 4096 May 3 09:32 ..
drwxr-xr-x 2 root root 4096 May 3 09:32 bin
-r--r--r-- 1 root root 3339 May 3 09:32 COPYRIGHT
drwxr-xr-x 4 root root 4096 May 3 09:32 db
drwxr-xr-x 3 root root 4096 May 3 09:32 include
drwxr-xr-x 5 root root 4096 May 3 09:32 jre
drwxr-xr-x 3 root root 4096 May 3 09:32 lib
-r--r--r-- 1 root root 40 May 3 09:32 LICENSE
drwxr-xr-x 4 root root 4096 May 3 09:32 man
-r--r--r-- 1 root root 114 May 3 09:32 README.html
-rw-r--r-- 1 root root 443 May 3 09:32 release
-rw-r--r-- 1 root root 19838528 May 3 09:32 src.zip
-rw-r--r-- 1 root root 123324 May 3 09:32 THIRDPARTYLICENSEREADME-JAVAFX.txt
-r--r--r-- 1 root root 172252 May 3 09:32 THIRDPARTYLICENSEREADME.txt

 

That’s all 🙂

Howto: Installing,Upgrading JAVA on Centos,Fedora,Ubuntu,RHEL5

Posted on

Download JAVA and follow the below installtion steps.

Use Java JDK absolute version (/usr/java/jdk1.7.0_03)

## java ##
alternatives --install /usr/bin/java java /usr/java/latest/bin/java 20000

## javaws ##
alternatives --install /usr/bin/javaws javaws /usr/java/latest/bin/javaws 20000

## Java Browser (Mozilla) Plugin 32-bit ##
alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/latest/lib/i386/libnpjp2.so 20000

## Java Browser (Mozilla) Plugin 64-bit ##
alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/latest/lib/amd64/libnpjp2.so 20000


Use Java JRE latest version (/usr/java/latest)

## java ##
alternatives --install /usr/bin/java java /usr/java/latest/bin/java 20000

## javaws ##
alternatives --install /usr/bin/javaws javaws /usr/java/latest/bin/javaws 20000

## Java Browser (Mozilla) Plugin 32-bit ##
alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/latest/lib/i386/libnpjp2.so 20000

## Java Browser (Mozilla) Plugin 64-bit ##
alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/latest/lib/amd64/libnpjp2.so 20000

 

 

Check current java, javac, javaws and libjavaplugin.so versions

 

java -version
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)

javaws
Java(TM) Web Start 10.0.0.4-fcs
[...]

javac -version
javac 1.7.0_03


Swap between OpenJDK and Sun/Oracle Java JDK/JRE 6 and 7 versions

JAVA

alternatives --config java

There are 5 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /usr/java/jdk1.6.0_24/jre/bin/java
   2           /usr/lib/jvm/jre-1.5.0-gcj/bin/java
 + 3           /usr/java/jdk1.6.0_26/jre/bin/java
   4           /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
   5           /usr/java/jdk1.7.0_03/jre/bin/java

Enter to keep the current selection[+], or type selection number: 5

Note: java with [+] is currently on use

javaws

alternatives --config javaws

There are 3 programs which provide 'javaws'.

  Selection    Command
-----------------------------------------------
*  1           /usr/java/jdk1.6.0_24/jre/bin/javaws
 + 2           /usr/java/jdk1.6.0_26/jre/bin/javaws
   3           /usr/java/jdk1.7.0_03/jre/bin/javaws

Enter to keep the current selection[+], or type selection number: 3

Note: java with [+] is currently on use

libjavaplugin.so (32-bit)

alternatives --config libjavaplugin.so

There are 3 programs which provide 'libjavaplugin.so'.

  Selection    Command
-----------------------------------------------
*  1           /usr/java/jdk1.6.0_24/jre/lib/i386/libnpjp2.so
 + 2           /usr/java/jdk1.6.0_26/jre/lib/i386/libnpjp2.so
   3           /usr/java/jdk1.7.0_03/jre/lib/i386/libnpjp2.so

Enter to keep the current selection[+], or type selection number: 3.

javac

alternatives --config javac

There are 3 programs which provide 'javac'.

  Selection    Command
-----------------------------------------------
*  1           /usr/java/jdk1.6.0_24/bin/javac
 + 2           /usr/java/jdk1.6.0_26/bin/javac
   3           /usr/java/jdk1.7.0_03/bin/javac

Enter to keep the current selection[+], or type selection number: 3

Note: java with [+] is currently on use


Post-Installation Setup

Add JAVA_HOME environment variable to /etc/profile file or $HOME/.bash_profile file

Java JDK and JRE latest version (/usr/java/latest)

## export JAVA_HOME JDK/JRE ##
export JAVA_HOME="/usr/java/latest"

Java JDK and JRE absolute version (/usr/java/jdk1.7.0_03)

## export JAVA_HOME JDK ##
export JAVA_HOME="/usr/java/jdk1.7.0_03"

## export JAVA_HOME JRE ##
export JAVA_HOME="/usr/java/jre1.7.0_03"

Java on linux

Posted on Updated on

Check Java on Linux

Open a Terminal Window and run

java -version

This should return something like

Java(TM) 2 Runtime Environment, Standard Edition (build 1.6)

If the build number is less than 1.6 you will need to install a later version of Java. If it returns

-bash: java: comand not found

This means that either it is not installed or you havent set up your paths properly check by looking at the installed program list, or type

whereis java

if it finds java installed on your computer add it to your path i.e. whereis java returns

/usr/local/java/j2sdk-1.6.0/bin.

you should add (Adding java path to system path it we can execute java any location of OS)

export PATH=$PATH:/usr/local/java/j2sdk-1.6.0/bin