New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Graylog2 support #339

Closed
obigard opened this Issue Sep 11, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@obigard

obigard commented Sep 11, 2014

No description provided.

@cescoffier cescoffier changed the title from Graylog to Provide Graylog2 support Oct 19, 2014

@cescoffier cescoffier added the feature label Oct 19, 2014

@cescoffier cescoffier added this to the 0.7 milestone Oct 19, 2014

@cescoffier cescoffier self-assigned this Oct 19, 2014

@cescoffier

This comment has been minimized.

Show comment
Hide comment
@cescoffier

cescoffier Oct 19, 2014

Member

The simplest way to get Wisdom logs sent to a Graylog 2 server is to use the https://github.com/Moocar/logback-gelf appender.

Graylog 2

First, to test your configuration, you need to get a Graylog 2 server running. If you use docker, then this does the job:

docker run -t --rm -P -e "GRAYLOG2_PASSWORD=password" sjoerdmulder/graylog2
# Retrieve the mapped port using:
docker ps

In the rest of this post,the mapping are:

0.0.0.0:49153->12900/tcp, 0.0.0.0:49153->12201/udp, 0.0.0.0:49154->9000/tcp

So, you can log to your graylog server using either http://localhost:49154 or http://boot2docker:40154, where boot2docker is the boot2docker IP. Credentials are "admin/password".

Adding the appender to the Wisdom server classpath

Use the maven-dependency-plugin to add two artifacts to target/wisdom/bin:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
  <goal>copy</goal>
</goals>
<configuration>
  <artifactItems>
    <artifactItem>
      <groupId>me.moocar</groupId>
      <artifactId>logback-gelf</artifactId>
      <version>0.11</version>
      <type>jar</type>
      <overWrite>false</overWrite>
     <outputDirectory>${project.build.directory}/wisdom/bin</outputDirectory>
    </artifactItem>
    <artifactItem>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
       <version>2.2.4</version>
      <type>jar</type>
      <overWrite>false</overWrite>
     <outputDirectory>${project.build.directory}/wisdom/bin</outputDirectory>
    </artifactItem>
  </artifactItems>
</configuration>
</execution>
</executions>
</plugin>

Appender configuration

We know need to configure the logger with the new appender.

Edit the src/main/configuration/logger.xml file. If this file does not exist, copy the one from target/wisdom/conf/logger.xml (created on the first build).

Then add the following appender:

<appender name="GELF" class="me.moocar.logbackgelf.GelfAppender">
        <facility>logback-gelf-test</facility>
        <graylog2ServerHost>192.168.59.103</graylog2ServerHost>
        <graylog2ServerPort>49153</graylog2ServerPort>
        <useLoggerName>true</useLoggerName>
        <hostName>localhost</hostName>
        <useThreadName>true</useThreadName>
        <useMarker>true</useMarker>
        <graylog2ServerVersion>0.9.6</graylog2ServerVersion>
        <chunkThreshold>1000</chunkThreshold>
        <messagePattern>%m%rEx</messagePattern>
        <shortMessagePattern>%.-100(%m%rEx)</shortMessagePattern>
        <staticAdditionalField>_appName:acme</staticAdditionalField>
        <fieldType>_request_id:long</fieldType>
        <includeFullMDC>true</includeFullMDC>
    </appender>

Edit the graylog2ServerHost and graylog2ServerPort. I recommend you to add a staticAdditionalField to identify your origin. Refer to https://github.com/Moocar/logback-gelf to configure the appender.

Once added, don't forget to add it to the appender list:

    <root level="info" additivity="false">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="ASYNC"/>
        <appender-ref ref="GELF" /> <!-- Added -->
    </root>

Run

That's all, you just have to repackage your application:

mvn clean package

and then, launch the application with the Graylog support with:

cd target/wisdom
./chameleon.sh

The log messages are sent to the graylog server.

Member

cescoffier commented Oct 19, 2014

The simplest way to get Wisdom logs sent to a Graylog 2 server is to use the https://github.com/Moocar/logback-gelf appender.

Graylog 2

First, to test your configuration, you need to get a Graylog 2 server running. If you use docker, then this does the job:

docker run -t --rm -P -e "GRAYLOG2_PASSWORD=password" sjoerdmulder/graylog2
# Retrieve the mapped port using:
docker ps

In the rest of this post,the mapping are:

0.0.0.0:49153->12900/tcp, 0.0.0.0:49153->12201/udp, 0.0.0.0:49154->9000/tcp

So, you can log to your graylog server using either http://localhost:49154 or http://boot2docker:40154, where boot2docker is the boot2docker IP. Credentials are "admin/password".

Adding the appender to the Wisdom server classpath

Use the maven-dependency-plugin to add two artifacts to target/wisdom/bin:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
  <goal>copy</goal>
</goals>
<configuration>
  <artifactItems>
    <artifactItem>
      <groupId>me.moocar</groupId>
      <artifactId>logback-gelf</artifactId>
      <version>0.11</version>
      <type>jar</type>
      <overWrite>false</overWrite>
     <outputDirectory>${project.build.directory}/wisdom/bin</outputDirectory>
    </artifactItem>
    <artifactItem>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
       <version>2.2.4</version>
      <type>jar</type>
      <overWrite>false</overWrite>
     <outputDirectory>${project.build.directory}/wisdom/bin</outputDirectory>
    </artifactItem>
  </artifactItems>
</configuration>
</execution>
</executions>
</plugin>

Appender configuration

We know need to configure the logger with the new appender.

Edit the src/main/configuration/logger.xml file. If this file does not exist, copy the one from target/wisdom/conf/logger.xml (created on the first build).

Then add the following appender:

<appender name="GELF" class="me.moocar.logbackgelf.GelfAppender">
        <facility>logback-gelf-test</facility>
        <graylog2ServerHost>192.168.59.103</graylog2ServerHost>
        <graylog2ServerPort>49153</graylog2ServerPort>
        <useLoggerName>true</useLoggerName>
        <hostName>localhost</hostName>
        <useThreadName>true</useThreadName>
        <useMarker>true</useMarker>
        <graylog2ServerVersion>0.9.6</graylog2ServerVersion>
        <chunkThreshold>1000</chunkThreshold>
        <messagePattern>%m%rEx</messagePattern>
        <shortMessagePattern>%.-100(%m%rEx)</shortMessagePattern>
        <staticAdditionalField>_appName:acme</staticAdditionalField>
        <fieldType>_request_id:long</fieldType>
        <includeFullMDC>true</includeFullMDC>
    </appender>

Edit the graylog2ServerHost and graylog2ServerPort. I recommend you to add a staticAdditionalField to identify your origin. Refer to https://github.com/Moocar/logback-gelf to configure the appender.

Once added, don't forget to add it to the appender list:

    <root level="info" additivity="false">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="ASYNC"/>
        <appender-ref ref="GELF" /> <!-- Added -->
    </root>

Run

That's all, you just have to repackage your application:

mvn clean package

and then, launch the application with the Graylog support with:

cd target/wisdom
./chameleon.sh

The log messages are sent to the graylog server.

@cescoffier cescoffier closed this Oct 19, 2014

@cescoffier cescoffier modified the milestones: 0.7, 0.6.5 Nov 5, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment