2016-10-11 12 views
0

構造化ログ出力(greenfieldプロジェクトで各ログエントリが事前定義された形式のJSONドキュメントになるように)を収集し、ELSに直接公開するようにfilebeatを構成しました。構造化されたログデータを直接ファイル検索で弾性検索にプッシュ

例ログファイルの抜粋(プリティこのポストのフォーマットが、各トップレベルのオブジェクトは、ファイル内の単一の行にあるadditionalは、他のすべてのプロパティが固定され、自由形式であることに注意してください。):

{ 
    "TimeUtc": "2016-09-23T14:13:02.217520245Z", 
    "ServiceKey": "MAAS_SVC", 
    "Title": "Get All Campaigns - Start", 
    "Additional": { 
     "HTTPRequest": { 
      "Method": "GET", 
      "URL": { 
       "Scheme": "", 
       "Opaque": "", 
       "User": null, 
       "Host": "", 
       "Path": "/admin/campaigns", 
       "RawPath": "", 
       "ForceQuery": false, 
       "RawQuery": "", 
       "Fragment": "" 
      }, 
      "Proto": "HTTP/1.1", 
      "ProtoMajor": 1, 
      "ProtoMinor": 1, 
      "Header": { 
       "Accept": ["*/*"], 
       "Accept-Encoding": ["gzip, deflate"], 
       "Connection": ["keep-alive"], 
       "Requestkey": ["78478050-47f0-4d0d-44e8-615d0599574a"], 
       "User-Agent": ["python-requests/2.7.0 CPython/2.7.12 Linux/3.13.0-74-generic"] 
      }, 
      "Body": { 
       "Closer": { 
        "Reader": null 
       } 
      }, 
      "ContentLength": 0, 
      "TransferEncoding": null, 
      "Close": false, 
      "Host": "xxxxxxxxx", 
      "Form": null, 
      "PostForm": null, 
      "MultipartForm": null, 
      "Trailer": null, 
      "RemoteAddr": "xxx.xxx.xxx.xxx", 
      "RequestURI": "/admin/campaigns", 
      "TLS": null, 
      "Cancel": , 
      "Response": null 
     } 
    }, 
    "RequestKey": "78478050-47f0-4d0d-44e8-615d0599574a", 
    "HostAddress": "xxxxxxxxx" 
} 

このELSに次の要求を行うfilebeatでの結果:それはありますが、ネストされたオブジェクトではなく、文字列となり、または私はfilebeatパッチを適用する必要がありますように

{ 
    "@timestamp": "2016-10-12T13:53:21.597Z", 
    "beat": { 
     "hostname": "7bca0e28e69e", 
     "name": "7bca0e28e69e" 
    }, 
    "count": 1, 
    "fields": null, 
    "input_type": "log", 
    "message": "{\"TimeUtc\":\"2016-09-23T14:13:02.217520245Z\",\"ServiceKey\":\"MAAS_SVC\",\"Title\":\"Get All Campaigns - Start\",\"Additional\":{\"HTTPRequest\":{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/admin/campaigns\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/1.1\",\"ProtoMajor\":1,\"ProtoMinor\":1,\"Header\":{\"Accept\":[\"*/*\"],\"Accept-Encoding\":[\"gzip, deflate\"],\"Connection\":[\"keep-alive\"],\"Requestkey\":[\"78478050-47f0-4d0d-44e8-615d0599574a\"],\"User-Agent\":[\"python-requests/2.7.0 CPython/2.7.12 Linux/3.13.0-74-generic\"]},\"Body\":{\"Closer\":{\"Reader\":null}},\"ContentLength\":0,\"TransferEncoding\":null,\"Close\":false,\"Host\":\"bistromath.marathon.mesos:40072\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"172.20.1.70:42854\",\"RequestURI\":\"/admin/campaigns\",\"TLS\":null,\"Cancel\":,\"Response\":null}},\"RequestKey\":\"78478050-47f0-4d0d-44e8-615d0599574a\",\"HostAddress\":\"ba47316c9c45\"}", 
    "offset": 0, 
    "source": "/filebeat/log-harvest/maas-service-single.log", 
    "type": "log" 
} 

は、私は私のログJSONから逃げるfilebeatを防ぐことはできますか?

+1

サンプルログラインと使用しているFilebeatプロスペクタの設定を投稿してください。 –

答えて

1

Filebeat 5.xではJSONメッセージを解析できますが、Filebeat 1.xでは解析できません。設定ファイルでjsonオプションを指定することができます。

Filebeat 1.xを使用することに限定されている場合は、messageフィールドからJSONデータを解析するためにLogstashする必要があります。 Filebeat - > Logstash - > Elasticsearchを設定します。

Filebeat 5.xの構成:

filebeat: 
    prospectors: 
    - paths: 
     - input.json 
     json.message_key: Title 
     json.keys_under_root: true 
     json.add_error_key: true 

output: 
    console: 
    pretty: true 

出力例:

{ 
    "@timestamp": "2016-10-12T22:40:16.338Z", 
    "Additional": { 
    "HTTPRequest": { 
     "Body": { 
     "Closer": {} 
     }, 
     "Close": false, 
     "ContentLength": 0, 
     "Header": { 
     "Accept": [ 
      "*/*" 
     ], 
     "Accept-Encoding": [ 
      "gzip, deflate" 
     ], 
     "Connection": [ 
      "keep-alive" 
     ], 
     "Requestkey": [ 
      "78478050-47f0-4d0d-44e8-615d0599574a" 
     ], 
     "User-Agent": [ 
      "python-requests/2.7.0 CPython/2.7.12 Linux/3.13.0-74-generic" 
     ] 
     }, 
     "Host": "xxxxxxxxx", 
     "Method": "GET", 
     "Proto": "HTTP/1.1", 
     "ProtoMajor": 1, 
     "ProtoMinor": 1, 
     "RemoteAddr": "xxx.xxx.xxx.xxx", 
     "RequestURI": "/admin/campaigns", 
     "URL": { 
     "ForceQuery": false, 
     "Fragment": "", 
     "Host": "", 
     "Opaque": "", 
     "Path": "/admin/campaigns", 
     "RawPath": "", 
     "RawQuery": "", 
     "Scheme": "" 
     } 
    } 
    }, 
    "HostAddress": "xxxxxxxxx", 
    "RequestKey": "78478050-47f0-4d0d-44e8-615d0599574a", 
    "ServiceKey": "MAAS_SVC", 
    "TimeUtc": "2016-09-23T14:13:02.217520245Z", 
    "Title": "Get All Campaigns - Start", 
    "beat": { 
    "hostname": "host", 
    "name": "host" 
    }, 
    "input_type": "log", 
    "offset": 919, 
    "source": "input.json", 
    "type": "log" 
} 

注:あなたが投稿JSONデータが有効ではありません。 Cancelフィールドに値がありませんでした。 Filebeatでデータを実行する前にnullに設定します。