| By Hovhannes Avoyan | Article Rating: |
|
| August 17, 2012 10:13 AM EDT | Reads: |
2,263 |
It has been talked about many, many times, so now it is naturally widely-known that any application, especially one that’s in production, must be monitored. When monitoring, it is important not only to evaluate the current status of the application, but, even more importantly, to predict future potential error situations. It is already standard practice that application programs write log files. These usually contain various information from many different points in the application. Therefore it is very important to process the log files in a way that provides an understanding of what’s going on when things go awry. Unfortunately, as might be expected, the files are usually far from ideally-designed and often contain too many details and too much noise. As a result, it is actually very difficult to glean much useful information from them. Faced with such a situation, you may often prefer just to select pieces of important information from your logs and see these in real time. In this article, the simple but effective solution for selective monitoring of your Java application logs, in real time, is presented.
You may ask – why Java? The answer is simple – because Java has a powerful log engine, called Log4J. Besides that, the Log4J engine has been ported to other popular programming languages (log4php, log4net, log4cxx, log4js, etc.), so perhaps this same approach can be used with those as well.
Log4j provides many extensions and one of these provides for creating custom appenders. Log4J also has a filtering facility that can be used in custom appenders. Thus, the idea is to create a custom appender with filtering which will selectively get information from your log file and send that information to Monitis. There, it can be shown in tabular and graphical form in order to notify the user if something is starting to go wrong.
We have created the generic custom appender with filtering which receives information from Log4J, filters it according to a user pattern (RegExp) and then sends it to Monitis using the Monitis Open API. The custom appender is wrapped in a Jar file and therefore you shouldn’t make any changes in your application. You can use it as is, without any problem.
All that needs to be done is the following:
- include the log_mon.jar (generic custom appender) in your list of application libraries
- Using the settings shown below as an example, modify your Log4J configuration file to specify the settings for the Monitis Appender
<appender name="monitisAppender">
<param name="monitisApiKey" value="2PE0HVI4DHP34JACKCAE37IOD4" />
<param name="monitisSecretKey" value="7OI90FU3C3DA8ENLNJ0JGGOGO0" />
<param name="monitisMonitorName" value="Log_files_monitor" />
<param name="monitisMonitorTag" value="Custom_logger_monitor" />
<param name="monitisSendInterval" value="60000" />
<layout>
<param name="ConversionPattern" value="%d{ISO8601} %-5p [%t]: %m%n" />
</layout>
<filter>
<param name="filterPattern" value="(Error|Fatal|Warn*|Attention)" />
<param name="minAllowedLevel" value="WARN" />
</filter>
</appender>
where:
- monitisApiKey is user personal API key that can be obtained from Monitis user account
- monitisSecretKey is user personal secret key that can be obtained from Monitis user account
- monitisMonitorName is user monitor name (any unique name can be chosen)
- monitisMonitorTag is tag value for user monitors
- monitisSendInterval is time interval [ms] between sending monitored info to Monitis
- ConversationPattern is the pattern that will be used by MonitisAppender to format records
- filterPattern is a pattern-string for selection of log records that you want to monitor
This should be composed as a Java RegEx and correspond to Java Pattern.matches requirements.
(default is no pattern – so all records will be sent to Log Monitor)
- minAllowedLevel is the log4j records level (ERROR, WARN, DEBUG, etc.) that you want to monitor (default value is WARN)
Notes:
- the Log4J configuration should be prepared in XML format because Log4J filter supports XML only
- this approach doesn’t affect your application performance because Log4J appenders work in separate threads asynchronously
- it can take more memory to run your application because an additional custom appender works in the same JVM bounds
- in comparison to other approaches this approach seems much simpler and doesn’t require additional tools. It’s very close to The Cure for Monitoring Java Logs technique, and simplifies it
The sources and more details can be found in the GitHub.











Read the original blog entry...
Published August 17, 2012 Reads 2,263
Copyright © 2012 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Hovhannes Avoyan
Hovhannes Avoyan is the CEO of Monitis, Inc., a provider of on-demand systems management and monitoring software to 50,000 users spanning small businesses and Fortune 500 companies.
Prior to Monitis, he served as General Manager and Director of Development at prominent web portal Lycos Europe, where he grew the Lycos Armenia group from 30 people to over 200, making it the company's largest development center. Prior to Lycos, Avoyan was VP of Technology at Brience, Inc. (based in San Francisco and acquired by Syniverse), which delivered mobile internet content solutions to companies like Cisco, Ingram Micro, Washington Mutual, Wyndham Hotels , T-Mobile , and CNN. Prior to that, he served as the founder and CEO of CEDIT ltd., which was acquired by Brience. A 24 year veteran of the software industry, he also runs Sourcio cjsc, an IT consulting company and startup incubator specializing in web 2.0 products and open-source technologies.
Hovhannes is a senior lecturer at the American Univeristy of Armenia and has been a visiting lecturer at San Francisco State University. He is a graduate of Bertelsmann University.
- Cloud People: A Who's Who of Cloud Computing
- New Relic Q1 2013 Blazes Past Growth Targets and Reaches 40,000 Active Customer Accounts
- Cloud Expo New York: Delivering Digital Marketing on the Cloud
- Cloudant to Exhibit at Cloud Expo & Big Data Expo New York
- Cloud Expo New York: Rethink IT and Reinvent Business with IBM SmartCloud
- The Accessibility of the Cloud
- Learn How To Use Google Apps Script
- Cloud Expo New York: Basics of SSD Technology and Its Use in Cloud
- Cloud Expo New York: Real-Time Analytics Using an In-Memory Data Grid
- Cloud Expo NY: Best Practices for Delivering Oracle Database as a Service
- Cloud Expo New York: The Big Challenge of Big Data & Hadoop Integration
- Measuring the Business Value of Cloud Computing
- Cloud People: A Who's Who of Cloud Computing
- Cloud Expo New York: Best CIO Practices Shared from SHI’s Customers
- Examining the True Cost of Big Data
- Cloud Expo New York: How to Use Google Apps Script
- New Relic Q1 2013 Blazes Past Growth Targets and Reaches 40,000 Active Customer Accounts
- Software Defined Networking – A Paradigm Shift
- Cloud Expo New York: Why Big Data Is Really About Small Data
- Cloud Expo New York: Delivering Digital Marketing on the Cloud
- Small Cancers, Big Data, and a Life Examined
- Cloud Expo New York: Requirements of a Cloud Database
- Cloud Expo NY: Calculating the True Value of Industry-Specific Clouds
- Cloudant to Exhibit at Cloud Expo & Big Data Expo New York
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- JavaServer Faces (JSF) vs Struts
- The i-Technology Right Stuff
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- What's New in Eclipse?
- Where Are RIA Technologies Headed in 2008?
























