LoginSignup
2
2

More than 3 years have passed since last update.

WildflyのアクセスログをFilebeatでElasticsearchへ取り込む

Last updated at Posted at 2020-08-08

はじめに

WildflyのアクセスログをFilebeatでElasticsearchへ取り込む設定を行います。

環境

使用した環境は以下のとおり。

  • CentOS 7.5
  • Elasticsearch 7.8
  • Kibana 7.8
  • Filebeat 7.8
  • Wildfly 20.0.1.Final

Elasticsearch/Kibana/Elastic APMは、「ElasticStack 7.8 環境構築」で構築した環境を利用しています。

Wildflyでアクセスログを出力する

Wildflyのアクセスログはデフォルトでは出力されないので、まずアクセスログを出力することから始めます。

standalone.xmlのundertowの設定箇所に"<access-log/>"を追記します。
これで、standalone/logs/access-logへアクセスログが出力されるようになります。
フォーマットではデフォルトでCommon Log Format (CLF)になります。

設定変更後のstandalone.xmlは以下のようになります。

standalone.xml
        <subsystem xmlns="urn:jboss:domain:undertow:11.0" default-server="default-server" default-virtual-host="default-host" default-servlet-container="default" default-security-domain="other" statistics-enabled="${wildfly.undertow.statistics-enabled:${wildfly.statistics-enabled:false}}">
            <buffer-cache name="default"/>
            <server name="default-server">
                <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
                <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
                <host name="default-host" alias="localhost">
                    <location name="/" handler="welcome-content"/>
                    <http-invoker security-realm="ApplicationRealm"/>
                    <access-log/>
                </host>
            </server>

"combined"にする場合は、"<access-log pattern="combined"/>"に変更します。

"combined"にした場合のログは以下のように出力されます。

192.168.10.100 - - [08/Aug/2020:03:09:41 +0200] "GET /wildfly_logo.png HTTP/1.1" 304 -
192.168.10.100 - - [08/Aug/2020:03:09:41 +0200] "GET /jbosscommunity_logo_hori_white.png HTTP/1.1" 304 -
192.168.10.100 - - [08/Aug/2020:03:09:42 +0200] "GET /wildfly-apm-testapp/services/test/test1 HTTP/1.1" 200 -

なお、コンソールから修正する場合は以下のようにコマンドを実行します。

# ./jboss-cli.sh --connect --controller=[IPアドレス]:9990

/subsystem=undertow/server=default-server/host=default-host/setting=access-log:add
{
    "outcome" => "success",
    "response-headers" => {
        "operation-requires-reload" => true,
        "process-state" => "reload-required"
    }
}

# access-logの属性を確認する場合
[standalone@192.168.10.126:9990 setting] /subsystem=undertow/server=default-server/host=default-host/setting=access-log:read-attribute(name=pattern)
{
    "outcome" => "success",
    "result" => "combined"
}

# access-logの属性を変更する場合
[standalone@192.168.10.126:9990 setting] /subsystem=undertow/server=default-server/host=default-host/setting=access-log:write-attribute(name=pattern,value=combined)
{"outcome" => "success"}

[standalone@192.168.10.126:9990 setting] /subsystem=undertow/server=default-server/host=default-host/setting=access-log:read-resource
{
    "outcome" => "success",
    "result" => {
        "directory" => expression "${jboss.server.log.dir}",
        "extended" => true,
        "pattern" => "common",
        "predicate" => undefined,
        "prefix" => "access_log.",
        "relative-to" => undefined,
        "rotate" => true,
        "suffix" => "log",
        "use-server-log" => false,
        "worker" => "default"
    },
    "response-headers" => {"process-state" => "reload-required"}
}

# access-logを削除する場合

/subsystem=undertow/server=default-server/host=default-host/setting=access-log:remove

Filebeatの設定

次にFilebeatでApacheログフォーマットのログを入力として、Elasticsearchへ送信するように設定します。

まずは、Filebeatのapacheモジュールを有効にします。

# filebeat modules enable apache
Enabled apache
# filebeat modules list
Enabled:
apache

次にapacheモジュールの設定を変更します。
apacheモジュールの設定は以下の公式サイトを参考にして実施しています。

# vi /etc/filebeat/modules.d/apache.yml 

変更後のapache.ymlは以下のようになります。

/etc/filebeat/modules.d/apache.yml
# grep -vE '^ *#|^$' /etc/filebeat/modules.d/apache.yml 
- module: apache
  access:
    enabled: true
    var.paths: ["/opt/wildfly-20.0.1.Final/standalone/log/access_log.log*"]
  error:
    enabled: false

filebeat.ymlは以下のように設定しました。

/etc/filebeat/filebeat.yml
# grep -vE '^ *#|^$' /etc/filebeat/filebeat.yml
filebeat.config.modules:
  path: ${path.config}/modules.d/*.yml
  reload.enabled: false
setup.kibana:
  host: "localhost:5601"
output.elasticsearch:
  hosts: ["localhost:9200"]

最後にFilebeatを以下のコマンドで再起動します。

# systemctl stop filebeat
# systemctl start filebeat

KibanaでWildflyのアクセスログを確認する

Kibanaの左側のメニューから[Logs]を選択して、アクセスログを表示することができます。

image.png

また、Filebeatは自動でダッシュボードのサンプルを作成しています。
サンプルのダッシュボード([Filebeat Apache] Access and error logs ECS)を選択すると以下のようなグラフが表示されます。

image.png

参考

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2