Over a million developers have joined DZone.

Groovy, A Reasonable JVM Language for DevOps

DZone's Guide to

Groovy, A Reasonable JVM Language for DevOps

· DevOps Zone ·
Free Resource

Open source vulnerabilities are on the rise. Read here how to tackle them effectively.

I’ve worked at several environments where most of our product was run through the JVM. I’ve always used the information available to me in Mbeans, but the overhead of exposing them to a monitoring system like Ganglia or Nagios has always been problematic. What I’ve been looking for is a simple JVM language that allows me to use any native object. In 2008 I found Groovy, and have used it as my JVM glue ever since.

Meet Groovy

I’ll skip from going into too much detail here, but Groovy is a simple dynamically typed language for the JVM. Its syntaxt and style is similar to that of Ruby. You can find more information here.

Solr JMX to Ganglia Example

import javax.management.ObjectName
import javax.management.remote.JMXConnectorFactory as JmxFactory
import javax.management.remote.JMXServiceURL as JmxUrl

def serverUrl = 'service:jmx:rmi:///jndi/rmi://my-solr-server:9004/jmxrmi'
def server = JmxFactory.connect(new JmxUrl(serverUrl)).MBeanServerConnection
def standard = new GroovyMBean(server, 'solr:type=standard,id=org.apache.solr.handler.component.SearchHandler')

println "request_per_second: $standard.avgRequestsPerSecond"
println "avg_request_ms: $standard.avgTimePerRequest"

"/usr/bin/gmetric --name=Solr_Requests_Per_Second --value=${standard.avgRequestsPerSecond} --type=float --unit=req/s --dmax=90".execute()
"/usr/bin/gmetric --name=Solr_Avg_Request_Time --value=${standard.avgTimePerRequest} --type=float --unit=s --dmax=90".execute()

This is a quick script to get data from JMX into ganglia fromSsolr. The syntax is simplfied, and missing the typical java boiler plate required to run from the command line. Not only that, but because of the simplified typing model, its very easy for me to build strings and then execute a command. This allows me to quickly construct a script like I would in Perl or Python, but also allows me easy access JMX, and any Java library of my choosing. The primary drawback will be the time it takes to instantiate the JVM, which you can work around if you can’t deal with the launch time.

So, if you're working in a Java with a bunch of Java apps, think about giving Groovy a chance for writing some of your monitoring tests, and metric collectors. It is a simpler language than Java to put together those little applications that can tell you how your system is performing, and well within the reach of your average DevOps engineer.

Source:  http://blog.hypergeometric.com/2012/03/06/groovy-a-reasonable-jvm-language-for-devops/

Learn about the ins and outs of open source security and management.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}