logstash 收集nginx 日志 windows
nginx 配置:
1 2 3 4 | log_format main 'remote_user=$remote_user&ip=$remote_addr&real_ip=$http_x_forwarded_for&log_time=$time_local&request_time=$request_time&host=$http_host&$args&status=$status&body_bytes_sent=$body_bytes_sent&referer=$http_referer&user_agent=$http_user_agent&forwarded_for=$http_x_forwarded_for' ; access_log logs/access.log main; |
1 2 3 | location = /s.gif { empty_gif; } |
logstash 配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | input { file{ path => "E:/test/nginx-1.18.0/logs/access.log" start_position => "beginning" stat_interval => "2" } } filter{ urldecode{ field => message } kv{ field_split => "&" }<br> } output { jdbc { # 配置数据库信息 connection_string => "jdbc:mysql://localhost:3306/logstash_test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai" driver_class => "com.mysql.cj.jdbc.Driver" username => "root" password => "123456" driver_jar_path => "E:/test/logstash-7.14.2/mysql/mysql-connector-java-8.0.25.jar" statement => [ "insert into log_coll(timestamp,args,remote_addr,name,age) VALUES(?,?,?,?,?)" , "timestamp" , "user_agent" , "remote_addr" , "name" , "age" ] } stdout { codec => rubydebug } } |
ruby{
code => "
event.set('tts',(Time.now.to_f.round(3)*1000).to_i) #毫秒时间戳
value = event.get('oaid')
require 'digest/md5'
md5 = Digest::MD5::hexdigest(value)
event.set('oaid', md5) # oaid MD5 加密
"
}
启动 bin 目录 .\logstash -f .\logstash.conf
输出output 添加http
nginx请求 :http://127.0.0.1/s.gif?name=123%E5%93%88%E5%93%88&ket=sd&age=9989&et=10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | input { file{ path => "E:/test/nginx-1.18.0/logs/access.log" start_position => "beginning" stat_interval => "2" } } filter{ urldecode{ field => message } kv{ field_split => "&" } } output { jdbc { # 配置数据库信息 connection_string => "jdbc:mysql://localhost:3306/logstash_test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai" driver_class => "com.mysql.cj.jdbc.Driver" username => "root" password => "123456" driver_jar_path => "E:/test/logstash-7.14.2/mysql/mysql-connector-java-8.0.25.jar" statement => [ "insert into log_coll(timestamp,args,remote_addr,name,age) VALUES(?,?,?,?,?)" , "timestamp" , "user_agent" , "remote_addr" , "name" , "age" ] } if [et] == "10" { http { http_method => "post" url => "http://localhost:8779/device/profit" format => "json" mapping => { "name" => "%{name}" "age" => "%{age}" } } } stdout { codec => rubydebug } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
2020-09-24 Linux 安装 redis
2020-09-24 安装mysql 不下载包 简单方式
2017-09-24 springBoot 打包 dubbo jar包
2017-09-24 Spring Boot Dubbo applications.properties 配置清单