Monitoring Camel applications on the Cloud
Join the DZone community and get the full member experience.
Join For Free
Apache Camel is the swiss army knife of application integration. If your
application is processing data from different systems, sooner or later
you will end up using some of the 130 (and growing number of) connectors
available. Camel also has excellent cloud support. You can use either jCoulds
component that provides portable service abstraction layer for Amazon,
GoGrid, VMWare, Azure, and Rackspace or use Amazon specific components
for SQS, SNS, S3, SES, SDB, DDB (some of which contributed by me).
In this tutorial I'm going to show you how to monitor Camel applications
with JMX and Amazon CloudWatch service. The need for such a monitoring
arose after I created livephotostream
- the photo streaming application I created while playing with Camel.
This application retrieves real time photos from Twitter streaming api,
and not so real time data from Instagram and Tumblr, then display them
using Bootstrap and sometimes Websocket. And I wanted to see how many
photos it is receiving, how many of them are failing, how long it takes
to process a photo and so on. So I end up creating a camel-cloudwatch
component and a simple application demonstrating how to use it to
display JMX metrics.
This is when the new cloudwatch producer becomes useful. It lets you send custom metrics to amazon CloudWatch service. All you have to do is give a namespace to your metrics, and send each metric by specifying its name, value and optionally the unit and timestamp. If you don't specify the unit and timestamp it will use count as unit and the current time as the metric time.
<camel:route> <camel:from uri="jmx:platform?objectDomain=org.apache.camel&monitorType=counter&differenceMode=false&key.context=MC-SS071464.local/monitorContext&key.type=routes&key.name=%22processingRoute%22&observedAttribute=ExchangesFailed&initThreshold=1&granularityPeriod=5000&offset=1&format=raw"/> <setHeader headerName="CamelAwsCwMetricName"> <simple>${body.observedAttribute}</simple> </setHeader> <setHeader headerName="CamelAwsCwMetricValue"> <simple>${body.derivedGauge}</simple> </setHeader> <setHeader headerName="CamelAwsCwMetricUnit"> <constant>Count</constant> </setHeader> <camel:to uri="aws-cw://www.livephotostream.com/live?accessKey=XXX&secretKey=XXX"/> </camel:route>
The route above doesn't require any additional code. It will send any changes to the ExchangesFailed attribute to CloudWatch service, and you can see the error count not changing in the CloudWatch graph:
The downside of using jmx consumer to monitor a bean is that you will need to create separate consumer and route for each bean and attribute monitored. Another approach is to have a processor that can access the beans from the JMX server, read all the attributes of interest and send all of them at once again using the cloudwatch component.
<route> <from uri="timer://jmxMonitoringTimer?fixedRate=true&period=10000"/> <process ref="jmxMetricReader" /> <camel:to uri="aws-cw://www.livephotostream.com/context?accessKey=XXX&secretKey=XXX"/> </route>In this scenario you will need also a timer to trigger the polling. The cloudwatch producer can generate a metric based on message headers as in the first example, or simply send the metric objects from the message body if present as in the second example. The processor for retrieving data from camel jmx is also straightforward and can be seen in the demo app on my guthub account.
The result from the last route is couple of metrics, all of which sent to CloudWatch every minute. As you can see from the next image the number of exchanges completed successfully is increasing all the time, but with a different rate:
![]() |
If the new metrics doesn't exist in CloudWatch, it will be created for you, but if you want to set up alarms and trigger automatic actions, you still have to log into amazon console and to it manually. And finally don't forget to check your "cloud bill" after adding all these metrics, they are not for free ;)
Published at DZone with permission of Bilgin Ibryam, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments