In order to use Graylog2 in the right way within servicemix and karaf some configuration steps are required. According to the karaf documentation these are the steps:
- add a new appender in <servicemix_home>/etc/org.ops4j.pax.logging.cfg
- generate an OSGi bundle using the Fragment-Host element in maven felix plugin
- add the bundle to the servicemix installation
- update the DS component log4j.properties file
Step 1.
On your servicemix server go to servicemix_home directory and open the file etc/org.ops4j.pax.logging.cfg using any text editor. Add the following lines at the bottom:
#Graylogger
log4j.logger.my.package.logging.to.graylog=INFO, graylog2
log4j.appender.graylog2=org.graylog2.log.GelfAppender
log4j.appender.graylog2.graylogHost=<graylog_server_address>
log4j.appender.graylog2.facility=<application_name>
log4j.appender.graylog2.Threshold=INFO
The line in italic is actually setting the package using the graylog2 appender for the agent. Let's say we want to have DSS using graylog2 then we need to add a similar there.
Step 2.
Clone the repository from
github: https://github.com/vivosys/gelfj
branch: osgi-bundle-enable
And generate the bundle using the command: mvn clean install
Note that the pom.xml already contains all the configuration for the felix plugin as defined by karaf documentation:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>
maven
-bundle-plugin</artifactId>
maven
-bundle-plugin</artifactId>
<version>2.3.5</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Name>...</Bundle-Name> <Bundle-SymbolicName>...</Bundle-SymbolicName>
<Import-Package>!*</Import-Package>
<Import-Package>!*</Import-Package>
<Embed-Dependency>*;scope=compile|runtime;inline=true</Embed-Dependency>
<Fragment-Host>org.ops4j.pax.logging.pax-logging-service</Fragment-Host>
<Implementation-Version>...</Implementation-Version>
</instructions>
</configuration>
</plugin>
Step 3.
Copy the generated file gelfj-0.9.1-SNAPSHOT.jar on test-integral in <servicemix_home>/system/org/ops4j/logging/gelfj/0.9.1-SNAPSHOT/gelfj-0.9.1-SNAPSHOT.jar. Generate the missing directory if needed.
The etc/startup.properties must be updated as well adding the part in bold below:
org/ops4j/pax/url/pax-url-wrap/1.2.4/pax-url-wrap-1.2.4.jar=5
org/ops4j/logging/gelfj/0.9.1-SNAPSHOT/gelfj-0.9.1-SNAPSHOT.jar=7
org/ops4j/pax/logging/pax-logging-api/1.5.3/pax-logging-api-1.5.3.jar=8
Restart servicemix: sudo /etc/init.d/servicemix restart
Step 4.
To setup the bundle that is going to log through Graylog its log4j.properties must be updated as listed below:
log4j.logger.com.nature.dsm.agent.bean.graylog=INFO, graylog2
log4j.appender.graylog2=org.graylog2.log.GelfAppender
log4j.appender.graylog2.graylogHost=<graylog_server_address>
log4j.appender.graylog2.facility=<application_name>
log4j.appender.graylog2.Threshold=INFO
Redeploy the component on your servicemix instance and have it writing some entries in Graylog2 (ie: reaching the point where your business logic is logging) then check if those entries are saved in Graylog.
Appenders in servicemix
This approach can be applied for any other appender that you want to use in any bundle either if it is using Camel in Karaf or not. As a matter of fact you generally want to have some log information written in a separate appender (ie: a file) for debugging purposes for instance.
This can be easily configured by adding the appender in etc/org.ops4j.pax.logging.cfg like:
log4j.logger.my.package.logging.to.the.file=DEBUG, F
log4j.appender.F=org.apache.log4j.DailyRollingFileAppender
log4j.appender.F.File=<servicemix_home>/data/log/app_log.log
log4j.appender.F.layout=org.apache.log4j.PatternLayout
log4j.appender.F.layout.ConversionPattern=%d{ABSOLUTE} %d{ABSOLUTE} [%5p - %t] %c: %m%n
Then add the same configuration to your bundle and redeploy. The nice thing is that you don't need to restart Karaf or Servicemix to have the new logging configuration working.
Check this page out if you want to install your local instance of Graylog:
http://blog.milford.io/2012/03/installing-graylog2-0-9-6-elasticsearch-0-18-7-mongodb-2-0-3-on-centos-5-with-rvm/
Please check the below link for integrating Syslog-ng, Logstash along with Graylog2 for collecting logs from Network devices.
ReplyDeletehttp://sharmith.blogspot.in/2012/05/network-device-syslog-ng-logstash.html