You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by James L Greene <jl...@aep.com> on 2014/11/07 01:35:45 UTC

camel-metrics Component

I have written a simple Java class to attempt to exercise the camel-metrics component.  In this example, I'm writing a standalone Java batch process, which will read files from an input directory, and deposit the files in an output directory.  I'm attempting to use the camel-metrics component to capture how many files were read (using the name "files-processed").  I've configured the class to only run for seventy seconds, giving the camel-metrics component an opportunity to output the values of the metric being captured to the application log (which its configured to do at sixty seconds intervals, and which appears to work properly).  

Prior to suspending/stopping my CamelContext, I attempted to retrieve the metrics as described in the camel-metrics component documentation.  Unfortunately, when I look at the contents of the metrics, my custom metric is nowhere to be found.  Below, please find the source for the sample class that I created, and its logged output.

Am I doing something wrong?

============================

Camel Version
2.14.0

JRE Version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

============================

package ...

import com.codahale.metrics.Counter;
import com.codahale.metrics.MetricRegistry;
import java.util.SortedMap;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.metrics.routepolicy.MetricsRegistryService;
import org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFactory;
import org.apache.camel.impl.DefaultCamelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {
    
    public static void main(String[] args) throws Exception {
        Logger LOG = LoggerFactory.getLogger(Main.class);
        
        CamelContext context = new DefaultCamelContext();
        
        RouteBuilder rb = new RouteBuilder() { 
            @Override
            public void configure() throws Exception {
                from("file://c:/test/input").
                        routeId("testroute").
                        log("Processing file [${header.CamelFileName}]").
                        to("metrics:counter:files-processed").
                        to("file://c:/test/output");
            }
        };
        context.addRoutes(rb);
        
        MetricsRoutePolicyFactory mrpf = new MetricsRoutePolicyFactory();
        context.addRoutePolicyFactory(mrpf);
        
        context.start();
        
        int sleepCounter = 0;
        while (sleepCounter < 7) {
            sleepCounter++;
            Thread.sleep(10000);
            LOG.info("Zzz...({} seconds)", sleepCounter * 10);
        }
        
        MetricsRegistryService regSvc = context.hasService(MetricsRegistryService.class);
        if(regSvc != null) { 
            // Dump the statistics to the log in JSON format.
            regSvc.setPrettyPrint(true);
            LOG.info(regSvc.dumpStatisticsAsJson());

            // Do it again, retrieving the map of counters from the MetricRegistry object.
            LOG.info("----------");
            MetricRegistry reg = regSvc.getMetricsRegistry();
            SortedMap<String, Counter> counters = reg.getCounters();
            LOG.info("Keys found {{}]", counters.keySet().size());
            for(String key : counters.keySet()) { 
                LOG.info("--- key [{}] - value [{}]", key, counters.get("key").getCount());
            }                
        } else { 
            System.out.println("Couldn't find MetricsRegisteryService instance");
        }
        context.suspend();        
        context.stop();
    }
}

============================
--- exec-maven-plugin:1.2.1:exec (default-cli) @ metricstest ---
2014-11-06 19:15:23 INFO  DefaultCamelContext        :1731 - Apache Camel 2.14.0 (CamelContext: camel-1) is starting
2014-11-06 19:15:23 INFO  ManagedManagementStrategy  : 187 - JMX is enabled
2014-11-06 19:15:23 INFO  DefaultTypeConverter       :  50 - Loaded 178 type converters
2014-11-06 19:15:23 INFO  MetricsComponent           : 108 - Creating new default MetricRegistry
2014-11-06 19:15:23 INFO  MetricsComponent           :  57 - Metrics type: counter; name: files-processed
2014-11-06 19:15:23 INFO  DefaultCamelContext        :1931 - AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
2014-11-06 19:15:23 INFO  DefaultCamelContext        :1941 - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
2014-11-06 19:15:23 INFO  DefaultCamelContext        :2453 - Route: testroute started and consuming from: Endpoint[file://c:/mdm/test/input]
2014-11-06 19:15:23 INFO  DefaultCamelContext        :1766 - Total 1 routes, of which 1 is started.
2014-11-06 19:15:23 INFO  DefaultCamelContext        :1767 - Apache Camel 2.14.0 (CamelContext: camel-1) started in 0.608 seconds
2014-11-06 19:15:24 INFO  testroute                  :  96 - Processing file [testfile1.txt]
2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile2.txt]
2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile3.txt]
2014-11-06 19:15:33 INFO  Main                       :  47 - Zzz...(10 seconds)
2014-11-06 19:15:43 INFO  Main                       :  47 - Zzz...(20 seconds)
2014-11-06 19:15:53 INFO  Main                       :  47 - Zzz...(30 seconds)
2014-11-06 19:16:03 INFO  Main                       :  47 - Zzz...(40 seconds)
2014-11-06 19:16:13 INFO  Main                       :  47 - Zzz...(50 seconds)
2014-11-06 19:16:23 INFO  MetricsComponent           : 104 - type=COUNTER, name=files-processed, count=3
2014-11-06 19:16:23 INFO  Main                       :  47 - Zzz...(60 seconds)
2014-11-06 19:16:33 INFO  Main                       :  47 - Zzz...(70 seconds)
2014-11-06 19:16:34 INFO  Main                       :  53 - {
  "version" : "3.0.0",
  "gauges" : { },
  "counters" : { },
  "histograms" : { },
  "meters" : { },
  "timers" : {
    "camel-1:testroute.responses" : {
      "count" : 3,
      "max" : 157.060387,
      "mean" : 88.249202,
      "min" : 44.265085,
      "p50" : 63.422134,
      "p75" : 157.060387,
      "p95" : 157.060387,
      "p98" : 157.060387,
      "p99" : 157.060387,
      "p999" : 157.060387,
      "stddev" : 60.35712482735794,
      "m15_rate" : 0.558194480485237,
      "m1_rate" : 0.20307925506404548,
      "m5_rate" : 0.48311899441084233,
      "mean_rate" : 0.04263368988938351,
      "duration_units" : "milliseconds",
      "rate_units" : "calls/second"
    }
  }
}
2014-11-06 19:16:34 INFO  Main                       :  54 - ----------
2014-11-06 19:16:34 INFO  Main                       :  57 - Keys found {0]
2014-11-06 19:16:34 INFO  DefaultCamelContext        :1648 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspending
2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 606 - Route: testroute suspend complete, was consuming from: Endpoint[file://c:/mdm/test/input]
2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
2014-11-06 19:16:34 INFO  DefaultCamelContext        :1686 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspended in 0.032 seconds
2014-11-06 19:16:34 INFO  DefaultCamelContext        :1958 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutting down
2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 609 - Route: testroute shutdown complete, was consuming from: Endpoint[file://c:/mdm/test/input]
2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
2014-11-06 19:16:34 INFO  DefaultCamelContext        :2040 - Apache Camel 2.14.0 (CamelContext: camel-1) uptime 1 minute
2014-11-06 19:16:34 INFO  DefaultCamelContext        :2041 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutdown in 0.000 seconds
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 1:12.415s
Finished at: Thu Nov 06 19:16:34 EST 2014
Final Memory: 5M/120M
------------------------------------------------------------------------

Re: camel-metrics Component

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Ah in blueprint its easier just declare a <bean> with
id="metricsRegistry" and its shared, eg.

<bean id="metricsRegistry" class="com.codahale.metrics.MetricsRegistry"/>

its the name metricsRegistry that has a special meaning

On Mon, Mar 2, 2015 at 8:20 AM, vivekt <vi...@gmail.com> wrote:
> Hello Claus,
>
> Thank you again for your reply. The code in java works and I can get the
> counter metrics values in MetricRegistry.
>
> I am now trying to figure out how can I create a bean in blueprint of
> SimpleRegistry which extends type HashMap.
> So far, I have this.
>
> <bean id="metricsRegistry" class="com.codahale.metrics.MetricsRegistry"/>
> <bean id="simpleRegistry" class="org.apache.camel.impl.SimpleRegistry">
>    <entry key="metricsRegistry" value-ref = "metricsRegistry" />
> </bean>
>
> Also, I am not sure how can I instantiate DefaultCamelContext and set
> SimpleRegistry in the constructor within blueprint (or even spring)
>
> It would be great if you can suggest the way to do it.
>
> Thanks,
>
> Vivek
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-metrics-Component-tp5758627p5763357.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: camel-metrics Component

Posted by vivekt <vi...@gmail.com>.
Hello Claus,

Thank you again for your reply. The code in java works and I can get the
counter metrics values in MetricRegistry.

I am now trying to figure out how can I create a bean in blueprint of
SimpleRegistry which extends type HashMap.
So far, I have this.

<bean id="metricsRegistry" class="com.codahale.metrics.MetricsRegistry"/>
<bean id="simpleRegistry" class="org.apache.camel.impl.SimpleRegistry">
   <entry key="metricsRegistry" value-ref = "metricsRegistry" />
</bean>

Also, I am not sure how can I instantiate DefaultCamelContext and set
SimpleRegistry in the constructor within blueprint (or even spring)

It would be great if you can suggest the way to do it.

Thanks,

Vivek



--
View this message in context: http://camel.465427.n5.nabble.com/camel-metrics-Component-tp5758627p5763357.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-metrics Component

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Setup a shared metrics registry with the name metricRegistry, then its shared.

If using java, then

SimpleRegistry map = new SimpleRegistry();
map.put("metricsRegistry, new MetricRegistry());

CamelContext context = new DefaultCamelContext(map);



On Sat, Feb 28, 2015 at 8:28 AM, vivekt <vi...@gmail.com> wrote:
> I am using metrics component of type counter in camel route. I do see the
> counters and their values reported in the logs every 1 minute, but I want to
> access these values via jmx so that I can push them to our dashboard.
>
> Here is the chunk of log file...
>
> 2015-02-26 17:23:49,948 | INFO  | eporter-thread-1 | MetricsComponent
> | 99 - org.apache.camel.camel-metrics - 2.14.1 | type=COUNTER,
> name=message.good.counts, count=4
> 2015-02-26 17:23:49,948 | INFO  | eporter-thread-1 | MetricsComponent
> | 99 - org.apache.camel.camel-metrics - 2.14.1 | type=COUNTER,
> name=message.incoming.counts, count=4
>
> I was hoping that since I am using MetricsRoutePolicy in my
> blueprintContext, these counters (and their values) will be reported and are
> accessible via MBean : MetricRegistryService. When I invoke the operation
> dumpStatisticsAsJson(), only timer metrics has values in json, and no
> counters are listed.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-metrics-Component-tp5758627p5763280.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: camel-metrics Component

Posted by vivekt <vi...@gmail.com>.
I am using metrics component of type counter in camel route. I do see the
counters and their values reported in the logs every 1 minute, but I want to
access these values via jmx so that I can push them to our dashboard.

Here is the chunk of log file...

2015-02-26 17:23:49,948 | INFO  | eporter-thread-1 | MetricsComponent                
| 99 - org.apache.camel.camel-metrics - 2.14.1 | type=COUNTER,
name=message.good.counts, count=4
2015-02-26 17:23:49,948 | INFO  | eporter-thread-1 | MetricsComponent                
| 99 - org.apache.camel.camel-metrics - 2.14.1 | type=COUNTER,
name=message.incoming.counts, count=4

I was hoping that since I am using MetricsRoutePolicy in my
blueprintContext, these counters (and their values) will be reported and are
accessible via MBean : MetricRegistryService. When I invoke the operation
dumpStatisticsAsJson(), only timer metrics has values in json, and no
counters are listed.



--
View this message in context: http://camel.465427.n5.nabble.com/camel-metrics-Component-tp5758627p5763280.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-metrics Component

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

What counters are you talking about?




On Thu, Feb 26, 2015 at 7:34 PM, vivekt <vi...@gmail.com> wrote:
> Hello Claus,
>
> Thank you for your quick reply.
> I do see that the metrics route policy is using a metrics timer to capture
> the data.
> But it does not have the counters values which I am using in the blueprint
> context.
>
> Do I have to write my own MetricsRoutePolicy (or extend it) so that all the
> counters are captured?
>
> Thanks,
>
> Vivek
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-metrics-Component-tp5758627p5763236.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: camel-metrics Component

Posted by vivekt <vi...@gmail.com>.
Hello Claus,

Thank you for your quick reply.
I do see that the metrics route policy is using a metrics timer to capture
the data. 
But it does not have the counters values which I am using in the blueprint
context.

Do I have to write my own MetricsRoutePolicy (or extend it) so that all the
counters are captured?

Thanks,

Vivek 



--
View this message in context: http://camel.465427.n5.nabble.com/camel-metrics-Component-tp5758627p5763236.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-metrics Component

Posted by Claus Ibsen <cl...@gmail.com>.
The metrics route policy is using a metrics timer to capture the data.
So the data is there in the json blob you posted.

https://github.com/apache/camel/blob/master/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java#L46

On Thu, Feb 26, 2015 at 12:43 AM, vivekt <vi...@gmail.com> wrote:
> Hello Claus, I tested Jim's orginal Java class with 2.14.1, but still could
> not get the metrics from MetricsRegistryService.
>
> When I invoke dumpStatisticsAsJson() , all the metrics are empty.
> Here is the output
>
> "version" : "3.0.0",
>   "gauges" : { },
>   "counters" : { },
>   "histograms" : { },
>   "meters" : { },
>   "timers" : {
>     "camel-1:testroute.responses" : {
>       "count" : 3,
>       "max" : 25.073,
>       "mean" : 9.543666666666665,
>       "min" : 1.5679999999999998,
>       "p50" : 1.99,
>       "p75" : 25.073,
>       "p95" : 25.073,
>       "p98" : 25.073,
>       "p99" : 25.073,
>       "p999" : 25.073,
>       "stddev" : 13.450452272445464,
>       "m15_rate" : 0.558194480485237,
>       "m1_rate" : 0.20307925506404548,
>       "m5_rate" : 0.48311899441084233,
>       "mean_rate" : 0.042752986809164464,
>       "duration_units" : "milliseconds",
>       "rate_units" : "calls/second"
>     }
>   }
> }
>
> My application uses blueprint and I want to expose the counters so that I
> can access the metrics via Hawtio
>
> In blueprint.xml, I have declared the bean as
>
> <bean id="metricsRoutePolicyFactory"
> class="org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFactory">
>                 <property name="useJmx" value="true"/>
>                 <property name="prettyPrint" value="true"/>
> </bean>
>
> In Hawtio interface, I do see the Mbean service but it does not have any
> counters in the output.
>
> Could you please let me know if the issue is fixed in 2.14.1?
> Is there something that I am missing?
>
> Thanks,
>
> Vivek
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-metrics-Component-tp5758627p5763182.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

RE: camel-metrics Component

Posted by vivekt <vi...@gmail.com>.
Hello Claus, I tested Jim's orginal Java class with 2.14.1, but still could
not get the metrics from MetricsRegistryService.

When I invoke dumpStatisticsAsJson() , all the metrics are empty.
Here is the output

"version" : "3.0.0",
  "gauges" : { },
  "counters" : { },
  "histograms" : { },
  "meters" : { },
  "timers" : {
    "camel-1:testroute.responses" : {
      "count" : 3,
      "max" : 25.073,
      "mean" : 9.543666666666665,
      "min" : 1.5679999999999998,
      "p50" : 1.99,
      "p75" : 25.073,
      "p95" : 25.073,
      "p98" : 25.073,
      "p99" : 25.073,
      "p999" : 25.073,
      "stddev" : 13.450452272445464,
      "m15_rate" : 0.558194480485237,
      "m1_rate" : 0.20307925506404548,
      "m5_rate" : 0.48311899441084233,
      "mean_rate" : 0.042752986809164464,
      "duration_units" : "milliseconds",
      "rate_units" : "calls/second"
    }
  }
}

My application uses blueprint and I want to expose the counters so that I
can access the metrics via Hawtio

In blueprint.xml, I have declared the bean as 

<bean id="metricsRoutePolicyFactory"
class="org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFactory">
		<property name="useJmx" value="true"/>
		<property name="prettyPrint" value="true"/>
</bean> 

In Hawtio interface, I do see the Mbean service but it does not have any
counters in the output.

Could you please let me know if the issue is fixed in 2.14.1?
Is there something that I am missing?

Thanks,

Vivek



--
View this message in context: http://camel.465427.n5.nabble.com/camel-metrics-Component-tp5758627p5763182.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: camel-metrics Component

Posted by James L Greene <jl...@aep.com>.
Thank you very much, Claus!  Your suggestion worked like a champ.  I look forward to seeing how this evolves.

Here's the final code that I implemented.

import com.codahale.metrics.Counter;
import com.codahale.metrics.MetricRegistry;
import java.util.SortedMap;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.SimpleRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {

    public static void main(String[] args) throws Exception {
        Logger LOG = LoggerFactory.getLogger(Main.class);

        SimpleRegistry registry = new SimpleRegistry();
        MetricRegistry metricRegistry = new com.codahale.metrics.MetricRegistry();
        registry.put("metricRegistry", metricRegistry);

        CamelContext context = new DefaultCamelContext(registry);

        RouteBuilder rb = new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("file://c:/mdm/test/input").
                        routeId("testroute").
                        log("Processing file [${header.CamelFileName}]").
                        to("metrics:counter:files-processed").
                        to("file://c:/mdm/test/output");
            }
        };
        context.addRoutes(rb);

        context.start();

        int sleepCounter = 0;
        while (sleepCounter < 7) {
            sleepCounter++;
            Thread.sleep(10000);
            LOG.info("Zzz...({} seconds)", sleepCounter * 10);
        }

        SortedMap<String, Counter> counters = metricRegistry.getCounters();
        LOG.info("Keys found {{}]", counters.keySet().size());
        for (String key : counters.keySet()) {
            LOG.info("--- key [{}] - value [{}]", key, counters.get(key).getCount());
        }

        context.suspend();
        context.stop();
    }
}

Thank you for being so responsive!

Regards, 
Jim

-----Original Message-----
From: Claus Ibsen [mailto:claus.ibsen@gmail.com] 
Sent: Friday, November 07, 2014 10:29 AM
To: users@camel.apache.org
Subject: Re: camel-metrics Component

 This is an EXTERNAL email. STOP. THINK before you CLICK links or OPEN attachments.

**********************************************************************
Hi

I logged a ticket to make it out of the box using the same codehale metrics.
https://issues.apache.org/jira/browse/CAMEL-8014


On Fri, Nov 7, 2014 at 4:22 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Yeah it looks like by default they wont use same registry because you 
> would need to add a registry with a name to the registry, and then 
> configure the metrics camel component to use a registry by its name.
>
> The default name to lookup is "metricRegistry" so you can do
>
> Map registry = new SimpleRegistry();
> registry.put("metricsRegistry", new 
> com.codahale.metrics.MetricRegistry();
>
> CamelContext camel = new DefaultCamelContext(registry);
>
>
>
>
>
> On Fri, Nov 7, 2014 at 4:04 PM, James L Greene <jl...@aep.com> wrote:
>> So you're saying this is something that would have to go on the development roadmap?  I'm writing several batch/standalone processes which I need to capture metrics like this, to be recorded in a data reconciliation system.  This component seemed like a good way to go, but if I can't capture the metrics at the end of the job, I might have to figure out another way to do this.
>>
>> Regards,
>> Jim Greene
>> Principal IT Architect, Enterprise Architecture & Strategy American 
>> Electric Power One Riverside Plaza, 11th Floor Columbus, OH 43125
>> Phone:  (w) 614-716-2617
>> Email:  jlgreene2@aep.com
>>
>>
>> -----Original Message-----
>> From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
>> Sent: Friday, November 07, 2014 9:26 AM
>> To: users@camel.apache.org
>> Subject: Re: camel-metrics Component
>>
>>  This is an EXTERNAL email. STOP. THINK before you CLICK links or OPEN attachments.
>>
>> *********************************************************************
>> * Ah the route policy and the metrics component is not identical. 
>> They are just hosted in the same JAR.
>>
>> The route policy is self container what details it records. I guess we could combine those so you can also do like you to add custom counters with the Camel routes.
>>
>> eg a bit of history then camel-metrics was first only a regular component. The route policy was added later to make it easy to turn that on in a single spot, and get metrics for all your routes.
>>
>> On Fri, Nov 7, 2014 at 3:07 PM, James L Greene <jl...@aep.com> wrote:
>>> Claus,
>>>
>>> I gave your suggestion a try.  There was no change in the output.  The camel-metrics component is displaying the value of the counters via the logger, but the counters collection is empty when I try to access it programmatically.
>>>
>>> Regards,
>>> Jim Greene
>>> Principal IT Architect, Enterprise Architecture & Strategy American 
>>> Electric Power One Riverside Plaza, 11th Floor Columbus, OH 43125
>>> Phone:  (w) 614-716-2617
>>> Email:  jlgreene2@aep.com
>>>
>>>
>>> -----Original Message-----
>>> From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
>>> Sent: Friday, November 07, 2014 1:27 AM
>>> To: users@camel.apache.org
>>> Subject: Re: camel-metrics Component
>>>
>>>  This is an EXTERNAL email. STOP. THINK before you CLICK links or OPEN attachments.
>>>
>>> ********************************************************************
>>> ** Try setting the route policy before adding the routes
>>>
>>> On Fri, Nov 7, 2014 at 1:35 AM, James L Greene <jl...@aep.com> wrote:
>>>> I have written a simple Java class to attempt to exercise the camel-metrics component.  In this example, I'm writing a standalone Java batch process, which will read files from an input directory, and deposit the files in an output directory.  I'm attempting to use the camel-metrics component to capture how many files were read (using the name "files-processed").  I've configured the class to only run for seventy seconds, giving the camel-metrics component an opportunity to output the values of the metric being captured to the application log (which its configured to do at sixty seconds intervals, and which appears to work properly).
>>>>
>>>> Prior to suspending/stopping my CamelContext, I attempted to retrieve the metrics as described in the camel-metrics component documentation.  Unfortunately, when I look at the contents of the metrics, my custom metric is nowhere to be found.  Below, please find the source for the sample class that I created, and its logged output.
>>>>
>>>> Am I doing something wrong?
>>>>
>>>> ============================
>>>>
>>>> Camel Version
>>>> 2.14.0
>>>>
>>>> JRE Version
>>>> java version "1.7.0_25"
>>>> Java(TM) SE Runtime Environment (build 1.7.0_25-b17) Java 
>>>> HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
>>>>
>>>> ============================
>>>>
>>>> package ...
>>>>
>>>> import com.codahale.metrics.Counter; import 
>>>> com.codahale.metrics.MetricRegistry;
>>>> import java.util.SortedMap;
>>>> import org.apache.camel.CamelContext; import 
>>>> org.apache.camel.builder.RouteBuilder;
>>>> import
>>>> org.apache.camel.component.metrics.routepolicy.MetricsRegistryServi
>>>> ce
>>>> ;
>>>> import
>>>> org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFa
>>>> ct o ry; import org.apache.camel.impl.DefaultCamelContext;
>>>> import org.slf4j.Logger;
>>>> import org.slf4j.LoggerFactory;
>>>>
>>>> public class Main {
>>>>
>>>>     public static void main(String[] args) throws Exception {
>>>>         Logger LOG = LoggerFactory.getLogger(Main.class);
>>>>
>>>>         CamelContext context = new DefaultCamelContext();
>>>>
>>>>         RouteBuilder rb = new RouteBuilder() {
>>>>             @Override
>>>>             public void configure() throws Exception {
>>>>                 from("file://c:/test/input").
>>>>                         routeId("testroute").
>>>>                         log("Processing file [${header.CamelFileName}]").
>>>>                         to("metrics:counter:files-processed").
>>>>                         to("file://c:/test/output");
>>>>             }
>>>>         };
>>>>         context.addRoutes(rb);
>>>>
>>>>         MetricsRoutePolicyFactory mrpf = new MetricsRoutePolicyFactory();
>>>>         context.addRoutePolicyFactory(mrpf);
>>>>
>>>>         context.start();
>>>>
>>>>         int sleepCounter = 0;
>>>>         while (sleepCounter < 7) {
>>>>             sleepCounter++;
>>>>             Thread.sleep(10000);
>>>>             LOG.info("Zzz...({} seconds)", sleepCounter * 10);
>>>>         }
>>>>
>>>>         MetricsRegistryService regSvc = context.hasService(MetricsRegistryService.class);
>>>>         if(regSvc != null) {
>>>>             // Dump the statistics to the log in JSON format.
>>>>             regSvc.setPrettyPrint(true);
>>>>             LOG.info(regSvc.dumpStatisticsAsJson());
>>>>
>>>>             // Do it again, retrieving the map of counters from the MetricRegistry object.
>>>>             LOG.info("----------");
>>>>             MetricRegistry reg = regSvc.getMetricsRegistry();
>>>>             SortedMap<String, Counter> counters = reg.getCounters();
>>>>             LOG.info("Keys found {{}]", counters.keySet().size());
>>>>             for(String key : counters.keySet()) {
>>>>                 LOG.info("--- key [{}] - value [{}]", key, counters.get("key").getCount());
>>>>             }
>>>>         } else {
>>>>             System.out.println("Couldn't find MetricsRegisteryService instance");
>>>>         }
>>>>         context.suspend();
>>>>         context.stop();
>>>>     }
>>>> }
>>>>
>>>> ============================
>>>> --- exec-maven-plugin:1.2.1:exec (default-cli) @ metricstest ---
>>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1731 - Apache Camel 2.14.0 (CamelContext: camel-1) is starting
>>>> 2014-11-06 19:15:23 INFO  ManagedManagementStrategy  : 187 - JMX is enabled
>>>> 2014-11-06 19:15:23 INFO  DefaultTypeConverter       :  50 - Loaded 178 type converters
>>>> 2014-11-06 19:15:23 INFO  MetricsComponent           : 108 - Creating new default MetricRegistry
>>>> 2014-11-06 19:15:23 INFO  MetricsComponent           :  57 - Metrics type: counter; name: files-processed
>>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1931 - AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
>>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1941 - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
>>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :2453 - Route: testroute started and consuming from: Endpoint[file://c:/mdm/test/input]
>>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1766 - Total 1 routes, of which 1 is started.
>>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1767 - Apache Camel 2.14.0 (CamelContext: camel-1) started in 0.608 seconds
>>>> 2014-11-06 19:15:24 INFO  testroute                  :  96 - Processing file [testfile1.txt]
>>>> 2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile2.txt]
>>>> 2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile3.txt]
>>>> 2014-11-06 19:15:33 INFO  Main                       :  47 - Zzz...(10 seconds)
>>>> 2014-11-06 19:15:43 INFO  Main                       :  47 - Zzz...(20 seconds)
>>>> 2014-11-06 19:15:53 INFO  Main                       :  47 - Zzz...(30 seconds)
>>>> 2014-11-06 19:16:03 INFO  Main                       :  47 - Zzz...(40 seconds)
>>>> 2014-11-06 19:16:13 INFO  Main                       :  47 - Zzz...(50 seconds)
>>>> 2014-11-06 19:16:23 INFO  MetricsComponent           : 104 - type=COUNTER, name=files-processed, count=3
>>>> 2014-11-06 19:16:23 INFO  Main                       :  47 - Zzz...(60 seconds)
>>>> 2014-11-06 19:16:33 INFO  Main                       :  47 - Zzz...(70 seconds)
>>>> 2014-11-06 19:16:34 INFO  Main                       :  53 - {
>>>>   "version" : "3.0.0",
>>>>   "gauges" : { },
>>>>   "counters" : { },
>>>>   "histograms" : { },
>>>>   "meters" : { },
>>>>   "timers" : {
>>>>     "camel-1:testroute.responses" : {
>>>>       "count" : 3,
>>>>       "max" : 157.060387,
>>>>       "mean" : 88.249202,
>>>>       "min" : 44.265085,
>>>>       "p50" : 63.422134,
>>>>       "p75" : 157.060387,
>>>>       "p95" : 157.060387,
>>>>       "p98" : 157.060387,
>>>>       "p99" : 157.060387,
>>>>       "p999" : 157.060387,
>>>>       "stddev" : 60.35712482735794,
>>>>       "m15_rate" : 0.558194480485237,
>>>>       "m1_rate" : 0.20307925506404548,
>>>>       "m5_rate" : 0.48311899441084233,
>>>>       "mean_rate" : 0.04263368988938351,
>>>>       "duration_units" : "milliseconds",
>>>>       "rate_units" : "calls/second"
>>>>     }
>>>>   }
>>>> }
>>>> 2014-11-06 19:16:34 INFO  Main                       :  54 - ----------
>>>> 2014-11-06 19:16:34 INFO  Main                       :  57 - Keys found {0]
>>>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1648 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspending
>>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
>>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 606 - Route: testroute suspend complete, was consuming from: Endpoint[file://c:/mdm/test/input]
>>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
>>>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1686 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspended in 0.032 seconds
>>>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1958 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutting down
>>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
>>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 609 - Route: testroute shutdown complete, was consuming from: Endpoint[file://c:/mdm/test/input]
>>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
>>>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :2040 - Apache Camel 2.14.0 (CamelContext: camel-1) uptime 1 minute
>>>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :2041 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutdown in 0.000 seconds
>>>> -------------------------------------------------------------------
>>>> --
>>>> -
>>>> --
>>>> BUILD SUCCESS
>>>> -------------------------------------------------------------------
>>>> --
>>>> -
>>>> --
>>>> Total time: 1:12.415s
>>>> Finished at: Thu Nov 06 19:16:34 EST 2014 Final Memory: 5M/120M
>>>> -------------------------------------------------------------------
>>>> --
>>>> -
>>>> --
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> -----------------
>>> Red Hat, Inc.
>>> Email: cibsen@redhat.com
>>> Twitter: davsclaus
>>> Blog: http://davsclaus.com
>>> Author of Camel in Action: http://www.manning.com/ibsen
>>> hawtio: http://hawt.io/
>>> fabric8: http://fabric8.io/
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> Email: cibsen@redhat.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>> hawtio: http://hawt.io/
>> fabric8: http://fabric8.io/
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: camel-metrics Component

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I logged a ticket to make it out of the box using the same codehale metrics.
https://issues.apache.org/jira/browse/CAMEL-8014


On Fri, Nov 7, 2014 at 4:22 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Yeah it looks like by default they wont use same registry because you
> would need to add a registry with a name to the registry, and then
> configure the metrics camel component to use a registry by its name.
>
> The default name to lookup is "metricRegistry" so you can do
>
> Map registry = new SimpleRegistry();
> registry.put("metricsRegistry", new com.codahale.metrics.MetricRegistry();
>
> CamelContext camel = new DefaultCamelContext(registry);
>
>
>
>
>
> On Fri, Nov 7, 2014 at 4:04 PM, James L Greene <jl...@aep.com> wrote:
>> So you're saying this is something that would have to go on the development roadmap?  I'm writing several batch/standalone processes which I need to capture metrics like this, to be recorded in a data reconciliation system.  This component seemed like a good way to go, but if I can't capture the metrics at the end of the job, I might have to figure out another way to do this.
>>
>> Regards,
>> Jim Greene
>> Principal IT Architect, Enterprise Architecture & Strategy
>> American Electric Power
>> One Riverside Plaza, 11th Floor
>> Columbus, OH 43125
>> Phone:  (w) 614-716-2617
>> Email:  jlgreene2@aep.com
>>
>>
>> -----Original Message-----
>> From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
>> Sent: Friday, November 07, 2014 9:26 AM
>> To: users@camel.apache.org
>> Subject: Re: camel-metrics Component
>>
>>  This is an EXTERNAL email. STOP. THINK before you CLICK links or OPEN attachments.
>>
>> **********************************************************************
>> Ah the route policy and the metrics component is not identical. They are just hosted in the same JAR.
>>
>> The route policy is self container what details it records. I guess we could combine those so you can also do like you to add custom counters with the Camel routes.
>>
>> eg a bit of history then camel-metrics was first only a regular component. The route policy was added later to make it easy to turn that on in a single spot, and get metrics for all your routes.
>>
>> On Fri, Nov 7, 2014 at 3:07 PM, James L Greene <jl...@aep.com> wrote:
>>> Claus,
>>>
>>> I gave your suggestion a try.  There was no change in the output.  The camel-metrics component is displaying the value of the counters via the logger, but the counters collection is empty when I try to access it programmatically.
>>>
>>> Regards,
>>> Jim Greene
>>> Principal IT Architect, Enterprise Architecture & Strategy American
>>> Electric Power One Riverside Plaza, 11th Floor Columbus, OH 43125
>>> Phone:  (w) 614-716-2617
>>> Email:  jlgreene2@aep.com
>>>
>>>
>>> -----Original Message-----
>>> From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
>>> Sent: Friday, November 07, 2014 1:27 AM
>>> To: users@camel.apache.org
>>> Subject: Re: camel-metrics Component
>>>
>>>  This is an EXTERNAL email. STOP. THINK before you CLICK links or OPEN attachments.
>>>
>>> **********************************************************************
>>> Try setting the route policy before adding the routes
>>>
>>> On Fri, Nov 7, 2014 at 1:35 AM, James L Greene <jl...@aep.com> wrote:
>>>> I have written a simple Java class to attempt to exercise the camel-metrics component.  In this example, I'm writing a standalone Java batch process, which will read files from an input directory, and deposit the files in an output directory.  I'm attempting to use the camel-metrics component to capture how many files were read (using the name "files-processed").  I've configured the class to only run for seventy seconds, giving the camel-metrics component an opportunity to output the values of the metric being captured to the application log (which its configured to do at sixty seconds intervals, and which appears to work properly).
>>>>
>>>> Prior to suspending/stopping my CamelContext, I attempted to retrieve the metrics as described in the camel-metrics component documentation.  Unfortunately, when I look at the contents of the metrics, my custom metric is nowhere to be found.  Below, please find the source for the sample class that I created, and its logged output.
>>>>
>>>> Am I doing something wrong?
>>>>
>>>> ============================
>>>>
>>>> Camel Version
>>>> 2.14.0
>>>>
>>>> JRE Version
>>>> java version "1.7.0_25"
>>>> Java(TM) SE Runtime Environment (build 1.7.0_25-b17) Java HotSpot(TM)
>>>> 64-Bit Server VM (build 23.25-b01, mixed mode)
>>>>
>>>> ============================
>>>>
>>>> package ...
>>>>
>>>> import com.codahale.metrics.Counter;
>>>> import com.codahale.metrics.MetricRegistry;
>>>> import java.util.SortedMap;
>>>> import org.apache.camel.CamelContext; import
>>>> org.apache.camel.builder.RouteBuilder;
>>>> import
>>>> org.apache.camel.component.metrics.routepolicy.MetricsRegistryService
>>>> ;
>>>> import
>>>> org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFact
>>>> o ry; import org.apache.camel.impl.DefaultCamelContext;
>>>> import org.slf4j.Logger;
>>>> import org.slf4j.LoggerFactory;
>>>>
>>>> public class Main {
>>>>
>>>>     public static void main(String[] args) throws Exception {
>>>>         Logger LOG = LoggerFactory.getLogger(Main.class);
>>>>
>>>>         CamelContext context = new DefaultCamelContext();
>>>>
>>>>         RouteBuilder rb = new RouteBuilder() {
>>>>             @Override
>>>>             public void configure() throws Exception {
>>>>                 from("file://c:/test/input").
>>>>                         routeId("testroute").
>>>>                         log("Processing file [${header.CamelFileName}]").
>>>>                         to("metrics:counter:files-processed").
>>>>                         to("file://c:/test/output");
>>>>             }
>>>>         };
>>>>         context.addRoutes(rb);
>>>>
>>>>         MetricsRoutePolicyFactory mrpf = new MetricsRoutePolicyFactory();
>>>>         context.addRoutePolicyFactory(mrpf);
>>>>
>>>>         context.start();
>>>>
>>>>         int sleepCounter = 0;
>>>>         while (sleepCounter < 7) {
>>>>             sleepCounter++;
>>>>             Thread.sleep(10000);
>>>>             LOG.info("Zzz...({} seconds)", sleepCounter * 10);
>>>>         }
>>>>
>>>>         MetricsRegistryService regSvc = context.hasService(MetricsRegistryService.class);
>>>>         if(regSvc != null) {
>>>>             // Dump the statistics to the log in JSON format.
>>>>             regSvc.setPrettyPrint(true);
>>>>             LOG.info(regSvc.dumpStatisticsAsJson());
>>>>
>>>>             // Do it again, retrieving the map of counters from the MetricRegistry object.
>>>>             LOG.info("----------");
>>>>             MetricRegistry reg = regSvc.getMetricsRegistry();
>>>>             SortedMap<String, Counter> counters = reg.getCounters();
>>>>             LOG.info("Keys found {{}]", counters.keySet().size());
>>>>             for(String key : counters.keySet()) {
>>>>                 LOG.info("--- key [{}] - value [{}]", key, counters.get("key").getCount());
>>>>             }
>>>>         } else {
>>>>             System.out.println("Couldn't find MetricsRegisteryService instance");
>>>>         }
>>>>         context.suspend();
>>>>         context.stop();
>>>>     }
>>>> }
>>>>
>>>> ============================
>>>> --- exec-maven-plugin:1.2.1:exec (default-cli) @ metricstest ---
>>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1731 - Apache Camel 2.14.0 (CamelContext: camel-1) is starting
>>>> 2014-11-06 19:15:23 INFO  ManagedManagementStrategy  : 187 - JMX is enabled
>>>> 2014-11-06 19:15:23 INFO  DefaultTypeConverter       :  50 - Loaded 178 type converters
>>>> 2014-11-06 19:15:23 INFO  MetricsComponent           : 108 - Creating new default MetricRegistry
>>>> 2014-11-06 19:15:23 INFO  MetricsComponent           :  57 - Metrics type: counter; name: files-processed
>>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1931 - AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
>>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1941 - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
>>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :2453 - Route: testroute started and consuming from: Endpoint[file://c:/mdm/test/input]
>>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1766 - Total 1 routes, of which 1 is started.
>>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1767 - Apache Camel 2.14.0 (CamelContext: camel-1) started in 0.608 seconds
>>>> 2014-11-06 19:15:24 INFO  testroute                  :  96 - Processing file [testfile1.txt]
>>>> 2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile2.txt]
>>>> 2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile3.txt]
>>>> 2014-11-06 19:15:33 INFO  Main                       :  47 - Zzz...(10 seconds)
>>>> 2014-11-06 19:15:43 INFO  Main                       :  47 - Zzz...(20 seconds)
>>>> 2014-11-06 19:15:53 INFO  Main                       :  47 - Zzz...(30 seconds)
>>>> 2014-11-06 19:16:03 INFO  Main                       :  47 - Zzz...(40 seconds)
>>>> 2014-11-06 19:16:13 INFO  Main                       :  47 - Zzz...(50 seconds)
>>>> 2014-11-06 19:16:23 INFO  MetricsComponent           : 104 - type=COUNTER, name=files-processed, count=3
>>>> 2014-11-06 19:16:23 INFO  Main                       :  47 - Zzz...(60 seconds)
>>>> 2014-11-06 19:16:33 INFO  Main                       :  47 - Zzz...(70 seconds)
>>>> 2014-11-06 19:16:34 INFO  Main                       :  53 - {
>>>>   "version" : "3.0.0",
>>>>   "gauges" : { },
>>>>   "counters" : { },
>>>>   "histograms" : { },
>>>>   "meters" : { },
>>>>   "timers" : {
>>>>     "camel-1:testroute.responses" : {
>>>>       "count" : 3,
>>>>       "max" : 157.060387,
>>>>       "mean" : 88.249202,
>>>>       "min" : 44.265085,
>>>>       "p50" : 63.422134,
>>>>       "p75" : 157.060387,
>>>>       "p95" : 157.060387,
>>>>       "p98" : 157.060387,
>>>>       "p99" : 157.060387,
>>>>       "p999" : 157.060387,
>>>>       "stddev" : 60.35712482735794,
>>>>       "m15_rate" : 0.558194480485237,
>>>>       "m1_rate" : 0.20307925506404548,
>>>>       "m5_rate" : 0.48311899441084233,
>>>>       "mean_rate" : 0.04263368988938351,
>>>>       "duration_units" : "milliseconds",
>>>>       "rate_units" : "calls/second"
>>>>     }
>>>>   }
>>>> }
>>>> 2014-11-06 19:16:34 INFO  Main                       :  54 - ----------
>>>> 2014-11-06 19:16:34 INFO  Main                       :  57 - Keys found {0]
>>>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1648 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspending
>>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
>>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 606 - Route: testroute suspend complete, was consuming from: Endpoint[file://c:/mdm/test/input]
>>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
>>>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1686 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspended in 0.032 seconds
>>>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1958 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutting down
>>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
>>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 609 - Route: testroute shutdown complete, was consuming from: Endpoint[file://c:/mdm/test/input]
>>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
>>>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :2040 - Apache Camel 2.14.0 (CamelContext: camel-1) uptime 1 minute
>>>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :2041 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutdown in 0.000 seconds
>>>> ---------------------------------------------------------------------
>>>> -
>>>> --
>>>> BUILD SUCCESS
>>>> ---------------------------------------------------------------------
>>>> -
>>>> --
>>>> Total time: 1:12.415s
>>>> Finished at: Thu Nov 06 19:16:34 EST 2014 Final Memory: 5M/120M
>>>> ---------------------------------------------------------------------
>>>> -
>>>> --
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> -----------------
>>> Red Hat, Inc.
>>> Email: cibsen@redhat.com
>>> Twitter: davsclaus
>>> Blog: http://davsclaus.com
>>> Author of Camel in Action: http://www.manning.com/ibsen
>>> hawtio: http://hawt.io/
>>> fabric8: http://fabric8.io/
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> Email: cibsen@redhat.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>> hawtio: http://hawt.io/
>> fabric8: http://fabric8.io/
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: camel-metrics Component

Posted by Claus Ibsen <cl...@gmail.com>.
Yeah it looks like by default they wont use same registry because you
would need to add a registry with a name to the registry, and then
configure the metrics camel component to use a registry by its name.

The default name to lookup is "metricRegistry" so you can do

Map registry = new SimpleRegistry();
registry.put("metricsRegistry", new com.codahale.metrics.MetricRegistry();

CamelContext camel = new DefaultCamelContext(registry);





On Fri, Nov 7, 2014 at 4:04 PM, James L Greene <jl...@aep.com> wrote:
> So you're saying this is something that would have to go on the development roadmap?  I'm writing several batch/standalone processes which I need to capture metrics like this, to be recorded in a data reconciliation system.  This component seemed like a good way to go, but if I can't capture the metrics at the end of the job, I might have to figure out another way to do this.
>
> Regards,
> Jim Greene
> Principal IT Architect, Enterprise Architecture & Strategy
> American Electric Power
> One Riverside Plaza, 11th Floor
> Columbus, OH 43125
> Phone:  (w) 614-716-2617
> Email:  jlgreene2@aep.com
>
>
> -----Original Message-----
> From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> Sent: Friday, November 07, 2014 9:26 AM
> To: users@camel.apache.org
> Subject: Re: camel-metrics Component
>
>  This is an EXTERNAL email. STOP. THINK before you CLICK links or OPEN attachments.
>
> **********************************************************************
> Ah the route policy and the metrics component is not identical. They are just hosted in the same JAR.
>
> The route policy is self container what details it records. I guess we could combine those so you can also do like you to add custom counters with the Camel routes.
>
> eg a bit of history then camel-metrics was first only a regular component. The route policy was added later to make it easy to turn that on in a single spot, and get metrics for all your routes.
>
> On Fri, Nov 7, 2014 at 3:07 PM, James L Greene <jl...@aep.com> wrote:
>> Claus,
>>
>> I gave your suggestion a try.  There was no change in the output.  The camel-metrics component is displaying the value of the counters via the logger, but the counters collection is empty when I try to access it programmatically.
>>
>> Regards,
>> Jim Greene
>> Principal IT Architect, Enterprise Architecture & Strategy American
>> Electric Power One Riverside Plaza, 11th Floor Columbus, OH 43125
>> Phone:  (w) 614-716-2617
>> Email:  jlgreene2@aep.com
>>
>>
>> -----Original Message-----
>> From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
>> Sent: Friday, November 07, 2014 1:27 AM
>> To: users@camel.apache.org
>> Subject: Re: camel-metrics Component
>>
>>  This is an EXTERNAL email. STOP. THINK before you CLICK links or OPEN attachments.
>>
>> **********************************************************************
>> Try setting the route policy before adding the routes
>>
>> On Fri, Nov 7, 2014 at 1:35 AM, James L Greene <jl...@aep.com> wrote:
>>> I have written a simple Java class to attempt to exercise the camel-metrics component.  In this example, I'm writing a standalone Java batch process, which will read files from an input directory, and deposit the files in an output directory.  I'm attempting to use the camel-metrics component to capture how many files were read (using the name "files-processed").  I've configured the class to only run for seventy seconds, giving the camel-metrics component an opportunity to output the values of the metric being captured to the application log (which its configured to do at sixty seconds intervals, and which appears to work properly).
>>>
>>> Prior to suspending/stopping my CamelContext, I attempted to retrieve the metrics as described in the camel-metrics component documentation.  Unfortunately, when I look at the contents of the metrics, my custom metric is nowhere to be found.  Below, please find the source for the sample class that I created, and its logged output.
>>>
>>> Am I doing something wrong?
>>>
>>> ============================
>>>
>>> Camel Version
>>> 2.14.0
>>>
>>> JRE Version
>>> java version "1.7.0_25"
>>> Java(TM) SE Runtime Environment (build 1.7.0_25-b17) Java HotSpot(TM)
>>> 64-Bit Server VM (build 23.25-b01, mixed mode)
>>>
>>> ============================
>>>
>>> package ...
>>>
>>> import com.codahale.metrics.Counter;
>>> import com.codahale.metrics.MetricRegistry;
>>> import java.util.SortedMap;
>>> import org.apache.camel.CamelContext; import
>>> org.apache.camel.builder.RouteBuilder;
>>> import
>>> org.apache.camel.component.metrics.routepolicy.MetricsRegistryService
>>> ;
>>> import
>>> org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFact
>>> o ry; import org.apache.camel.impl.DefaultCamelContext;
>>> import org.slf4j.Logger;
>>> import org.slf4j.LoggerFactory;
>>>
>>> public class Main {
>>>
>>>     public static void main(String[] args) throws Exception {
>>>         Logger LOG = LoggerFactory.getLogger(Main.class);
>>>
>>>         CamelContext context = new DefaultCamelContext();
>>>
>>>         RouteBuilder rb = new RouteBuilder() {
>>>             @Override
>>>             public void configure() throws Exception {
>>>                 from("file://c:/test/input").
>>>                         routeId("testroute").
>>>                         log("Processing file [${header.CamelFileName}]").
>>>                         to("metrics:counter:files-processed").
>>>                         to("file://c:/test/output");
>>>             }
>>>         };
>>>         context.addRoutes(rb);
>>>
>>>         MetricsRoutePolicyFactory mrpf = new MetricsRoutePolicyFactory();
>>>         context.addRoutePolicyFactory(mrpf);
>>>
>>>         context.start();
>>>
>>>         int sleepCounter = 0;
>>>         while (sleepCounter < 7) {
>>>             sleepCounter++;
>>>             Thread.sleep(10000);
>>>             LOG.info("Zzz...({} seconds)", sleepCounter * 10);
>>>         }
>>>
>>>         MetricsRegistryService regSvc = context.hasService(MetricsRegistryService.class);
>>>         if(regSvc != null) {
>>>             // Dump the statistics to the log in JSON format.
>>>             regSvc.setPrettyPrint(true);
>>>             LOG.info(regSvc.dumpStatisticsAsJson());
>>>
>>>             // Do it again, retrieving the map of counters from the MetricRegistry object.
>>>             LOG.info("----------");
>>>             MetricRegistry reg = regSvc.getMetricsRegistry();
>>>             SortedMap<String, Counter> counters = reg.getCounters();
>>>             LOG.info("Keys found {{}]", counters.keySet().size());
>>>             for(String key : counters.keySet()) {
>>>                 LOG.info("--- key [{}] - value [{}]", key, counters.get("key").getCount());
>>>             }
>>>         } else {
>>>             System.out.println("Couldn't find MetricsRegisteryService instance");
>>>         }
>>>         context.suspend();
>>>         context.stop();
>>>     }
>>> }
>>>
>>> ============================
>>> --- exec-maven-plugin:1.2.1:exec (default-cli) @ metricstest ---
>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1731 - Apache Camel 2.14.0 (CamelContext: camel-1) is starting
>>> 2014-11-06 19:15:23 INFO  ManagedManagementStrategy  : 187 - JMX is enabled
>>> 2014-11-06 19:15:23 INFO  DefaultTypeConverter       :  50 - Loaded 178 type converters
>>> 2014-11-06 19:15:23 INFO  MetricsComponent           : 108 - Creating new default MetricRegistry
>>> 2014-11-06 19:15:23 INFO  MetricsComponent           :  57 - Metrics type: counter; name: files-processed
>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1931 - AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1941 - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :2453 - Route: testroute started and consuming from: Endpoint[file://c:/mdm/test/input]
>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1766 - Total 1 routes, of which 1 is started.
>>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1767 - Apache Camel 2.14.0 (CamelContext: camel-1) started in 0.608 seconds
>>> 2014-11-06 19:15:24 INFO  testroute                  :  96 - Processing file [testfile1.txt]
>>> 2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile2.txt]
>>> 2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile3.txt]
>>> 2014-11-06 19:15:33 INFO  Main                       :  47 - Zzz...(10 seconds)
>>> 2014-11-06 19:15:43 INFO  Main                       :  47 - Zzz...(20 seconds)
>>> 2014-11-06 19:15:53 INFO  Main                       :  47 - Zzz...(30 seconds)
>>> 2014-11-06 19:16:03 INFO  Main                       :  47 - Zzz...(40 seconds)
>>> 2014-11-06 19:16:13 INFO  Main                       :  47 - Zzz...(50 seconds)
>>> 2014-11-06 19:16:23 INFO  MetricsComponent           : 104 - type=COUNTER, name=files-processed, count=3
>>> 2014-11-06 19:16:23 INFO  Main                       :  47 - Zzz...(60 seconds)
>>> 2014-11-06 19:16:33 INFO  Main                       :  47 - Zzz...(70 seconds)
>>> 2014-11-06 19:16:34 INFO  Main                       :  53 - {
>>>   "version" : "3.0.0",
>>>   "gauges" : { },
>>>   "counters" : { },
>>>   "histograms" : { },
>>>   "meters" : { },
>>>   "timers" : {
>>>     "camel-1:testroute.responses" : {
>>>       "count" : 3,
>>>       "max" : 157.060387,
>>>       "mean" : 88.249202,
>>>       "min" : 44.265085,
>>>       "p50" : 63.422134,
>>>       "p75" : 157.060387,
>>>       "p95" : 157.060387,
>>>       "p98" : 157.060387,
>>>       "p99" : 157.060387,
>>>       "p999" : 157.060387,
>>>       "stddev" : 60.35712482735794,
>>>       "m15_rate" : 0.558194480485237,
>>>       "m1_rate" : 0.20307925506404548,
>>>       "m5_rate" : 0.48311899441084233,
>>>       "mean_rate" : 0.04263368988938351,
>>>       "duration_units" : "milliseconds",
>>>       "rate_units" : "calls/second"
>>>     }
>>>   }
>>> }
>>> 2014-11-06 19:16:34 INFO  Main                       :  54 - ----------
>>> 2014-11-06 19:16:34 INFO  Main                       :  57 - Keys found {0]
>>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1648 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspending
>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 606 - Route: testroute suspend complete, was consuming from: Endpoint[file://c:/mdm/test/input]
>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
>>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1686 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspended in 0.032 seconds
>>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1958 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutting down
>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 609 - Route: testroute shutdown complete, was consuming from: Endpoint[file://c:/mdm/test/input]
>>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
>>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :2040 - Apache Camel 2.14.0 (CamelContext: camel-1) uptime 1 minute
>>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :2041 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutdown in 0.000 seconds
>>> ---------------------------------------------------------------------
>>> -
>>> --
>>> BUILD SUCCESS
>>> ---------------------------------------------------------------------
>>> -
>>> --
>>> Total time: 1:12.415s
>>> Finished at: Thu Nov 06 19:16:34 EST 2014 Final Memory: 5M/120M
>>> ---------------------------------------------------------------------
>>> -
>>> --
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> Email: cibsen@redhat.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>> hawtio: http://hawt.io/
>> fabric8: http://fabric8.io/
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

RE: camel-metrics Component

Posted by James L Greene <jl...@aep.com>.
So you're saying this is something that would have to go on the development roadmap?  I'm writing several batch/standalone processes which I need to capture metrics like this, to be recorded in a data reconciliation system.  This component seemed like a good way to go, but if I can't capture the metrics at the end of the job, I might have to figure out another way to do this.

Regards,
Jim Greene
Principal IT Architect, Enterprise Architecture & Strategy
American Electric Power
One Riverside Plaza, 11th Floor
Columbus, OH 43125
Phone:  (w) 614-716-2617 
Email:  jlgreene2@aep.com


-----Original Message-----
From: Claus Ibsen [mailto:claus.ibsen@gmail.com] 
Sent: Friday, November 07, 2014 9:26 AM
To: users@camel.apache.org
Subject: Re: camel-metrics Component

 This is an EXTERNAL email. STOP. THINK before you CLICK links or OPEN attachments.

**********************************************************************
Ah the route policy and the metrics component is not identical. They are just hosted in the same JAR.

The route policy is self container what details it records. I guess we could combine those so you can also do like you to add custom counters with the Camel routes.

eg a bit of history then camel-metrics was first only a regular component. The route policy was added later to make it easy to turn that on in a single spot, and get metrics for all your routes.

On Fri, Nov 7, 2014 at 3:07 PM, James L Greene <jl...@aep.com> wrote:
> Claus,
>
> I gave your suggestion a try.  There was no change in the output.  The camel-metrics component is displaying the value of the counters via the logger, but the counters collection is empty when I try to access it programmatically.
>
> Regards,
> Jim Greene
> Principal IT Architect, Enterprise Architecture & Strategy American 
> Electric Power One Riverside Plaza, 11th Floor Columbus, OH 43125
> Phone:  (w) 614-716-2617
> Email:  jlgreene2@aep.com
>
>
> -----Original Message-----
> From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> Sent: Friday, November 07, 2014 1:27 AM
> To: users@camel.apache.org
> Subject: Re: camel-metrics Component
>
>  This is an EXTERNAL email. STOP. THINK before you CLICK links or OPEN attachments.
>
> **********************************************************************
> Try setting the route policy before adding the routes
>
> On Fri, Nov 7, 2014 at 1:35 AM, James L Greene <jl...@aep.com> wrote:
>> I have written a simple Java class to attempt to exercise the camel-metrics component.  In this example, I'm writing a standalone Java batch process, which will read files from an input directory, and deposit the files in an output directory.  I'm attempting to use the camel-metrics component to capture how many files were read (using the name "files-processed").  I've configured the class to only run for seventy seconds, giving the camel-metrics component an opportunity to output the values of the metric being captured to the application log (which its configured to do at sixty seconds intervals, and which appears to work properly).
>>
>> Prior to suspending/stopping my CamelContext, I attempted to retrieve the metrics as described in the camel-metrics component documentation.  Unfortunately, when I look at the contents of the metrics, my custom metric is nowhere to be found.  Below, please find the source for the sample class that I created, and its logged output.
>>
>> Am I doing something wrong?
>>
>> ============================
>>
>> Camel Version
>> 2.14.0
>>
>> JRE Version
>> java version "1.7.0_25"
>> Java(TM) SE Runtime Environment (build 1.7.0_25-b17) Java HotSpot(TM) 
>> 64-Bit Server VM (build 23.25-b01, mixed mode)
>>
>> ============================
>>
>> package ...
>>
>> import com.codahale.metrics.Counter;
>> import com.codahale.metrics.MetricRegistry;
>> import java.util.SortedMap;
>> import org.apache.camel.CamelContext; import 
>> org.apache.camel.builder.RouteBuilder;
>> import
>> org.apache.camel.component.metrics.routepolicy.MetricsRegistryService
>> ;
>> import
>> org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFact
>> o ry; import org.apache.camel.impl.DefaultCamelContext;
>> import org.slf4j.Logger;
>> import org.slf4j.LoggerFactory;
>>
>> public class Main {
>>
>>     public static void main(String[] args) throws Exception {
>>         Logger LOG = LoggerFactory.getLogger(Main.class);
>>
>>         CamelContext context = new DefaultCamelContext();
>>
>>         RouteBuilder rb = new RouteBuilder() {
>>             @Override
>>             public void configure() throws Exception {
>>                 from("file://c:/test/input").
>>                         routeId("testroute").
>>                         log("Processing file [${header.CamelFileName}]").
>>                         to("metrics:counter:files-processed").
>>                         to("file://c:/test/output");
>>             }
>>         };
>>         context.addRoutes(rb);
>>
>>         MetricsRoutePolicyFactory mrpf = new MetricsRoutePolicyFactory();
>>         context.addRoutePolicyFactory(mrpf);
>>
>>         context.start();
>>
>>         int sleepCounter = 0;
>>         while (sleepCounter < 7) {
>>             sleepCounter++;
>>             Thread.sleep(10000);
>>             LOG.info("Zzz...({} seconds)", sleepCounter * 10);
>>         }
>>
>>         MetricsRegistryService regSvc = context.hasService(MetricsRegistryService.class);
>>         if(regSvc != null) {
>>             // Dump the statistics to the log in JSON format.
>>             regSvc.setPrettyPrint(true);
>>             LOG.info(regSvc.dumpStatisticsAsJson());
>>
>>             // Do it again, retrieving the map of counters from the MetricRegistry object.
>>             LOG.info("----------");
>>             MetricRegistry reg = regSvc.getMetricsRegistry();
>>             SortedMap<String, Counter> counters = reg.getCounters();
>>             LOG.info("Keys found {{}]", counters.keySet().size());
>>             for(String key : counters.keySet()) {
>>                 LOG.info("--- key [{}] - value [{}]", key, counters.get("key").getCount());
>>             }
>>         } else {
>>             System.out.println("Couldn't find MetricsRegisteryService instance");
>>         }
>>         context.suspend();
>>         context.stop();
>>     }
>> }
>>
>> ============================
>> --- exec-maven-plugin:1.2.1:exec (default-cli) @ metricstest ---
>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1731 - Apache Camel 2.14.0 (CamelContext: camel-1) is starting
>> 2014-11-06 19:15:23 INFO  ManagedManagementStrategy  : 187 - JMX is enabled
>> 2014-11-06 19:15:23 INFO  DefaultTypeConverter       :  50 - Loaded 178 type converters
>> 2014-11-06 19:15:23 INFO  MetricsComponent           : 108 - Creating new default MetricRegistry
>> 2014-11-06 19:15:23 INFO  MetricsComponent           :  57 - Metrics type: counter; name: files-processed
>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1931 - AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1941 - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :2453 - Route: testroute started and consuming from: Endpoint[file://c:/mdm/test/input]
>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1766 - Total 1 routes, of which 1 is started.
>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1767 - Apache Camel 2.14.0 (CamelContext: camel-1) started in 0.608 seconds
>> 2014-11-06 19:15:24 INFO  testroute                  :  96 - Processing file [testfile1.txt]
>> 2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile2.txt]
>> 2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile3.txt]
>> 2014-11-06 19:15:33 INFO  Main                       :  47 - Zzz...(10 seconds)
>> 2014-11-06 19:15:43 INFO  Main                       :  47 - Zzz...(20 seconds)
>> 2014-11-06 19:15:53 INFO  Main                       :  47 - Zzz...(30 seconds)
>> 2014-11-06 19:16:03 INFO  Main                       :  47 - Zzz...(40 seconds)
>> 2014-11-06 19:16:13 INFO  Main                       :  47 - Zzz...(50 seconds)
>> 2014-11-06 19:16:23 INFO  MetricsComponent           : 104 - type=COUNTER, name=files-processed, count=3
>> 2014-11-06 19:16:23 INFO  Main                       :  47 - Zzz...(60 seconds)
>> 2014-11-06 19:16:33 INFO  Main                       :  47 - Zzz...(70 seconds)
>> 2014-11-06 19:16:34 INFO  Main                       :  53 - {
>>   "version" : "3.0.0",
>>   "gauges" : { },
>>   "counters" : { },
>>   "histograms" : { },
>>   "meters" : { },
>>   "timers" : {
>>     "camel-1:testroute.responses" : {
>>       "count" : 3,
>>       "max" : 157.060387,
>>       "mean" : 88.249202,
>>       "min" : 44.265085,
>>       "p50" : 63.422134,
>>       "p75" : 157.060387,
>>       "p95" : 157.060387,
>>       "p98" : 157.060387,
>>       "p99" : 157.060387,
>>       "p999" : 157.060387,
>>       "stddev" : 60.35712482735794,
>>       "m15_rate" : 0.558194480485237,
>>       "m1_rate" : 0.20307925506404548,
>>       "m5_rate" : 0.48311899441084233,
>>       "mean_rate" : 0.04263368988938351,
>>       "duration_units" : "milliseconds",
>>       "rate_units" : "calls/second"
>>     }
>>   }
>> }
>> 2014-11-06 19:16:34 INFO  Main                       :  54 - ----------
>> 2014-11-06 19:16:34 INFO  Main                       :  57 - Keys found {0]
>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1648 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspending
>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 606 - Route: testroute suspend complete, was consuming from: Endpoint[file://c:/mdm/test/input]
>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1686 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspended in 0.032 seconds
>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1958 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutting down
>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 609 - Route: testroute shutdown complete, was consuming from: Endpoint[file://c:/mdm/test/input]
>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :2040 - Apache Camel 2.14.0 (CamelContext: camel-1) uptime 1 minute
>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :2041 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutdown in 0.000 seconds
>> ---------------------------------------------------------------------
>> -
>> --
>> BUILD SUCCESS
>> ---------------------------------------------------------------------
>> -
>> --
>> Total time: 1:12.415s
>> Finished at: Thu Nov 06 19:16:34 EST 2014 Final Memory: 5M/120M
>> ---------------------------------------------------------------------
>> -
>> --
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: camel-metrics Component

Posted by Claus Ibsen <cl...@gmail.com>.
Ah the route policy and the metrics component is not identical. They
are just hosted in the same JAR.

The route policy is self container what details it records. I guess we
could combine those so you can also do like you to add custom counters
with the Camel routes.

eg a bit of history then camel-metrics was first only a regular
component. The route policy was added later to make it easy to turn
that on in a single spot, and get metrics for all your routes.

On Fri, Nov 7, 2014 at 3:07 PM, James L Greene <jl...@aep.com> wrote:
> Claus,
>
> I gave your suggestion a try.  There was no change in the output.  The camel-metrics component is displaying the value of the counters via the logger, but the counters collection is empty when I try to access it programmatically.
>
> Regards,
> Jim Greene
> Principal IT Architect, Enterprise Architecture & Strategy
> American Electric Power
> One Riverside Plaza, 11th Floor
> Columbus, OH 43125
> Phone:  (w) 614-716-2617
> Email:  jlgreene2@aep.com
>
>
> -----Original Message-----
> From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> Sent: Friday, November 07, 2014 1:27 AM
> To: users@camel.apache.org
> Subject: Re: camel-metrics Component
>
>  This is an EXTERNAL email. STOP. THINK before you CLICK links or OPEN attachments.
>
> **********************************************************************
> Try setting the route policy before adding the routes
>
> On Fri, Nov 7, 2014 at 1:35 AM, James L Greene <jl...@aep.com> wrote:
>> I have written a simple Java class to attempt to exercise the camel-metrics component.  In this example, I'm writing a standalone Java batch process, which will read files from an input directory, and deposit the files in an output directory.  I'm attempting to use the camel-metrics component to capture how many files were read (using the name "files-processed").  I've configured the class to only run for seventy seconds, giving the camel-metrics component an opportunity to output the values of the metric being captured to the application log (which its configured to do at sixty seconds intervals, and which appears to work properly).
>>
>> Prior to suspending/stopping my CamelContext, I attempted to retrieve the metrics as described in the camel-metrics component documentation.  Unfortunately, when I look at the contents of the metrics, my custom metric is nowhere to be found.  Below, please find the source for the sample class that I created, and its logged output.
>>
>> Am I doing something wrong?
>>
>> ============================
>>
>> Camel Version
>> 2.14.0
>>
>> JRE Version
>> java version "1.7.0_25"
>> Java(TM) SE Runtime Environment (build 1.7.0_25-b17) Java HotSpot(TM)
>> 64-Bit Server VM (build 23.25-b01, mixed mode)
>>
>> ============================
>>
>> package ...
>>
>> import com.codahale.metrics.Counter;
>> import com.codahale.metrics.MetricRegistry;
>> import java.util.SortedMap;
>> import org.apache.camel.CamelContext;
>> import org.apache.camel.builder.RouteBuilder;
>> import
>> org.apache.camel.component.metrics.routepolicy.MetricsRegistryService;
>> import
>> org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFacto
>> ry; import org.apache.camel.impl.DefaultCamelContext;
>> import org.slf4j.Logger;
>> import org.slf4j.LoggerFactory;
>>
>> public class Main {
>>
>>     public static void main(String[] args) throws Exception {
>>         Logger LOG = LoggerFactory.getLogger(Main.class);
>>
>>         CamelContext context = new DefaultCamelContext();
>>
>>         RouteBuilder rb = new RouteBuilder() {
>>             @Override
>>             public void configure() throws Exception {
>>                 from("file://c:/test/input").
>>                         routeId("testroute").
>>                         log("Processing file [${header.CamelFileName}]").
>>                         to("metrics:counter:files-processed").
>>                         to("file://c:/test/output");
>>             }
>>         };
>>         context.addRoutes(rb);
>>
>>         MetricsRoutePolicyFactory mrpf = new MetricsRoutePolicyFactory();
>>         context.addRoutePolicyFactory(mrpf);
>>
>>         context.start();
>>
>>         int sleepCounter = 0;
>>         while (sleepCounter < 7) {
>>             sleepCounter++;
>>             Thread.sleep(10000);
>>             LOG.info("Zzz...({} seconds)", sleepCounter * 10);
>>         }
>>
>>         MetricsRegistryService regSvc = context.hasService(MetricsRegistryService.class);
>>         if(regSvc != null) {
>>             // Dump the statistics to the log in JSON format.
>>             regSvc.setPrettyPrint(true);
>>             LOG.info(regSvc.dumpStatisticsAsJson());
>>
>>             // Do it again, retrieving the map of counters from the MetricRegistry object.
>>             LOG.info("----------");
>>             MetricRegistry reg = regSvc.getMetricsRegistry();
>>             SortedMap<String, Counter> counters = reg.getCounters();
>>             LOG.info("Keys found {{}]", counters.keySet().size());
>>             for(String key : counters.keySet()) {
>>                 LOG.info("--- key [{}] - value [{}]", key, counters.get("key").getCount());
>>             }
>>         } else {
>>             System.out.println("Couldn't find MetricsRegisteryService instance");
>>         }
>>         context.suspend();
>>         context.stop();
>>     }
>> }
>>
>> ============================
>> --- exec-maven-plugin:1.2.1:exec (default-cli) @ metricstest ---
>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1731 - Apache Camel 2.14.0 (CamelContext: camel-1) is starting
>> 2014-11-06 19:15:23 INFO  ManagedManagementStrategy  : 187 - JMX is enabled
>> 2014-11-06 19:15:23 INFO  DefaultTypeConverter       :  50 - Loaded 178 type converters
>> 2014-11-06 19:15:23 INFO  MetricsComponent           : 108 - Creating new default MetricRegistry
>> 2014-11-06 19:15:23 INFO  MetricsComponent           :  57 - Metrics type: counter; name: files-processed
>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1931 - AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1941 - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :2453 - Route: testroute started and consuming from: Endpoint[file://c:/mdm/test/input]
>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1766 - Total 1 routes, of which 1 is started.
>> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1767 - Apache Camel 2.14.0 (CamelContext: camel-1) started in 0.608 seconds
>> 2014-11-06 19:15:24 INFO  testroute                  :  96 - Processing file [testfile1.txt]
>> 2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile2.txt]
>> 2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile3.txt]
>> 2014-11-06 19:15:33 INFO  Main                       :  47 - Zzz...(10 seconds)
>> 2014-11-06 19:15:43 INFO  Main                       :  47 - Zzz...(20 seconds)
>> 2014-11-06 19:15:53 INFO  Main                       :  47 - Zzz...(30 seconds)
>> 2014-11-06 19:16:03 INFO  Main                       :  47 - Zzz...(40 seconds)
>> 2014-11-06 19:16:13 INFO  Main                       :  47 - Zzz...(50 seconds)
>> 2014-11-06 19:16:23 INFO  MetricsComponent           : 104 - type=COUNTER, name=files-processed, count=3
>> 2014-11-06 19:16:23 INFO  Main                       :  47 - Zzz...(60 seconds)
>> 2014-11-06 19:16:33 INFO  Main                       :  47 - Zzz...(70 seconds)
>> 2014-11-06 19:16:34 INFO  Main                       :  53 - {
>>   "version" : "3.0.0",
>>   "gauges" : { },
>>   "counters" : { },
>>   "histograms" : { },
>>   "meters" : { },
>>   "timers" : {
>>     "camel-1:testroute.responses" : {
>>       "count" : 3,
>>       "max" : 157.060387,
>>       "mean" : 88.249202,
>>       "min" : 44.265085,
>>       "p50" : 63.422134,
>>       "p75" : 157.060387,
>>       "p95" : 157.060387,
>>       "p98" : 157.060387,
>>       "p99" : 157.060387,
>>       "p999" : 157.060387,
>>       "stddev" : 60.35712482735794,
>>       "m15_rate" : 0.558194480485237,
>>       "m1_rate" : 0.20307925506404548,
>>       "m5_rate" : 0.48311899441084233,
>>       "mean_rate" : 0.04263368988938351,
>>       "duration_units" : "milliseconds",
>>       "rate_units" : "calls/second"
>>     }
>>   }
>> }
>> 2014-11-06 19:16:34 INFO  Main                       :  54 - ----------
>> 2014-11-06 19:16:34 INFO  Main                       :  57 - Keys found {0]
>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1648 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspending
>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 606 - Route: testroute suspend complete, was consuming from: Endpoint[file://c:/mdm/test/input]
>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1686 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspended in 0.032 seconds
>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1958 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutting down
>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 609 - Route: testroute shutdown complete, was consuming from: Endpoint[file://c:/mdm/test/input]
>> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :2040 - Apache Camel 2.14.0 (CamelContext: camel-1) uptime 1 minute
>> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :2041 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutdown in 0.000 seconds
>> ----------------------------------------------------------------------
>> --
>> BUILD SUCCESS
>> ----------------------------------------------------------------------
>> --
>> Total time: 1:12.415s
>> Finished at: Thu Nov 06 19:16:34 EST 2014 Final Memory: 5M/120M
>> ----------------------------------------------------------------------
>> --
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

RE: camel-metrics Component

Posted by James L Greene <jl...@aep.com>.
Claus, 

I gave your suggestion a try.  There was no change in the output.  The camel-metrics component is displaying the value of the counters via the logger, but the counters collection is empty when I try to access it programmatically.

Regards,
Jim Greene
Principal IT Architect, Enterprise Architecture & Strategy
American Electric Power
One Riverside Plaza, 11th Floor
Columbus, OH 43125
Phone:  (w) 614-716-2617 
Email:  jlgreene2@aep.com


-----Original Message-----
From: Claus Ibsen [mailto:claus.ibsen@gmail.com] 
Sent: Friday, November 07, 2014 1:27 AM
To: users@camel.apache.org
Subject: Re: camel-metrics Component

 This is an EXTERNAL email. STOP. THINK before you CLICK links or OPEN attachments.

**********************************************************************
Try setting the route policy before adding the routes

On Fri, Nov 7, 2014 at 1:35 AM, James L Greene <jl...@aep.com> wrote:
> I have written a simple Java class to attempt to exercise the camel-metrics component.  In this example, I'm writing a standalone Java batch process, which will read files from an input directory, and deposit the files in an output directory.  I'm attempting to use the camel-metrics component to capture how many files were read (using the name "files-processed").  I've configured the class to only run for seventy seconds, giving the camel-metrics component an opportunity to output the values of the metric being captured to the application log (which its configured to do at sixty seconds intervals, and which appears to work properly).
>
> Prior to suspending/stopping my CamelContext, I attempted to retrieve the metrics as described in the camel-metrics component documentation.  Unfortunately, when I look at the contents of the metrics, my custom metric is nowhere to be found.  Below, please find the source for the sample class that I created, and its logged output.
>
> Am I doing something wrong?
>
> ============================
>
> Camel Version
> 2.14.0
>
> JRE Version
> java version "1.7.0_25"
> Java(TM) SE Runtime Environment (build 1.7.0_25-b17) Java HotSpot(TM) 
> 64-Bit Server VM (build 23.25-b01, mixed mode)
>
> ============================
>
> package ...
>
> import com.codahale.metrics.Counter;
> import com.codahale.metrics.MetricRegistry;
> import java.util.SortedMap;
> import org.apache.camel.CamelContext;
> import org.apache.camel.builder.RouteBuilder;
> import 
> org.apache.camel.component.metrics.routepolicy.MetricsRegistryService;
> import 
> org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFacto
> ry; import org.apache.camel.impl.DefaultCamelContext;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> public class Main {
>
>     public static void main(String[] args) throws Exception {
>         Logger LOG = LoggerFactory.getLogger(Main.class);
>
>         CamelContext context = new DefaultCamelContext();
>
>         RouteBuilder rb = new RouteBuilder() {
>             @Override
>             public void configure() throws Exception {
>                 from("file://c:/test/input").
>                         routeId("testroute").
>                         log("Processing file [${header.CamelFileName}]").
>                         to("metrics:counter:files-processed").
>                         to("file://c:/test/output");
>             }
>         };
>         context.addRoutes(rb);
>
>         MetricsRoutePolicyFactory mrpf = new MetricsRoutePolicyFactory();
>         context.addRoutePolicyFactory(mrpf);
>
>         context.start();
>
>         int sleepCounter = 0;
>         while (sleepCounter < 7) {
>             sleepCounter++;
>             Thread.sleep(10000);
>             LOG.info("Zzz...({} seconds)", sleepCounter * 10);
>         }
>
>         MetricsRegistryService regSvc = context.hasService(MetricsRegistryService.class);
>         if(regSvc != null) {
>             // Dump the statistics to the log in JSON format.
>             regSvc.setPrettyPrint(true);
>             LOG.info(regSvc.dumpStatisticsAsJson());
>
>             // Do it again, retrieving the map of counters from the MetricRegistry object.
>             LOG.info("----------");
>             MetricRegistry reg = regSvc.getMetricsRegistry();
>             SortedMap<String, Counter> counters = reg.getCounters();
>             LOG.info("Keys found {{}]", counters.keySet().size());
>             for(String key : counters.keySet()) {
>                 LOG.info("--- key [{}] - value [{}]", key, counters.get("key").getCount());
>             }
>         } else {
>             System.out.println("Couldn't find MetricsRegisteryService instance");
>         }
>         context.suspend();
>         context.stop();
>     }
> }
>
> ============================
> --- exec-maven-plugin:1.2.1:exec (default-cli) @ metricstest ---
> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1731 - Apache Camel 2.14.0 (CamelContext: camel-1) is starting
> 2014-11-06 19:15:23 INFO  ManagedManagementStrategy  : 187 - JMX is enabled
> 2014-11-06 19:15:23 INFO  DefaultTypeConverter       :  50 - Loaded 178 type converters
> 2014-11-06 19:15:23 INFO  MetricsComponent           : 108 - Creating new default MetricRegistry
> 2014-11-06 19:15:23 INFO  MetricsComponent           :  57 - Metrics type: counter; name: files-processed
> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1931 - AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1941 - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :2453 - Route: testroute started and consuming from: Endpoint[file://c:/mdm/test/input]
> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1766 - Total 1 routes, of which 1 is started.
> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1767 - Apache Camel 2.14.0 (CamelContext: camel-1) started in 0.608 seconds
> 2014-11-06 19:15:24 INFO  testroute                  :  96 - Processing file [testfile1.txt]
> 2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile2.txt]
> 2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile3.txt]
> 2014-11-06 19:15:33 INFO  Main                       :  47 - Zzz...(10 seconds)
> 2014-11-06 19:15:43 INFO  Main                       :  47 - Zzz...(20 seconds)
> 2014-11-06 19:15:53 INFO  Main                       :  47 - Zzz...(30 seconds)
> 2014-11-06 19:16:03 INFO  Main                       :  47 - Zzz...(40 seconds)
> 2014-11-06 19:16:13 INFO  Main                       :  47 - Zzz...(50 seconds)
> 2014-11-06 19:16:23 INFO  MetricsComponent           : 104 - type=COUNTER, name=files-processed, count=3
> 2014-11-06 19:16:23 INFO  Main                       :  47 - Zzz...(60 seconds)
> 2014-11-06 19:16:33 INFO  Main                       :  47 - Zzz...(70 seconds)
> 2014-11-06 19:16:34 INFO  Main                       :  53 - {
>   "version" : "3.0.0",
>   "gauges" : { },
>   "counters" : { },
>   "histograms" : { },
>   "meters" : { },
>   "timers" : {
>     "camel-1:testroute.responses" : {
>       "count" : 3,
>       "max" : 157.060387,
>       "mean" : 88.249202,
>       "min" : 44.265085,
>       "p50" : 63.422134,
>       "p75" : 157.060387,
>       "p95" : 157.060387,
>       "p98" : 157.060387,
>       "p99" : 157.060387,
>       "p999" : 157.060387,
>       "stddev" : 60.35712482735794,
>       "m15_rate" : 0.558194480485237,
>       "m1_rate" : 0.20307925506404548,
>       "m5_rate" : 0.48311899441084233,
>       "mean_rate" : 0.04263368988938351,
>       "duration_units" : "milliseconds",
>       "rate_units" : "calls/second"
>     }
>   }
> }
> 2014-11-06 19:16:34 INFO  Main                       :  54 - ----------
> 2014-11-06 19:16:34 INFO  Main                       :  57 - Keys found {0]
> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1648 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspending
> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 606 - Route: testroute suspend complete, was consuming from: Endpoint[file://c:/mdm/test/input]
> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1686 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspended in 0.032 seconds
> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1958 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutting down
> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 609 - Route: testroute shutdown complete, was consuming from: Endpoint[file://c:/mdm/test/input]
> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :2040 - Apache Camel 2.14.0 (CamelContext: camel-1) uptime 1 minute
> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :2041 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutdown in 0.000 seconds
> ----------------------------------------------------------------------
> --
> BUILD SUCCESS
> ----------------------------------------------------------------------
> --
> Total time: 1:12.415s
> Finished at: Thu Nov 06 19:16:34 EST 2014 Final Memory: 5M/120M
> ----------------------------------------------------------------------
> --



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: camel-metrics Component

Posted by Claus Ibsen <cl...@gmail.com>.
Try setting the route policy before adding the routes

On Fri, Nov 7, 2014 at 1:35 AM, James L Greene <jl...@aep.com> wrote:
> I have written a simple Java class to attempt to exercise the camel-metrics component.  In this example, I'm writing a standalone Java batch process, which will read files from an input directory, and deposit the files in an output directory.  I'm attempting to use the camel-metrics component to capture how many files were read (using the name "files-processed").  I've configured the class to only run for seventy seconds, giving the camel-metrics component an opportunity to output the values of the metric being captured to the application log (which its configured to do at sixty seconds intervals, and which appears to work properly).
>
> Prior to suspending/stopping my CamelContext, I attempted to retrieve the metrics as described in the camel-metrics component documentation.  Unfortunately, when I look at the contents of the metrics, my custom metric is nowhere to be found.  Below, please find the source for the sample class that I created, and its logged output.
>
> Am I doing something wrong?
>
> ============================
>
> Camel Version
> 2.14.0
>
> JRE Version
> java version "1.7.0_25"
> Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
> Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
>
> ============================
>
> package ...
>
> import com.codahale.metrics.Counter;
> import com.codahale.metrics.MetricRegistry;
> import java.util.SortedMap;
> import org.apache.camel.CamelContext;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.component.metrics.routepolicy.MetricsRegistryService;
> import org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFactory;
> import org.apache.camel.impl.DefaultCamelContext;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> public class Main {
>
>     public static void main(String[] args) throws Exception {
>         Logger LOG = LoggerFactory.getLogger(Main.class);
>
>         CamelContext context = new DefaultCamelContext();
>
>         RouteBuilder rb = new RouteBuilder() {
>             @Override
>             public void configure() throws Exception {
>                 from("file://c:/test/input").
>                         routeId("testroute").
>                         log("Processing file [${header.CamelFileName}]").
>                         to("metrics:counter:files-processed").
>                         to("file://c:/test/output");
>             }
>         };
>         context.addRoutes(rb);
>
>         MetricsRoutePolicyFactory mrpf = new MetricsRoutePolicyFactory();
>         context.addRoutePolicyFactory(mrpf);
>
>         context.start();
>
>         int sleepCounter = 0;
>         while (sleepCounter < 7) {
>             sleepCounter++;
>             Thread.sleep(10000);
>             LOG.info("Zzz...({} seconds)", sleepCounter * 10);
>         }
>
>         MetricsRegistryService regSvc = context.hasService(MetricsRegistryService.class);
>         if(regSvc != null) {
>             // Dump the statistics to the log in JSON format.
>             regSvc.setPrettyPrint(true);
>             LOG.info(regSvc.dumpStatisticsAsJson());
>
>             // Do it again, retrieving the map of counters from the MetricRegistry object.
>             LOG.info("----------");
>             MetricRegistry reg = regSvc.getMetricsRegistry();
>             SortedMap<String, Counter> counters = reg.getCounters();
>             LOG.info("Keys found {{}]", counters.keySet().size());
>             for(String key : counters.keySet()) {
>                 LOG.info("--- key [{}] - value [{}]", key, counters.get("key").getCount());
>             }
>         } else {
>             System.out.println("Couldn't find MetricsRegisteryService instance");
>         }
>         context.suspend();
>         context.stop();
>     }
> }
>
> ============================
> --- exec-maven-plugin:1.2.1:exec (default-cli) @ metricstest ---
> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1731 - Apache Camel 2.14.0 (CamelContext: camel-1) is starting
> 2014-11-06 19:15:23 INFO  ManagedManagementStrategy  : 187 - JMX is enabled
> 2014-11-06 19:15:23 INFO  DefaultTypeConverter       :  50 - Loaded 178 type converters
> 2014-11-06 19:15:23 INFO  MetricsComponent           : 108 - Creating new default MetricRegistry
> 2014-11-06 19:15:23 INFO  MetricsComponent           :  57 - Metrics type: counter; name: files-processed
> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1931 - AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1941 - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :2453 - Route: testroute started and consuming from: Endpoint[file://c:/mdm/test/input]
> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1766 - Total 1 routes, of which 1 is started.
> 2014-11-06 19:15:23 INFO  DefaultCamelContext        :1767 - Apache Camel 2.14.0 (CamelContext: camel-1) started in 0.608 seconds
> 2014-11-06 19:15:24 INFO  testroute                  :  96 - Processing file [testfile1.txt]
> 2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile2.txt]
> 2014-11-06 19:15:25 INFO  testroute                  :  96 - Processing file [testfile3.txt]
> 2014-11-06 19:15:33 INFO  Main                       :  47 - Zzz...(10 seconds)
> 2014-11-06 19:15:43 INFO  Main                       :  47 - Zzz...(20 seconds)
> 2014-11-06 19:15:53 INFO  Main                       :  47 - Zzz...(30 seconds)
> 2014-11-06 19:16:03 INFO  Main                       :  47 - Zzz...(40 seconds)
> 2014-11-06 19:16:13 INFO  Main                       :  47 - Zzz...(50 seconds)
> 2014-11-06 19:16:23 INFO  MetricsComponent           : 104 - type=COUNTER, name=files-processed, count=3
> 2014-11-06 19:16:23 INFO  Main                       :  47 - Zzz...(60 seconds)
> 2014-11-06 19:16:33 INFO  Main                       :  47 - Zzz...(70 seconds)
> 2014-11-06 19:16:34 INFO  Main                       :  53 - {
>   "version" : "3.0.0",
>   "gauges" : { },
>   "counters" : { },
>   "histograms" : { },
>   "meters" : { },
>   "timers" : {
>     "camel-1:testroute.responses" : {
>       "count" : 3,
>       "max" : 157.060387,
>       "mean" : 88.249202,
>       "min" : 44.265085,
>       "p50" : 63.422134,
>       "p75" : 157.060387,
>       "p95" : 157.060387,
>       "p98" : 157.060387,
>       "p99" : 157.060387,
>       "p999" : 157.060387,
>       "stddev" : 60.35712482735794,
>       "m15_rate" : 0.558194480485237,
>       "m1_rate" : 0.20307925506404548,
>       "m5_rate" : 0.48311899441084233,
>       "mean_rate" : 0.04263368988938351,
>       "duration_units" : "milliseconds",
>       "rate_units" : "calls/second"
>     }
>   }
> }
> 2014-11-06 19:16:34 INFO  Main                       :  54 - ----------
> 2014-11-06 19:16:34 INFO  Main                       :  57 - Keys found {0]
> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1648 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspending
> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 606 - Route: testroute suspend complete, was consuming from: Endpoint[file://c:/mdm/test/input]
> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1686 - Apache Camel 2.14.0 (CamelContext: camel-1) is suspended in 0.032 seconds
> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :1958 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutting down
> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 172 - Starting to graceful shutdown 1 routes (timeout 300 seconds)
> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 609 - Route: testroute shutdown complete, was consuming from: Endpoint[file://c:/mdm/test/input]
> 2014-11-06 19:16:34 INFO  DefaultShutdownStrategy    : 222 - Graceful shutdown of 1 routes completed in 0 seconds
> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :2040 - Apache Camel 2.14.0 (CamelContext: camel-1) uptime 1 minute
> 2014-11-06 19:16:34 INFO  DefaultCamelContext        :2041 - Apache Camel 2.14.0 (CamelContext: camel-1) is shutdown in 0.000 seconds
> ------------------------------------------------------------------------
> BUILD SUCCESS
> ------------------------------------------------------------------------
> Total time: 1:12.415s
> Finished at: Thu Nov 06 19:16:34 EST 2014
> Final Memory: 5M/120M
> ------------------------------------------------------------------------



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/