Tuesday, September 2, 2008

PermGen OutOfMemoryError problem in Tomcat

A cause and how to fix java.lang.OutOfMemoryError: PermGen space

The permanent generation is the area of heap that holds all the reflective data of the virtual machine itself, such as class and method objects (also called “method area” in The Java Virtual Machine Specification).

Why do you care?

If an application loads “too many” classes then it is possible it will abort with an OutOfMemoryError. The specific error is: “Exception in thread XXXX java.lang.OutOfMemoryError: PermGen space”

Translation: The JVM itself needs memory to be able to run your application. The PermGen is information about the classes that make up your application. Web applications and Servlet containers often need more PermGen memory than the JVM defaults to be able to run.

Fixing the java.lang.OutOfMemoryError: PermGen space error.

Start your JVM with -XX:MaxPermSize=XXXm where XXX is a number like 128, 256. This will allow the JVM to allocate XXX megabytes of memory for the PermGen space if that space is needed.

How do you find out what’s classes are being stored in PermGen? Trace class loading/unloading


How to trace classes are being loaded or unloaded? Use the command line options -XX:+TraceClassloading and -XX:+TraceClassUnloading http://java.sun.com/docs/hotspot/HotSpotFAQ.html


Monday, September 1, 2008

jManage 2.0

Monitoring Tomcat 6 with jManage 2.0

jManage 2.0 is an open source application management platform, which provides a centralized console for managing application clusters and distributed-application environments.
Easy to use Web based interface, which allows jManage to be used from behind firewall.

Here a list of main features:
- Web and command line based JMX console.
- Dashboard framework to build custom dashboards. Customized dashboards can be tailored to specific objectives
- Production level security.
- Command line interface - Useful for scripting and automation.
- Application Cluster Support - Change attribute values and perform operations across the cluster.
- Authentication and fine-grained Authorization to control access to different MBean attributes and operations.
- Custom Graphs.
- MBean attribute value monitoring.
- Email and console alerts based on MBean notifications and MBean attribute monitors.
- Framework to define custom DataFormat classes for custom objects.

1.Installation

Just download and unpack linux package, make sure all sh files have execute permissions and run
"startup" from the jManage "bin" directory, this starts the jManage server. Use
admin/123456 if you didn't run "keygen".
In case you use production environment it's possible to generate a new password with "keygen" utility.

Access the server with URL "http://<server name>:9090".

2.Configuration

To monitor Tomcat first of all you need to allow JMX support in bin/catalina.sh:
JAVA_OPTS="-Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
What is JMX?

To make it short, JMX is a technology that lets you implement management interfaces for Java applications.A management interface, as defined by JMX, is composed of named objects - called MBeans (Management Beans). MBeans are registered with a name (an ObjectName) in an MBeanServer. To manage (a) resource(s) in your application, you will write an MBean that defines its management interface, and then register thatMBean in your MBeanServer.The content of the MBeanServer can then be exposed through various protocols, implemented by protocol connectors, or protocol adaptors.

Login in to jManage
  • click on Add Application
  • click on JSR160 Application
    • name the app something meaningful
    • add in this URL: service:jmx:rmi:///jndi/rmi://host_name:9999/jmxrmi
  • you shouldn't need a username or pass, since we specified
    authenticate=false in JAVA_OPTS. Change this according to your needs.
  • substitute you own IP address/hostname for the application server
  • no other fields need to be completed--- click on SAVE
3.Use

By default each new application get JVM threads, JVM summary and Class loading graphs. In addition you could add monitoring to each component in tomcat or jvm, change mbeans parameters and load/unload components that support mbean technology.
Also it's possible to configure a different alerts, which could be one of:




4.Links