数码资讯
filebeat 获取nginx日志 发送给ElasticSearch
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
目的:通过filebeat获取nginx日志,发送给ElasticSearch,filebeat可以解析json格式日志,所以设置nginx日志为json格式。
1、配置nginx配置文件
log_format jsonTest '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"service":"nginxTest",'
'"trace":"$upstream_https_ctx_transaction_id",'
'"log":"log",'
'"clientip":"$remote_addr",'
'"remote_user":"$remote_user",'
'"request":"$request",'
'"https_user_agent":"$https_user_agent",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"https_host":"$host",'
'"url":"$uri",'
'"domain":"$host",'
'"xff":"$https_x_forwarded_for",'
'"referer":"$https_referer",'
'"status":"$status"}';
access_log /var/log/nginx/access.log jsonTest;
定义jsonTest的json格式,其中trace是页面response headers的值 ctx-transaction-id,通过upstream_https_ctx_transaction_id可以获取头文件属性。
将日志输出到/var/log/nginx/access.log
2、配置filebeat配置文件
filebeat.prospectors: - type: log paths: - '/root/front/logs/*.log' json.message_key: log json.keys_under_root: true output.elasticsearch: hosts: ["*.*.*.*:9200"]
将日志传输给ElasticSearch
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。