Skip to content

Instantly share code, notes, and snippets.

@lalyos
Last active December 14, 2015 15:49
Show Gist options
  • Save lalyos/5110992 to your computer and use it in GitHub Desktop.
Save lalyos/5110992 to your computer and use it in GitHub Desktop.
Connectiong to localm jmx server by PID.

Changing Logback specific logger level to INFO. Plesa remember to add the jmx configuration to your logback.xml

<configuration scan="true" scanPeriod="5 seconds" >
  <jmxConfigurator />

runnig the script

In order to be able to run the script you need groovy. You can install it by:

Once you installed groovy you can run the script directly from github:

groovy https://raw.github.com/gist/5110992/getMbeanAttribute.groovy
pid=80887
logger="org.springframework"
newLogLevel="INFO"
import java.lang.management.*
import javax.management.ObjectName
import javax.management.remote.JMXConnectorFactory as JmxFactory
import javax.management.remote.JMXServiceURL as JmxUrl
import javax.management.ObjectName
CONNECTOR_ADDRESS = "com.sun.management.jmxremote.localConnectorAddress"
vm = com.sun.tools.attach.VirtualMachine.attach(pid.toString())
connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS)
url=new JmxUrl(connectorAddress)
connecion=JmxFactory.connect(url).getMBeanServerConnection()
server=connecion
query=new ObjectName("ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator")
mb1=new GroovyMBean(server,query)
oldLevel = mb1.getLoggerEffectiveLevel(logger)
println "Current loglevel of $logger is: $oldLevel"
//mb1.setLoggerLevel(logger, newLogLevel)
//mb1.getLoggerEffectiveLevel(logger)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment