Giter Site home page Giter Site logo

camel-metrics's Introduction

Metrics Component

Build Status

This repo is inactive since 03.07.2014

Documentation

Available as of Camel 2.14

The metrics: component allows you to collect various metrics directly from Camel routes. Supported metric types are counter, meter, histogram and timer. Metrics provides simple way to measure behaviour of your application. Configurable reporting backend is enabling different integration options for collecting and visualizing statistics.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-metrics</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI format

metrics:[ meter | counter | histogram | timer ]:metricname[?options]

Metric Registry

If MetricRegistry instance for name metricRegistry is not found from Camel registry default one is used. Default MetricRegistry uses Slf4jReporter and 60 second reporting interval. MetricRegistry instance can be configured by adding bean with name metricRegistry to Camel registry. For example using Spring Java Configuration.

    @Configuration
    public static class MyConfig extends SingleRouteCamelConfiguration {

        @Bean
        @Override
        public RouteBuilder route() {
            return new RouteBuilder() {

                @Override
                public void configure() throws Exception {
                    // define Camel routes here
                }
            };
        }

        @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME)
        public MetricRegistry getMetricRegistry() {
            MetricRegistry registry = ...;
            return registry;
        }
    }

Usage

Each metric has type and name. Supported types are counter, meter, histogram and timer. Metric name is simple string. If metric type is not provided then type meter is used by default.

Headers

Metric name defined in URI can be overridden by using header with name CamelMetricsName.

For example

from("direct:in")
    .setHeader(MetricsComponent.HEADER_METRIC_NAME, constant("new.name"))
    .to("metrics:counter:name.not.used")
    .to("direct:out")

will update counter with name new.name instead of name.not.used.

All Metrics specific headers are removed from the message once Metrics endpoint finishes processing of exchange. While processing exchange Metrics endpoint will catch all exceptions and write log entry using level warn.

Metrics type counter

metrics:counter:metricname[?options]

Where options are

Name Default Description
increment - Long value to add to the counter
decrement - Long value to subtract from the counter

If neither increment or decrement is defined counter value will be incremented by one. If increment and decrement are both defined only increment operation is called.

// update counter simple.counter by 7
from("direct:in")
    .to("metric:counter:simple.counter?increment=7")
    .to("direct:out")
// increment counter simple.counter by 1
from("direct:in")
    .to("metric:counter:simple.counter")
    .to("direct:out")
// decrement counter simple.counter by 3
from("direct:in")
    .to("metric:counter:simple.counter?decrement=3")
    .to("direct:out")

Headers

Message headers can be used to override increment and decrement values specified in Metrics component URI.

Name Description Expected type
CamelMetricsCounterIncrement Override increment value in URI Long
CamelMetricsCounterDecrement Override decrement value in URI Long
// update counter simple.counter by 417
from("direct:in")
    .setHeader(MetricsComponent.HEADER_COUNTER_INCREMENT, constant(417L))
    .to("metric:counter:simple.counter?increment=7")
    .to("direct:out")
// updates counter using simple language to evaluate body.length
from("direct:in")
    .setHeader(MetricsComponent.HEADER_COUNTER_INCREMENT, simple("${body.length}"))
    .to("metrics:counter:body.length")
    .to("mock:out");

Metric type histogram

metrics:histogram:metricname[?options]

Where options are

Name Default Description
value - Value to use in histogram

If no value is not set nothing is added to histogram and warning is logged.

// adds value 9923 to simple.histogram
from("direct:in")
    .to("metric:histogram:simple.histogram?value=9923")
    .to("direct:out")
// nothing is added to simple.histogram; warning is logged
from("direct:in")
    .to("metric:histogram:simple.histogram")
    .to("direct:out")

Headers

Message header can be used to override value specified in Metrics component URI.

Name Description Expected type
CamelMetricsHistogramValue Override histogram value in URI Long
// adds value 992 to simple.histogram
from("direct:in")
    .setHeader(MetricsComponent.HEADER_HISTOGRAM_VALUE, constant(992L))
    .to("metric:histogram:simple.histogram?value=700")
    .to("direct:out")

Metric type meter

metrics:meter:metricname[?options]

Where options are

Name Default Description
mark - Long value to use as mark

If mark is not set meter.mark() is called without argument.

// marks simple.meter without value
from("direct:in")
    .to("metric:simple.meter")
    .to("direct:out")
// marks simple.meter with value 81
from("direct:in")
    .to("metric:meter:simple.meter?mark=81")
    .to("direct:out")

Headers

Message header can be used to override mark value specified in Metrics component URI.

Name Description Expected type
CamelMetricsMeterMark Override mark value in URI Long
// updates meter simple.meter with value 345
from("direct:in")
    .setHeader(MetricsComponent.HEADER_METER_MARK, constant(345L))
    .to("metric:meter:simple.meter?mark=123")
    .to("direct:out")

Metrics type timer

metrics:timer:metricname[?options]

Where options are

Name Default Description
action - start or stop

If no action or invalid value is provided warning is logged and no timer is updated. If action start is called on already running timer or stop is called on not running timer nothing is updated and warning is logged.

// measure time taken by route calculate
from("direct:in")
    .to("metrics:timer:simple.timer?action=start")
    .to("direct:calculate")
    .to("metrics:timer:simple.timer?action=stop");

Timer Context objects are stored as Exchange properties between different Metrics component calls.

Headers

Message header can be used to override action value specified in Metrics component URI.

Name Description Expected type
CamelMetricsTimerAction Override timer action in URI org.apache.camel.metrics.timer.TimerEndpoint.TimerAction
// sets timer action using header
from("direct:in")
    .setHeader(MetricsComponent.HEADER_TIMER_ACTION, TimerAction.start)
    .to("metric:timer:simple.timer")
    .to("direct:out")

camel-metrics's People

Contributors

laurikimmel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

camel-metrics's Issues

Reset Metrics like every day?

Is there an option to reset all of the metrics everyday without a restart?
The idea is to look at current day's performance rather than historical.

Improvement and Support

Hi,

Do you plan to make some improvement on this camel component? Can I help you in something?

I think this can be a very useful component.

Thanks a lot.

Bye,
Andrea

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.