<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Martin Ahrer - Together we&#039;ll make IT &#187; JMX</title>
	<atom:link href="http://www.martinahrer.at/tag/jmx/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.martinahrer.at</link>
	<description>Java Enterprise Softwareentwicklung und Consulting</description>
	<lastBuildDate>Sun, 11 Dec 2011 16:19:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<meta name="generator" content="deSignum 0.8.1" />
		<item>
		<title>VisualVM 1.0 RC</title>
		<link>http://www.martinahrer.at/2008/07/01/visualvm-10-rc/</link>
		<comments>http://www.martinahrer.at/2008/07/01/visualvm-10-rc/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 09:25:02 +0000</pubDate>
		<dc:creator>Martin Ahrer</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JMX]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[Profiling]]></category>

		<guid isPermaLink="false">http://www.martinahrer.at/?p=76</guid>
		<description><![CDATA[One of the sessions of TheServerSide Java Symposium in Prague was about JMX support in Java. During the talk Jean Francoise Denise briefly demoed a new tool VisualVM based on the Netbeans Platform. Today I did some experiments and found it quite useful. It is also utilizing the NetBeans plugin mechanisms to provide extensibility (e.g [...]]]></description>
			<content:encoded><![CDATA[<p>One of the sessions of TheServerSide Java Symposium in Prague was about JMX support in Java. During the talk Jean Francoise Denise briefly demoed a new tool <a href="https://visualvm.dev.java.net/">VisualVM</a> based on the Netbeans Platform. Today I did some experiments and found it quite useful. It is also utilizing the NetBeans plugin mechanisms to provide extensibility (e.g in order to monitor JMX Beans  you must install the MBeans plugin).<br />
<a href='http://www.martinahrer.at/wp-content/uploads/2008/07/visualvm1.png'><img src="http://www.martinahrer.at/wp-content/uploads/2008/07/visualvm1.png" alt="https://visualvm.dev.java.net/" title="https://visualvm.dev.java.net/" width="150" height="115" class="alignleft size-thumbnail wp-image-78" /></a>.</p>
<p>The tool even provides a profiler. I haven&#8217;t even looked at it closer. Though I believe it is quite useful to have it available for ad doc profiling without requiring any external tools!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.martinahrer.at/2008/07/01/visualvm-10-rc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Change log4j logging level at runtime using JMX/Spring</title>
		<link>http://www.martinahrer.at/2008/02/11/change-log4j-logging-level-at-runtime-using-jmxspring/</link>
		<comments>http://www.martinahrer.at/2008/02/11/change-log4j-logging-level-at-runtime-using-jmxspring/#comments</comments>
		<pubDate>Mon, 11 Feb 2008 12:01:26 +0000</pubDate>
		<dc:creator>Martin Ahrer</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JMX]]></category>
		<category><![CDATA[Springframework]]></category>

		<guid isPermaLink="false">http://www.martinahrer.at/2008/02/11/change-log4j-logging-level-at-runtime-using-jmxspring/</guid>
		<description><![CDATA[Monitoring application servers is a daunting task. Without the right instrumentation of your code it is even impossible. I try to use log4j as much as possible and in general I&#8217;m very generous regarding logging levels. But occasionally the console just gets flooded with logging output. Typically then I would modify the logging configuration files [...]]]></description>
			<content:encoded><![CDATA[<p>Monitoring application servers is a daunting task. Without the right instrumentation of your code it is even impossible. I try to use log4j as much as possible and in general I&#8217;m very generous regarding logging levels. But occasionally the console just gets flooded with logging output. Typically then I would modify the logging configuration files and restart the server which may be very time consuming and unnecessary.</p>
<p>In the past I had used JMX to switch logging levels at runtime for various projects. The first time now I have tried this with the Spring framework and it worked like a charm (did you expect anything else). I&#8217;m making the solution public in case I need this for future projects and to document the steps required!</p>
<p>First, a bean is required that uses the logging API (here log4j) to manage the logging level.</p>
<pre lang="Java5">
/*
 * Copyright 2002-2008 Martin Ahrer.
 *
 * $Id$
 */
package at.martinahrer.blueprint.log4j;

import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedOperationParameter;
import org.springframework.jmx.export.annotation.ManagedOperationParameters;
import org.springframework.jmx.export.annotation.ManagedResource;

/**
 * @author Martin Ahrer
 *
 */

@ManagedResource(objectName = "at.martinahrer.blueprint.log4j:name=Logging", description = "Logging", log = true, logFile = "jmx.log", currencyTimeLimit = 15, persistPolicy = "OnUpdate", persistPeriod = 200, persistLocation = "logging", persistName = "logging")
public class Logging {
	@ManagedOperation(description = "Set the logging level for a category")
	@ManagedOperationParameters( { @ManagedOperationParameter(name = "category", description = "Logger category"),
			@ManagedOperationParameter(name = "level", description = "Logging level") })
	public void setLoggerLevel(String category, String level) {
		LogManager.getLogger(category).setLevel(Level.toLevel(level));
	}

	@ManagedOperation(description = "Get the logging level for a category")
	@ManagedOperationParameters( { @ManagedOperationParameter(name = "category", description = "Logger category") })
	public String getLoggerLevel(String category) {
		return LogManager.getLogger(category).getLevel().toString();
	}
}
</pre>
<p>It&#8217;s been annotated with Spring JMX annotations to provide JMX meta data. Next, we need to export the bean as a JMX Bean. This is supported very well by the Springframework&#8217;s MBeanExporter.</p>
<pre lang="xml">
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="assembler" ref="assembler" />
<property name="namingStrategy" ref="namingStrategy" />
<property name="autodetect" value="true" />
	</bean>

	<bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />

	<!-- will create management interface using annotation metadata -->
	<bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
<property name="attributeSource" ref="jmxAttributeSource" />
	</bean>

	<!-- will pick up the ObjectName from the annotation -->
	<bean id="namingStrategy" class="org.springframework.jmx.export.naming.MetadataNamingStrategy">
<property name="attributeSource" ref="jmxAttributeSource" />
	</bean>

	<bean id="log4jConfig" class="at.martinahrer.blueprint.log4j.Logging"></bean>
</beans>
</pre>
<p>Finally to connect to the MBeanServer using jconsole the JVM (running the MBean) must be started with the system property <em>-Dcom.sun.management.jmxremote</em><strong> set.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.martinahrer.at/2008/02/11/change-log4j-logging-level-at-runtime-using-jmxspring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

