DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Coding
  3. Frameworks
  4. Monitoring Grails Apps part 1 – Custom JMX MBeans

Monitoring Grails Apps part 1 – Custom JMX MBeans

Robin Bramley user avatar by
Robin Bramley
·
Jun. 01, 11 · Interview
Like (0)
Save
Tweet
Share
6.33K Views

Join the DZone community and get the full member experience.

Join For Free

this article gives an introduction to using custom jmx mbeans within grails.

jmx (java management extension) was an early jsr specification ( jsr-3 ) and the first final release was in 2000 with subsequent maintenance releases in 2002 & 2006. additional capabilities such as remoting support ( jmx-rmi ) were added through subsequent jsrs.

the jmx spec in essence allows you to check values of attributes on an mbean (management bean), set attribute values, invoke methods (e.g. shutdown) and it also caters for notifications. for this article we’ll focus on the first of those.

in my experience not many java application developers are familiar with jmx though i’ve seen (and encouraged) more usage of custom mbeans on spring powered applications. the spring framework makes it exceptionally easy to export a bean as an mbean and to register it with an mbeanserver.

a custom mbean
let’s start with a ‘hello world’ example…

/**
* simple jmx mbean example.
*
* @author robin bramley
*/
public class simplembean {
public string gethelloworld() {
return 'hello world'
}
}

i’ve created this in src/groovy/com/rbramley/jmx/simplembean.groovy (so obviously it has “package com.rbramley.jmx” at the top).

spring config
open up grails-app/conf/spring/resources.groovy
firstly, we need to declare our bean:

simplembean(com.rbramley.jmx.simplembean) {}

having set up a bean, we need an mbean server so that we can register our mbean. luckily the spring framework helps us out here. the mbeanserverfactorybean will attempt to locate an existing mbean server (this behaviour can be turned off).

mbeanserver(org.springframework.jmx.support.mbeanserverfactorybean) {
locateexistingserverifpossible = true
}

spring provides a number of ways of exposing beans as mbeans, the simplest is the mbeanexporter (for other exporters & assemblers see the spring framework jmx docs ) – this will expose our bean to the mbeanserver:

mbeanexporter(org.springframework.jmx.export.mbeanexporter) {
server = ref('mbeanserver')
registrationbehaviorname = 'registration_replace_existing'
beans = ['rbramley:name=simplembean':ref('simplembean')]
}

accessing jmx
now we’ve exposed some information via jmx, how can we access it?

first up is jconsole , this tool has been shipped with the sun jdk for a while now. it can access local apps by process id and remote applications by url.

here i’ve accessed the grails local process, selected the ‘mbeans’ tab and navigated to the ‘helloworld’ attribute. notice how the mbean is in the ‘rbramley’ namespace – this was achieved with the map key in the ‘beans’ property of the mbeanexporter bean.

custom mbean viewed through jconsole

if you’re using tomcat, the manager application provides a jmx proxy servlet – see the manager docs for more details.

we can also access jmx from nagios-based monitoring systems such as opsview using check_jmx – but more on that later on in the series when we pull it all together.

from http://leanjavaengineering.wordpress.com/2011/03/29/monitoring-grails-apps-part-1-custom-jmx-mbeans/

Spring Framework Grail (web browser) app

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • [DZone Survey] Share Your Expertise and Take our 2023 Web, Mobile, and Low-Code Apps Survey
  • How Elasticsearch Works
  • Monolithic First
  • Introduction to Container Orchestration

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: