How to define uri metrics in dropwizard metrics?

367 views
Skip to first unread message

WD

unread,
Oct 19, 2016, 7:40:34 PM10/19/16
to vert.x
In my vertx application, I used the command line option to set the dropwizardmetrics=true to enable dropwizardmetrics.
In the "start verticle", the default vertx instance is used to set up an httpserver to receive http request. I would like to collect the metrics on the request uri. the following is the sample from the vertx dropwizard document. does that mean now I have 2 vertx instances? one is the default one and one is for the dropwizard metrics? I need to know how to define the dropwizardMericsOptions after vertx instance is already instantiated by the Vertx Launcher?

Vertx vertx = Vertx.vertx(new VertxOptions().setMetricsOptions( new DropwizardMetricsOptions(). setEnabled(true). addMonitoredHttpServerUri( new Match().setValue("/")). addMonitoredHttpServerUri( new Match().setValue("/foo/.*").setType(MatchType.REGEX)) ));


Julien Viet

unread,
Oct 20, 2016, 5:52:28 PM10/20/16
to ve...@googlegroups.com
Hi, 

can you post readable code ?

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/ae4c6f35-8589-4e14-9bae-c49f15b0cd25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

WD

unread,
Oct 20, 2016, 8:09:57 PM10/20/16
to vert.x
Hi Julien, 
here is the code:

public class StartVerticle extends AbstractVerticle {

    @Override
    public void start() {
        Router router = Router.router(vertx);

        router.get("/foo/:time").handler(this::handleFoo);

        HttpServer httpServer = vertx.createHttpServer(options);
        httpServer.requestHandler(router::accept).listen(8888);

        // now need to setup to get the metrics for /foo uri
        // does it create another vertx instance vterx2 ?
        Vertx vertx2 = Vertx.vertx(new VertxOptions().setMetricsOptions(
            new DropwizardMetricsOptions().
                setEnabled(true).
                addMonitoredHttpServerUri(
                    new Match().setValue("/")).
                    addMonitoredHttpServerUri(
                        new Match().setValue("/foo/.*").setType(MatchType.REGEX))
        ));

        // now print out the metrics, which vertx to use? vertx or vertx2 ?

        MetricsService service = MetricsService.create(vertx);

        JsonObject vertxMetrics = service.getMetricsSnapshot(vertx);

    }

    private void handleFoo(RoutingContext routingContext) {
    // do something

Thomas SEGISMONT

unread,
Oct 24, 2016, 11:01:44 AM10/24/16
to ve...@googlegroups.com
If you activated the Dropwizard module by command line you can simply get metric info from Vert. objects:


Don't create the additional Vert.x instance.

To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.

WD

unread,
Oct 24, 2016, 12:48:01 PM10/24/16
to vert.x
Hi Thomas, 
I need the Http server uri metrics, in the Vert.x document, it says "Http URI metrics must be explicitely configured in the options either by exact match or regex match:"
I can only enable the dropwizard but not able to set the uri for the httpserver metrics. please advise.


thanks,

MD

Thomas SEGISMONT

unread,
Oct 25, 2016, 5:42:03 AM10/25/16
to ve...@googlegroups.com
You can set a path to metrics options JSON file with -Dvertx.metrics.options.configPath=/path/to/your/config/gile

And then in the file, something like:

{
    "enabled" : true,
    "monitoredHttpServerUris" : [
      {
        "value" : "/"
      },
      {
        "value" : "/foo/.*",
        "type" : "REGEX"
      }
    ]
}

This is just an example, update the values depending on your needs.

To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.

WD

unread,
Oct 25, 2016, 8:38:59 PM10/25/16
to vert.x
Hi Thomas,
thanks for the help, I got one step closer. I use the following configFile:

{

    "enabled" : true,

    "jmxEnabled" : true,

    "monitoredHttpServerUris" : [

      {

        "value" : "/foo/.*",

        "type" : "REGEX"

      },

      {

        "value" : "/bar"

      }

    ],

    "monitoredHandlers" : [

      {

        "value" : "ebAddr"

      }

    ]

}


I have HttpServer configured to listen on port 8887, after starting the application, running the jconsole to check the MBeans.

I could see the MBean vertx.eventbus.handlers.ebAddr. so that means the config file should be correct. I could also see the regular vertx.http.servers.0.0.0.0:8887 MBeans.

But I could not see any http.servers MBeans with /bar nor /foo Uris.



MD

Thomas SEGISMONT

unread,
Oct 26, 2016, 2:58:42 AM10/26/16
to ve...@googlegroups.com
Can you post your HTTP server code?

To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.

WD

unread,
Oct 26, 2016, 5:34:30 PM10/26/16
to vert.x

        HttpServerOptions options = new HttpServerOptions();

        options.setCompressionSupported(true);

        options.setIdleTimeout(5);

HttpServer httpServer = vertx.createHttpServer(options);

httpServer.requestHandler(router::accept).listen(8887);

        

HttpServer httpServer2 = vertx.createHttpServer(options);

httpServer2.requestHandler(router::accept).listen(8889);


In my actual application, I have 2 http servers running listening on port 8889 and 8887. What I noticed with jconsole, with Vertx 3.2.1, for each http server, it has its own set of MBean. In Vertx 3.3.3, I could only see one http server MBean set.

Thomas SEGISMONT

unread,
Nov 2, 2016, 12:12:05 PM11/2/16
to ve...@googlegroups.com
The MBeans for you "/bar" or "/foo" will only show up after a request has been received.

As for the difference with Vert.x 3.3.3, that seems wrong indeed. Would you mind to open an issue on GH with a simple reproducer? Thanks.
It seems there is an issue with the object name (the colon has a special meaning in JMX)

To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.

Thomas SEGISMONT

unread,
Nov 30, 2016, 6:08:27 AM11/30/16
to ve...@googlegroups.com
FYI, I filed a ticket to track the issue: https://github.com/vert-x3/vertx-dropwizard-metrics/issues/53

The fix should be released in the next version.

shailender arya

unread,
Feb 7, 2017, 4:34:14 AM2/7/17
to vert.x
Hi Guys 
I am facing issue where specifying metrics through command line options don't show any mbeans in jconsole. 
Command LIne is as follows 

java -Xmx512M -Xms512M -XX:+PrintGCDetails -Xloggc:logs/gc.log -verbose:gc -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps  -jar target/SfMain-0.0.1-fat.jar -Dvertx.metrics.options.configPath=monitor.json -conf conf/dev/config.json  -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dorg.vertx.logger-delegate-factory-class-name=org.vertx.java.core.logging.impl.SLF4JLogDelegateFactory

 Content of monitor.json are
{
    "enabled" : true,
    "jmxEnabled":true,
    "registryName":"waybillAsAService",
    "jmxDomain":"waybillServ",
    "monitoredHttpServerUri" : [
      {
        "value" : "/waybill.*",
        "type" : "REGEX"
      }
    ]
}

But I don;t see any Mbeans through JConsole. WHereas if i don't specify options file and instead specify following command line arguments, I see lots of default metrics but URI level metrics are not shown. Command Line args which partially work are 
-Dvertx.metrics.options.enabled=true  -Dvertx.metrics.options.jmxEnabled=true -Dvertx.metrics.options.registryName=waybillAsAService  -Dvertx.metrics.options.jmxDomain=delhiverySarya
 Please help how to overcome this problem

Thomas SEGISMONT

unread,
Feb 7, 2017, 5:20:37 AM2/7/17
to ve...@googlegroups.com
Which version do you use? 3.3.3 ? Can you have a try with 3.4.0.Beta1?

To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.

shailender arya

unread,
Feb 7, 2017, 9:26:35 AM2/7/17
to vert.x

we are using version 3.2.1 and this is for production. So we can't move to beta version. Is there any other way in which I can get http URI metrics through command line

Thomas SEGISMONT

unread,
Feb 7, 2017, 10:20:59 AM2/7/17
to ve...@googlegroups.com
3.2.1 didn't have the issue discussed in this thread. Can you put together a small reproducer on GitHub?

To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.

shailender arya

unread,
Feb 7, 2017, 10:23:15 AM2/7/17
to ve...@googlegroups.com
Sure by tonight I will put a repo on github and update on this thread

--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/BP3XVk10QTE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Regards
Shailender Arya

shailender arya

unread,
Feb 8, 2017, 3:40:30 AM2/8/17
to vert.x
Hi following github project has the same problem 

It is not able to read metrics.options from configfile

shailender arya

unread,
Feb 8, 2017, 3:41:45 AM2/8/17
to vert.x
Hi following github project has the same problem 
It is not able to read metrics.options from configfile



Thomas SEGISMONT

unread,
Feb 8, 2017, 7:44:31 AM2/8/17
to ve...@googlegroups.com
Add -Dvertx.metrics.options.enabled=true to your startup command and change monitor.json to use monitoredServerUris instead of monitoredHttpServerUri

You must enable metrics on the command line otherwise the config path is not read.
In 3.2.1, there was a mismatch between the Options field and the name in Json format. It has been fixed in 3.4 (https://github.com/vert-x3/vertx-dropwizard-metrics/pull/52)

shailender arya

unread,
Feb 8, 2017, 1:15:24 PM2/8/17
to vert.x
Thanks Thomas it worked. It would be great if we can update the website too about this information 

--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/BP3XVk10QTE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.



--
Regards
Shailender Arya

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
Reply all
Reply to author
Forward
0 new messages