使用 Apache Tomcat 7 服务器收集日志
在此示例中,我们使用文件输入插件收集安装在 windows 中的 Apache Tomcat 7 服务器的日志并将它们发送到另一个日志。
logstash.conf
这里,Logstash被配置为访问本地安装的Apache Tomcat 7的访问日志。正则表达式模式用于文件插件的路径设置以从日志文件中获取数据。这在其名称中包含“访问”,并添加了 apache 类型,这有助于将 apache 事件与集中目标源中的其他事件区分开来。最后,输出事件将显示在 output.log 中。
input {
file {
path => "C:/Program Files/Apache Software Foundation/Tomcat 7.0/logs/*access*"
type => "apache"
}
}
output {
file {
path => "C:/tpwork/logstash/bin/log/output.log"
}
}
运行 Logstash
我们可以使用以下命令运行 Logstash。
C:\logstash\bin> logstash –f Logstash.conf
Apache Tomcat 日志
访问 Apache Tomcat 服务器及其 Web 应用程序 (http://localhost:8080) 生成日志。日志中更新的数据由 Logstash 实时读取,并按照配置文件中的指定存储在 output.log 中。
Apache Tomcat 根据日期生成一个新的访问日志文件,并在那里记录访问事件。在我们的例子中,它是 localhost_access_log.2016-12-24.txt 在logsApache Tomcat 目录。
0:0:0:0:0:0:0:1 - - [
25/Dec/2016:18:37:00 +0800] "GET / HTTP/1.1" 200 11418
0:0:0:0:0:0:0:1 - munish [
25/Dec/2016:18:37:02 +0800] "GET /manager/html HTTP/1.1" 200 17472
0:0:0:0:0:0:0:1 - - [
25/Dec/2016:18:37:08 +0800] "GET /docs/ HTTP/1.1" 200 19373
0:0:0:0:0:0:0:1 - - [
25/Dec/2016:18:37:10 +0800] "GET /docs/introduction.html HTTP/1.1" 200 15399
输出日志
您可以在输出事件中看到,添加了一个类型字段,并且该事件出现在消息字段中。
{
"path":"C:/Program Files/Apache Software Foundation/Tomcat 7.0/logs/
localhost_access_log.2016-12-25.txt",
"@timestamp":"2016-12-25T10:37:00.363Z","@version":"1","host":"Dell-PC",
"message":"0:0:0:0:0:0:0:1 - - [25/Dec/2016:18:37:00 +0800] \"GET /
HTTP/1.1\" 200 11418\r","type":"apache","tags":[]
}
{
"path":"C:/Program Files/Apache Software Foundation/Tomcat 7.0/logs/
localhost_access_log.2016-12-25.txt","@timestamp":"2016-12-25T10:37:10.407Z",
"@version":"1","host":"Dell-PC",
"message":"0:0:0:0:0:0:0:1 - munish [25/Dec/2016:18:37:02 +0800] \"GET /
manager/html HTTP/1.1\" 200 17472\r","type":"apache","tags":[]
}
{
"path":"C:/Program Files/Apache Software Foundation/Tomcat 7.0/logs/
localhost_access_log.2016-12-25.txt","@timestamp":"2016-12-25T10:37:10.407Z",
"@version":"1","host":"Dell-PC",
"message":"0:0:0:0:0:0:0:1 - - [25/Dec/2016:18:37:08 +0800] \"GET /docs/
HTTP/1.1\" 200 19373\r","type":"apache","tags":[]
}
{
"path":"C:/Program Files/Apache Software Foundation/Tomcat 7.0/logs/
localhost_access_log.2016-12-25.txt","@timestamp":"2016-12-25T10:37:20.436Z",
"@version":"1","host":"Dell-PC",
"message":"0:0:0:0:0:0:0:1 - - [25/Dec/2016:18:37:10 +0800] \"GET /docs/
introduction.html HTTP/1.1\" 200 15399\r","type":"apache","tags":[]
}