0

I am using simplejmx to publish my JMX Resources.

I have got jmx-config.xml

<bean id="beanPublisher" class="com.j256.simplejmx.spring.BeanPublisher">
    <property name="jmxServer" ref="jmxServer" />
</bean>

<bean id="jmxServer" class="com.j256.simplejmx.server.JmxServer"
    init-method="start" destroy-method="stop">
    <property name="registryPort" value="8123" />
</bean>

I am starting my JBoss application, everything is ok:

15:20:11,860 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-8) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1be30160: defining beans [...,beanPublisher,jmxServer,...]; root of factory hierarchy

I created a simply class.

package com.mypckg.jmx;

import com.j256.simplejmx.common.JmxAttributeField;
import com.j256.simplejmx.common.JmxResource;

@JmxResource(description = "Blah1", domainName = "Blah2", beanName = "Blah3")
public class DummyJMX {

    @JmxAttributeField(description = "Blah4")
    private int var = 3;
}

I am starting JConsole, I am choosing JBoss application and I am going to MBeans. That is what I see:

enter image description here *

Probably, my DummyJMX class has not been published (or I just cannot find it).

About which step I forgot?

Thank you in advance


EDIT :

enter image description here


EDIT :

@Andrei Stefan

An error which I got using your link:

enter image description here

@Gray

An error which I got using localhost:8123:

enter image description here

ruhungry
  • 4,506
  • 20
  • 54
  • 98
  • 1
    I haven't used j256 jmx server, but since there is a port that's being specified at server creation, shouldn't you connect with JConsole to something else other than JBoss? – Andrei Stefan Apr 11 '14 at 13:54
  • @AndreiStefan I am even almost sure, that you are right, but...when my JBoss Server is down, I can choose 2 things in JConsole, when I run my server, there is only one more. I added a screenshot to my question. – ruhungry Apr 11 '14 at 14:10
  • 2
    Don't choose a Local Process, but try with a Remote Process. Use this as a JMX URL: service:jmx:rmi://jndi/rmi://localhost:8123/jmxrmi – Andrei Stefan Apr 11 '14 at 15:18
  • Hi, I tried it but it does not work. I edited my post and I pasted a printscreen. I checked [Using JConsole](http://docs.oracle.com/javase/7/docs/technotes/guides/management/jconsole.html) syntax of this URL and it looks good. – ruhungry Apr 14 '14 at 06:57

3 Answers3

0

Probably, my DummyJMX class has not been published (or I just cannot find it).

When you are using the registryPort configuration for JmxServer then it will not show up in the "Local Process" list under Jconsole. It will be able to be accessed as a "Remote Process" with localhost:8123. If you are on a Linux box, you might use netstat -an | grep LISTEN to see what ports your application is listening on. If you don't see 8123 in the list then maybe it already has a RMI server configured?

If you want to use the platform mbean-server which does show up as a local process then use the new setter or constructor in version 1.9 which was released recently (4/2014). Unfortunately, SimpleJMX cannot programmatically register itself so it shows up in the process list -- that's not code that the JVM exports.

<bean id="jmxServer" class="com.j256.simplejmx.server.JmxServer"
    init-method="start" destroy-method="stop">
    <property name="usePlatformMBeanServer" value="true" />
</bean>
Gray
  • 115,027
  • 24
  • 293
  • 354
  • Hi, I would like to keep it in this way. I tried `localhost:8123` but it gives me an error. I edited my post. – ruhungry Apr 14 '14 at 06:58
  • when I am trying with `usePlatformMBeanServer` it gives me an error `[...] org.springframework.beans.factory.BeanCreationException: Error creating bean with name "beanPublisher" [...] Bean property 'setUsePlatformMBeanServer' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?` . I changed `sipmle jmx` version to `1.9` – ruhungry Apr 14 '14 at 07:17
  • 1
    I don't understand this @GirlyGirl. The code I posted works for me. Are you sure you are using 1.9? Note that the property is _not_ `setUsePlatformMBeanServer` but is instead `usePlatformMBeanServer`. Is that the problem? – Gray Apr 14 '14 at 14:10
  • I cannot understand, why I pasted here `setUsePlatformMBeanServer`. I used your piece of code. An error is of course about field `usePlatformMBeanServer` . `Bean property 'usePlatformMBeanServer' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?` I checked directory `\standalone\deployments\myproject.war\WEB-INF\lib` and I can see 2 libs: `simplejmx-1.8` and `simplejmx-1.9` . I did `Project clean` and also `Maven clean` in Eclipse. No changes, still both versions exist in lib directory. – ruhungry Apr 15 '14 at 07:41
  • I have got a question: Is version `1.9` dependent on `1.8`? If not, probably I have got some problems with `Maven`. I run my server and I did `full publish`. After that, I stopped it and I removed manually version `1.8` from deployed `war`. I run my server once again and now it works. Anyhow, I would like to use your lib in this way: `` so I will be working on it. – ruhungry Apr 15 '14 at 08:00
  • 1.9 is certainly not dependent on 1.8. Are you depending on another package that depends on 1.8? Maybe you are missing an exclusion @GirlyGirl. – Gray Apr 15 '14 at 13:07
  • To be honest, I have no idea what was wrong. I will just keep version `1.8`. – ruhungry Apr 15 '14 at 13:15
  • 1
    You'll need 1.9 for the `usePlatformMBeanServer` @GirlyGirl. – Gray Apr 15 '14 at 13:18
  • I will not use it. I am using now `1.8` with `registryPort` and now it works. I can easily access my `JMX Beans` using local process. – ruhungry Apr 15 '14 at 13:25
0

Try the following url in JConsole, with Remote Process option: service:jmx:rmi:///jndi/rmi://localhost:8123/jmxrmi

It's a bit different than what I provided in the comments.

Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89
  • Thank you. It gives the same error. Do you think it could be a problem with `/`? I am working on Windows if it changes something. – ruhungry Apr 14 '14 at 07:38
  • 1
    The URL I provided works for me in a simple Spring project that uses your exact code and configuration. I can see the bean in JConsole, after I added this to my configuration: `` (I assumed you have this somewhere in your config). – Andrei Stefan Apr 14 '14 at 07:40
  • In, my code, this bean `dummy` is commented. I just want to set up my server and verify, if I am able to connect with `JConsole`. – ruhungry Apr 14 '14 at 07:50
  • I uncommented it. Still, I cannot connect with `JConsole`. Two, not really smart questions: 1. Can it be problem with `proxy`? 2. Should I provide any `username/password` ? In documentation is written to use it only in a specyfic case. – ruhungry Apr 14 '14 at 07:59
  • Now I'm thinking it can be something related to JBoss... but not sure what. You could try the same code and configuration in a standalone project, not .war and outside JBoss. – Andrei Stefan Apr 14 '14 at 08:01
  • What JBoss version are you using? – Andrei Stefan Apr 14 '14 at 09:38
  • Try another thing: uncomment the dummy bean in your code, replackage and redeploy your .war and then connect with JConsole to the JBoss JMX service. – Andrei Stefan Apr 14 '14 at 09:46
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/50670/discussion-between-girly-girl-and-andrei-stefan) – ruhungry Apr 15 '14 at 08:01
0

Finally, I am connected to my JMX Beans using JConsole.

Probably, I did something wrong in the beginning of my work with simplejmx.

I have not changed a lot of things. I kept jmx-config file and I still use version 1.8 of simplejmx.

I can easily connect to this bean locally - I have no idea why I was not able to do that earlier. Could you tell me, why in your opinion it should not be a local process?

Below, you can see that my JMX Bean appears in JConsole:

enter image description here

ruhungry
  • 4,506
  • 20
  • 54
  • 98
  • It depends. Briefly, my question was: `what to do to make it works`. Finally, it works as a local process and your answers suggested to use remote one. I cannot figure out why it did not work in the beginning. If you have got any idea, what could be a proper answer here, do not hesitate to answer my question. – ruhungry Apr 15 '14 at 13:13
  • My answer specifically says that it won't show up as a local process. It's a different registration mechanism. As my answer states, you should use the platform mbean server if you want it to be seen locally. – Gray Apr 21 '14 at 13:05