2016-04-18 30 views
1

rsyslog、remote logging、elasticsearchの新機能です。Rsyslogの設定(Docker-> TCP-> Rsyslog-> ElasticSearch)

私はTCPを介して$ HOST:$ PORTにロギングを送るpythonスクリプト(ドッカーコンテナーから実行される)を構成しました。

私は、alsにrsyslogというモジュール、mmnormalizeモジュールとomelasticsearchモジュールをインストールしました。

ここで、elasticsearchを使用してログ(172.17.0.0/16から取得)を収集するために、(ホスト上の)rsyslog.confがどのようになっているかを理解したいと思います。

ありがとうございました!ここで

答えて

0

は、私はこの問題を解決する方法である:「インデックス名またはパターンを」ドッキングウィンドウ「に:

# /etc/rsyslog.d/docker.rb 
version=2 
# My sample record 
# [Apr 25 12:00]$CONTAINER_HOSTNAME:INFO:Package.Module.Sub-Module:Hello World 
# 
# Here there is the rule to parse the log records into trees 
rule=:[%date:char-to:]%]%hostname:char-to::%:%level:char-to::%:%file:char-to::%:%message:rest% 
# 
# alternative to set date field in rfc3339 format 
# rule=:[%date:date-rfc3339%]%hostname:char-to::%:%level:char-to::%:%file:char-to::%:%message:rest% 

# /etc/rsyslog.conf 
module(load="mmnormalize") 
module(load="omelasticsearch") 
module(load="imtcp") 

# apply to log records coming from address:port the specified rule 
input(type="imtcp" 
     address="127.0.0.1" # $HOST 
     port="514"   # $PORT 
     ruleset="docker-rule") 

# define the rule in two actions; parsing the log record into a tree with 
# root $! ($!son-node!grandson-node...) and adding to the elasticsearch index 
# 'docker-logs' the parsed tree, but in a JSON format (specified in a template) 
ruleset(name="docker-rule"){ 
    action(type="mmnormalize" 
      rulebase="/etc/rsyslog.d/docker.rb" 
      useRawMsg="on" 
      path="$!") 
    action(type="omelasticsearch" 
      template="docker-template" 
      searchIndex="docker-logs" 
      bulkmode="on" 
      action.resumeretrycount="-1") 
} 

# define the template: 
# 'constants' are simply putting into the record JSON delimiters as '{' or ',' 
# 'properties' are simply putting the values of the parsed tree into fields 
# named in the previous constant statements through 'value="..."' 
# the result is a JSON record like: 
# { "@timestamp":"foo", 
# "hostname":"bar", 
# "level":"foo", 
# "file":"bar", 
# "message":"foo" 
# } 
template(name="docker-template" type="list"){ 
    constant(value="{") 
     constant(value="\"@timestamp\":") 
      constant(value="\"") 
       # because kibana would use '$!date' as string not as date 
       # that is the only field not from the parsed tree 
       property(name="timereported" dateFormat="rfc3339") 
      constant(value="\"") 
     constant(value=",") 
     constant(value="\"hostname\":") 
      constant(value="\"") 
       property(name="$!hostname") 
      constant(value="\"") 
     constant(value=",") 
     constant(value="\"level\":") 
      constant(value="\"") 
       property(name="$!level") 
      constant(value="\"") 
     constant(value=",") 
     constant(value="\"file\":") 
      constant(value="\"") 
       property(name="$!file") 
      constant(value="\"") 
     constant(value=",") 
     constant(value="\"message\":") 
      constant(value="\"") 
       property(name="$!message") 
      constant(value="\"") 
    constant(value="}") 
} 

kibanaをインストール隣に単に設定し、「インデックスパターンを設定」することが可能です-logs "と" Time-field name "を" @timestamp "に変更します。

ログのソース(172.17.0.0/16)は制御されません。正しく解析された場合、$ HOST:$ PORTに送られるすべてのログレコードはelasticsearchインデックスに挿入されます。

関連する問題