After I used fluent-plugin-kafka, I found that I had no time field in my log.
follows:
{"client_ip":"39.76.243.121","domain":"
i.xxx.com","method":"GET","url":"/login/callback?pwd=0&d=emXYDnLHD6emC279&tsl=0&auth=jBDNN%2BpeV7JDqZ%2Fxmyu4RVGo1HuNiMjd8gj98oMbtWbgFyQ8ZkO3FVKOyo3LIi0jC3WV5nDH%2Bi%2BWZA2RmW%2F%2FpmtmzkaivDgErjuk1x%2F07XZqUa9uo5aYZkbTAA%2FqYXMQdi4HXf4HtErNWQZx7GfZcyoq5OtiAQ%2FTG8bz%2Bn6y%2F8Q%3D&m=1&pass_eas=6.0&pass_uas=8.0&pass_ss=6.0&nonce=smvZw3bR4S4Bbxre&_ssign=5AsKKQzLv2YYHrBwDt0j1OYaN3I%3D&clientSign=VyhhPhkYecG9vmaUSOxwrtCAe4c%3D&_userIdNeedEncrypt=true","http_ver":"HTTP/1.0","http_code":"200","http_length":"741","referer":"-","ua":"2014811/wt88047; MIUI/V6.7.1.0.KHJCNCH E/V6 B/S L/zh-CN LO/CN","proxy_ip":"10.108.70.12","upstream_addr":"
127.0.0.1:9000","request_time":"0.001","response_time":"0.001","upstream_status":"200","custom_status":"-","userid":"","logid":"496401249220","time":1443515401,"tag":"ngx_log_xxx"}
My fluentd configuration is as follows:
########td-agent.conf###########
<source>
type tail
format /^(?<client_ip>[^ ]*) - (?<domain>[^ ]*) \[(?<log_time>[^\]]*)\] "(?<method>[^ ]*) (?<url>[^ ]*) (?<http_ver>[^ ]*)" (?<http_code>[^ ]*) (?<http_length>[^ ]*) "(?<referer>[^ ]*)" "(?<ua>[^\"]*)" "(?<proxy_ip>[^\/]*)/(?<upstream_addr>[^\"]*)" "(?<request_time>[^\/]*)/(?<response_time>[^\/]*)/(?<upstream_status>[^\/]*)/(?<custom_status>[^\/]*)/(?<userid>[^\"]*)"( "(?<logid>[^"]*)")?$/
time_format %d/%b/%Y:%H:%M:%S %z
pos_file /tmp/td-agent/nginx_log.pos
#refresh_interval 60
path /home/work/logs/nginx/*.log
tag ngx_log_xxx
</source>
<match ngx_log_xxx>
type kafka
brokers kafka01:9092,kafka02:9092,kafka03:9092
zookeeper zk01:2181,zk02:2181,zk03:2181
default_topic kafka_test
output_data_type json
#output_include_tag true
#output_include_time true
</match>
################################
But I want the result to be like this:
{"client_ip":"222.84.167.100","domain":"
xmevent.xxx.com",
"time":"29/Sep/2015:16:31:43 +0800","method":"GET","url":"/login/callback?pwd=0&d=eSjZpzJmym0c7dlS&tsl=0&auth=SB0AyMVyyVx0lyLE%2FubXxiCvcdqbYNLWuWmDDKW9PDBb2Xjmep%2FoEL5BUjWgmUc1gR2AXosiQzvRLQMDkPN7vHtJwNHSEWaJw%2FOpFIF8LWXaoXDU%2B5DJKi5fP24SWkb7dJREJA07b%2BFFf9lLme8ODUn2dDRuSErex2EJtGbYXQg%3D&m=1&pass_eas=9.0&pass_uas=4.0&pass_ss=7.0&nonce=1JQ30TqRERYBbxrf&_ssign=ENDBT9SB%2BwjrAyypY1PLOFSBByE%3D&_userIdNeedEncrypt=true&clientSign=vJxpZfnzcw6rCcc6ZrEGtWXRcgU%3D","http_ver":"HTTP/1.0","http_code":"200","http_length":"849","referer":"-","ua":"Redmi Note 2/Redmi Note 2; MIUI/V6.7.10.0.LHMCNCH E/V6 B/S L/zh-CN LO/CN","proxy_ip":"10.108.47.18","upstream_addr":"
127.0.0.1:9000","request_time":"0.003","response_time":"0.003","upstream_status":"200","custom_status":"0","userid":"","logid":"603503536912","time":1443515503,"tag":"ngx_log_xxx"}
I tried to change the time to log_time in the log format to be output, but I need time to create the pattern index, and I now find that I can't create the pattern time if it is collected by me,
1, time field in fluentd-plugin-kafka and td-agent whether there is a special significance? Is there any way to solve this problem?
2, in the fluentd-plugin-kafka is to create such a tag: ngx_xxx_log-2015.09.29