How to Configure JMX port to my play application

4,414 views
Skip to first unread message

Puneet Jain

unread,
Apr 8, 2013, 1:40:13 PM4/8/13
to play-fr...@googlegroups.com
Hi,

I have written an application in play 2.1.0. I need to export the jmx port in that. I added following lines in the settings of project/Build.scala file:

javaOptions += "-Dcom.sun.management.jmxremote",
javaOptions += "-Dcom.sun.management.jmxremote.port=5678",
javaOptions += "-Dcom.sun.management.jmxremote.local.only=false ",
javaOptions += "-Dcom.sun.management.jmxremote.ssl=false",
javaOptions += "-Dcom.sun.management.jmxremote.authenticate=false"

It didn't work.

My env:
OS: Ubuntu
Java: 1.6
Scala: 2.10
Play: 2.1.0
SBt: 0.12.4

Please help me out how to set jmx port for my application. This is a bottleneck for me.

Thanks in advance,
Puneet

Martin Grotzke

unread,
Apr 8, 2013, 1:49:32 PM4/8/13
to play-fr...@googlegroups.com

Does it work for you on your local machine via the service url / port? When you're connecting a remote server there might be a firewall blocking - as jmx/rmi uses dynamic ports for communication.

Cheers,
Martin

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Puneet Jain

unread,
Apr 8, 2013, 4:38:13 PM4/8/13
to play-fr...@googlegroups.com, martin....@googlemail.com
Hi Martin, 

Thanks for looking into my post. No, it didn't work. I am not getting your meaning by saying "jmx uses dynamic ports for communication". As far as I know, in jvm I can define what port I want to expose to connect to jmx server. And any remote application can connect to my jmx server using my hostname and port. Right now I am not worried about firewall coz all the clients of my server are with in the firewall.

I want to know how can I define the jmx port for my application. I tried

[ play project ]$ start -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost

this worked fine. But the same configuration is not working with "run". Secondly, can I define these options in project/Build.scala file?

Thanks,
Puneet

Martin Grotzke

unread,
Apr 8, 2013, 7:53:01 PM4/8/13
to play-fr...@googlegroups.com
On 04/08/2013 10:38 PM, Puneet Jain wrote:
> Hi Martin,
>
> Thanks for looking into my post. No, it didn't work. I am not getting
> your meaning by saying "jmx uses dynamic ports for communication".

The JMX RMI connector opens two ports: one is for the RMI registry (the
port that you supply with -Dcom.sun.management.jmxremote.port=<port>),
the other port is used to export JMX RMI connection objects. This second
port is usually dynamically allocated at random. Indeed you don't need
to know this port number in order to connect to the JMX agent: the only
port number you need to know is the RMI registry port number from which
to obtain the stubs (the stubs then contain the dynamic port number /
the endpoint on the other side).
So the dynamic port number only becomes relevant if you're trying to use
jmx through a firewall.


> I want to know how can I define the jmx port for my application. I tried
>
> [ play project ]$ start -Dcom.sun.management.jmxremote.port=9010
> -Dcom.sun.management.jmxremote.authenticate=false
> -Dcom.sun.management.jmxremote.ssl=false
> -Djava.rmi.server.hostname=localhost
>
> this worked fine.

Ok, so the jmx remote issue is basically solved? Great!

> But the same configuration is not working with "run".

With run? You should only run the production app in dev mode when you
know what you're doing ;-)

> Secondly, can I define these options in project/Build.scala file?

This should work:
javaOptions in run += "-Dcom.sun.management.jmxremote.port=9010",
javaOptions in run += ...

Cheers,
Martin


>
> Thanks,
> Puneet
>
>
> On Monday, April 8, 2013 10:49:32 AM UTC-7, Martin Grotzke wrote:
>
> Does it work for you on your local machine via the service url /
> port? When you're connecting a remote server there might be a
> firewall blocking - as jmx/rmi uses dynamic ports for communication.
>
> Cheers,
> Martin
>
> Am 08.04.2013 19:40 schrieb "Puneet Jain" <punee...@gmail.com
> <javascript:>>:
> <javascript:>.
> For more options, visit https://groups.google.com/groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
>
>

--
inoio gmbh - http://inoio.de
Schulterblatt 36, 20357 Hamburg
Amtsgericht Hamburg, HRB 123031
Geschäftsführer: Dennis Brakhane, Martin Grotzke, Ole Langbehn

Puneet Jain

unread,
Apr 9, 2013, 7:51:24 PM4/9/13
to play-fr...@googlegroups.com, martin....@googlemail.com
Thanks Martin, that make sense. But I was trying to connect on my local machine but didn't work. Looks like play dev mode doesn't support it. Can you help to how to configure it for dev mode.

Thanks,
Puneet

Martin Grotzke

unread,
Apr 10, 2013, 3:46:24 AM4/10/13
to Puneet Jain, play-fr...@googlegroups.com

Connect from your machine to your machine, with jconsole/jvisualvm as client? Then you can just select the java process running sbt...

Cheers,
Martin

Puneet Jain

unread,
Apr 12, 2013, 2:16:59 PM4/12/13
to play-fr...@googlegroups.com, Puneet Jain, martin....@googlemail.com
Thanks Martin,

But actually we are using a monitoring tool to monitor our application, which is running outside our deployment stack. And that is JMX based. And you were correct, if I open the firewall for all the ports, my tool is able to connect, if not my tool is not connecting the JMX. Is there anyway we can configure a fixed port instead of this dynamic port?

Thanks,
Puneet

Martin Grotzke

unread,
Apr 12, 2013, 4:50:15 PM4/12/13
to play-fr...@googlegroups.com
Back in the servlet container days I used this ServletContextListener to
fix the port: https://gist.github.com/magro/5374970

You could adapt it (remove servlet deps) and try to start it in
Global.onStart (and stop accordingly), but I'm not sure if this will
work in terms of lifecycle (IIRC it must be invoked before the
MBeanServer is accessed, so it also depends on the plugins you're using).
I'm currently thinking about turning this into a play plugin itself...

Cheers,
Martin


On 04/12/2013 08:16 PM, Puneet Jain wrote:
> Thanks Martin,
>
> But actually we are using a monitoring tool to monitor our application,
> which is running outside our deployment stack. And that is JMX based.
> And you were correct, if I open the firewall for all the ports, my tool
> is able to connect, if not my tool is not connecting the JMX. Is there
> anyway we can configure a fixed port instead of this dynamic port?
>
> Thanks,
> Puneet
>
> On Wednesday, April 10, 2013 12:46:24 AM UTC-7, Martin Grotzke wrote:
>
> Connect from your machine to your machine, with jconsole/jvisualvm
> as client? Then you can just select the java process running sbt...
>
> Cheers,
> Martin
>
> Am 10.04.2013 01:51 schrieb "Puneet Jain" <punee...@gmail.com
> <javascript:>>:
>
> Thanks Martin, that make sense. But I was trying to connect on
> my local machine but didn't work. Looks like play dev mode
> doesn't support it. Can you help to how to configure it for dev
> mode.
>
> Thanks,
> Puneet
>
> On Monday, April 8, 2013 4:53:01 PM UTC-7, Martin Grotzke wrote:
>
> On 04/08/2013 10:38 PM, Puneet Jain wrote:
> > Hi Martin,
> >
> > Thanks for looking into my post. No, it didn't work. I am
> not getting
> > your meaning by saying "jmx uses dynamic ports for
> communication".
>
> The JMX RMI connector opens two ports: one is for the RMI
> registry (the
> port that you supply with
> -Dcom.sun.management.__jmxremote.port=<port>),
> the other port is used to export JMX RMI connection objects.
> This second
> port is usually dynamically allocated at random. Indeed you
> don't need
> to know this port number in order to connect to the JMX
> agent: the only
> port number you need to know is the RMI registry port number
> from which
> to obtain the stubs (the stubs then contain the dynamic port
> number /
> the endpoint on the other side).
> So the dynamic port number only becomes relevant if you're
> trying to use
> jmx through a firewall.
>
>
> > I want to know how can I define the jmx port for my
> application. I tried
> >
> > [ play project ]$ start
> -Dcom.sun.management.__jmxremote.port=9010
> > -Dcom.sun.management.__jmxremote.authenticate=false
> > -Dcom.sun.management.__jmxremote.ssl=false
> > -Djava.rmi.server.hostname=__localhost
> >
> > this worked fine.
>
> Ok, so the jmx remote issue is basically solved? Great!
>
> > But the same configuration is not working with "run".
>
> With run? You should only run the production app in dev mode
> when you
> know what you're doing ;-)
>
> > Secondly, can I define these options in
> project/Build.scala file?
>
> This should work:
> javaOptions in run +=
> "-Dcom.sun.management.__jmxremote.port=9010",
> javaOptions in run += ...
>
> Cheers,
> Martin
>
>
> >
> > Thanks,
> > Puneet
> >
> >
> > On Monday, April 8, 2013 10:49:32 AM UTC-7, Martin Grotzke
> wrote:
> >
> > Does it work for you on your local machine via the
> service url /
> > port? When you're connecting a remote server there
> might be a
> > firewall blocking - as jmx/rmi uses dynamic ports for
> communication.
> >
> > Cheers,
> > Martin
> >
> > Am 08.04.2013 19:40 schrieb "Puneet Jain"
> <punee...@gmail.com
> > <javascript:>>:
> >
> > Hi,
> >
> > I have written an application in play 2.1.0. I
> need to export
> > the jmx port in that. I added following lines in
> the settings of
> > project/Build.scala file:
> >
> > javaOptions += "-Dcom.sun.management.__jmxremote",
> > javaOptions +=
> "-Dcom.sun.management.__jmxremote.port=5678",
> > javaOptions +=
> "-Dcom.sun.management.__jmxremote.local.only=false ",
> > javaOptions +=
> "-Dcom.sun.management.__jmxremote.ssl=false",
> > javaOptions +=
> "-Dcom.sun.management.__jmxremote.authenticate=false"
> >
> > It didn't work.
> >
> > My env:
> > OS: Ubuntu
> > Java: 1.6
> > Scala: 2.10
> > Play: 2.1.0
> > SBt: 0.12.4
> >
> > Please help me out how to set jmx port for my
> application. This
> > is a bottleneck for me.
> >
> > Thanks in advance,
> > Puneet
> >
> > --
> > You received this message because you are
> subscribed to the
> > Google Groups "play-framework" group.
> > To unsubscribe from this group and stop receiving
> emails from
> > it, send an email to
> play-framewor...@googlegroups.__com
> > <javascript:>.
> > For more options, visit
> https://groups.google.com/__groups/opt_out
> <https://groups.google.com/groups/opt_out>
> > <https://groups.google.com/__groups/opt_out
signature.asc
Reply all
Reply to author
Forward
0 new messages