使用logstash的input file filter收集日志文件
使用logstash的input file filter收集日志文件
一、需求
使用logstash读取本地磁盘上的文件,并通过标准输出输出出来。
二、实现步骤
1、前置知识
1、读取本地磁盘文件?
可以通过 input file plugin 来实现。
2、如何保证文件的每一行只读取一次?
这个是通过 sincedb
来保证的。
2、编写pipeline文件
vim multi-input/multi-input.conf
input {
file {
path => ["/Users/huan/soft/elastic-stack/logstash/logstash/pipeline.conf/multi-input/redis.log"]
start_position => "beginning"
sincedb_path => "/Users/huan/soft/elastic-stack/logstash/logstash/pipeline.conf/multi-input/sincedb.db"
type => "redis"
mode => "read"
stat_interval => "1 second"
discover_interval => 15
sincedb_write_interval => 15
add_field => {
"custom_mode" => "tail"
}
}
file {
path => ["/Users/huan/soft/elastic-stack/logstash/logstash/pipeline.conf/multi-input/springboot.log"]
start_position => "end"
sincedb_path => "/Users/huan/soft/elastic-stack/logstash/logstash/pipeline.conf/multi-input/sincedb.db"
mode => "tail"
type => "springboot"
}
}
# 过滤数据
filter {
}
# 输出
output {
# 如果type的值是redis则使用 rubydebug 输出。 type的值是在 input阶段制定的。
if [type] == 'redis' {
stdout {
codec => rubydebug {
}
}
}
if [type] == 'springboot' {
stdout {
codec => line {
charset => "UTF-8"
}
}
}
}
3、Input 中 file 插件的部分参数解释:
path
:指定了从那个地方读取文件,使用的是glob匹配语法。
["/var/log/*.log"] 表示匹配的是 /var/log 目录下所有的以 .log 结尾的文件。
["/var/log/**/*.log"] 表示匹配的是 /var/log 目录下、以及它下方的子目录下所有的以 .log 结尾的文件。
["/var/log/{redis,springboot}/*.log"] 表示匹配的是 /var/log 目录下方 redis或springboot目录下方所有的以 .log 结尾的文件。
exclue
: 表示需要排除的文件。start_position
:表示从那个地方开始读取文件- beginning 表示从文件开头读取。
- end 表示从文件结尾读取。
sincedb_path
: sincedb数据库文件的位置,必须是一个文件,不可是目录。sincedb 这个记录了当前读取文件的inode、读取到文件字节的position位置、读取的是那个文件、文件最后修改的时候戳。
sincedb_path => /dev/null
开发时为了每次都能从文件的开头读取,设置成 /dev/null 可能会报如下错误。Error: Permission denied - Permission denied
Exception: Errno::EACCES Stack: org/jruby/RubyFile.java:1267:in `utime'
解决方案:将
sincedb_path
的路径设置成一个具体的文件。
stat_interval
: 定时监测文件是否有更新,单位是秒或者string_duration格式。discover_interval
: 每隔多少时间监测是否有新的文件产生,单位是秒。mode
:读取文件的模式,为tail
或read
,默认是tail
。- 当是
read
时,默认读取完这个文件后会删除这个文件。
- 当是
sincedb_write_interval
: 多久将文件的position位置写入到sincedb文件中。
4、启动logstash
bin/logstash -f logstash/pipeline.conf/multi-input/multi-input.conf
5、测试
三、参考链接
2、sincedb_path 设置成 /dev/null 可能报的一个错
使用logstash的input file filter收集日志文件的更多相关文章
- 第八章·Logstash深入-通过TCP/UDP收集日志
1.收集TCP/UDP日志 通过logstash的tcp/udp插件收集日志,通常用于在向elasticsearch日志补录丢失的部分日志,可以将丢失的日志通过一个TCP端口直接写入到elastics ...
- 如何用一张图片代替 'input:file' 上传本地文件??
今天去面试,碰到了一道题,也许是因为紧张或者喝水喝多了,一时竟然没有转过弯来,回来之后一细想原来这么简单,哭笑不得,特此记录一下! 原题是这样的: 如何用一张图片代替 'input:file' 上传 ...
- ie8及其以下版本兼容性问题之input file隐藏上传文件
文件上传时,默认的file标签很难看,而且每个浏览器下都有很大差距.因此我们基本都把真正的file标签给隐藏,然后创建一个标签来替代它.但是由于IE出于安全方面的考虑上传文件时必须点击file的浏览按 ...
- 将input file的选择的文件清空的两种解决方案
<input type="file" id="fileupload" name="file" /> 上传文件时,选择了文件后想清 ...
- input file禁用手机本地文件选择,只允许拍照上传图片
<input type="file" accept="image/*" capture="camera"> 会有个问题,上传的图 ...
- html input file accept 上传文件类型限制格式 MIME 类型列表
例: <input type="file" accept="application/vnd.openxmlformats-officedocument.spread ...
- input file 上传 判断文件类型、路径是否为空
<html> <body bgcolor="white"> <TABLE cellSpacing=0 cellPadding=0 width=&quo ...
- [转]将input file的选择的文件清空
本文转自:http://hi.baidu.com/xiongshihu/item/125c79b47632e794194697f5 上传文件时,选择了文件后想清空文件路径的两种办法: JS代码 < ...
- input file限制上传文件类型
http://www.cnblogs.com/haocool/p/3431181.html http://www.haorooms.com/post/input_file_leixing http:/ ...
随机推荐
- linux常用查询命令
1 **系统** 2 # uname -a # 查看内核/操作系统/CPU信息 3 # head -n 1 /etc/issue # 查看操作系统版本 4 # cat /proc/cpuinfo # ...
- 【第四篇】- Maven 构建生命周期之Spring Cloud直播商城 b2b2c电子商务技术总结
Maven 构建生命周期 Maven 构建生命周期定义了一个项目构建跟发布的过程. 一个典型的 Maven 构建(build)生命周期是由以下几个阶段的序列组成的: 阶段 处理 描述 验证 ...
- webService动态调用及返回至处理
http://www.cnblogs.com/xffy1028/archive/2012/05/07/2487595.html using System; using System.Collectio ...
- freeswitch 编译安装后的配置
--------------------FreeSWITCH configuration------------Locations: prefix: /usr/local/freeswitchexec ...
- [源码解析] PyTorch 流水线并行实现 (1)--基础知识
[源码解析] PyTorch 流水线并行实现 (1)--基础知识 目录 [源码解析] PyTorch 流水线并行实现 (1)--基础知识 0x00 摘要 0x01 历史 1.1 GPipe 1.2 t ...
- PHP中的MySQLi扩展学习(四)mysqli的事务与预处理语句
对于 MySQLi 来说,事务和预处理语句当然是它之所以能够淘汰 MySQL(原始) 扩展的资本.我们之前也已经学习过了 PDO 中关于事务和预处理语句相关的内容.所以在这里,我们就不再多讲理论方面的 ...
- CentOS Linux 简单安装 clickhouse
本文只是仅仅的介绍安装 至于更多介绍请自信百度 1.本人 linux版本 [root@localhost /]# cat /etc/redhat-releaseCentOS Linux release ...
- jmeter旅程第二站:jmeter登录接口测试
因为上一篇已经讲了jmeter抓包,那么接下来会将讲解jmeter接口测试. 这里以浏览器为例. 从简到繁,那么首先先以比较常见的登录做实例. 目前登录操作有这几种:账户是否存在.账户密码登录.验证码 ...
- 10分钟教你使用Picgo+GitHub+ jsDelivr搭建CDN加速免费图床
前言 经常写Markdown或者博客的同学,肯定都要用到图床.图床是什么呢?其实相当于一个存储图片的网站,类似百度云这样,不过上传图片到图床后可以直接通过外链进行访问. 比如把本地一张a.jpg上传到 ...
- english note(6.17to6.23)
6.17 http://www.51voa.com/VOA_Special_English/are-these-us-treasures-about-to-be-destroyed-82260_1.h ...