Vector是一个高性能的日志采集器,用于构建可观察性(数据)管道的轻量级超快速工具,Vector简单易用并且只自定义组合数据格式灵活的创建数据管道,可收集、转换所有日志、指标、跟踪路由等各种数据,Vector采用Rust编写的,提供了内存安全和效率保证。根据官方说明:Vector可以显著的降低建设数据管道成本、并确保数据安全,开源,并且比所有已知替代方案快10倍;
Vector的主要优势。
What is Vector? | Vector documentation
GitHub - vectordotdev/vector: A high-performance observability data pipeline.
Download | Vector
进入Vecotr安装目录config,如:D:\Program Files\Vector\config
修改vector.toml配置文件,根据需要如下配置:
data_dir = "D:/data2/log/vector"
[sources.goa_logs]
type = "file"
include = ["D:/data2/log/xxxx/run-app.log"]
[transforms.parse_logs]
type = "remap"
inputs = ["xxxx_logs"]
source = '''
. = parse_grok!(string!(.message),"%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:level} %{GREEDYDATA:thread} %{GREEDYDATA:class} %{GREEDYDATA:line} %{GREEDYDATA:message}")
'''
[sinks.print]
type = "console"
inputs = ["parse_logs"]
encoding.codec = "json"
# Vector支持多操作系统平台安装,本例安装以windows为主,通过命令行进入安装包bin目录下
vector.exe --config ..\config\vector.toml
创建Vector的data_dir目录,此目录需要提前创建,用于存放Vector加载日志文件的行号记录;删除此目录下的文件可能会导致Vector重新从头读取日志文件;
本示例需要将Vector采集的项目日志输出到ZincObserve日志服务中,ZincObserve是一个高性能、便捷、易维护使用的日志存储与搜索、可视化数据解决方案;
因已提前安装ZincObserve服务,默认安装后,访问:http://localhost:5080/进入ZincObjserve日志服务控制台界面,从菜单功能》采集界面中的“摄入”功能展示窗口内,复制ZincObsevre自动生成的Vector配置输出参数;
Vector配置文件:D:\Program Files\Vector\config\vector.toml
# __ __ __
# \ \ / / / /
# \ V / / /
# \_/ \/
#
# V E C T O R
# Configuration
#
# ------------------------------------------------------------------------------
# Website: https://vector.dev
# Docs: https://vector.dev/docs
# Chat: https://chat.vector.dev
# ------------------------------------------------------------------------------
# Change this to use a non-default directory for Vector data storage:
data_dir = "D:/data2/log/vector"
# Random Syslog-formatted logs
[sources.goa_logs]
type = "file"
# format = "syslog"
include = ["D:/data2/log/xxx/run-app.log"]
# Parse Syslog logs
# See the Vector Remap Language reference for more info: https://vrl.dev
[transforms.parse_logs]
type = "remap"
inputs = ["xxx_logs"]
source = '''
. = parse_grok!(string!(.message),"%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:level} %{GREEDYDATA:thread} %{GREEDYDATA:class} %{GREEDYDATA:line} %{GREEDYDATA:message}")
'''
# Print parsed logs to stdout
[sinks.print]
type = "console"
inputs = ["parse_logs"]
encoding.codec = "json"
[sinks.zinc]
type = "http"
inputs = ["parse_logs"]
uri = "http://localhost:5080/api/default/default/_json"
method = "post"
auth.strategy = "basic"
auth.user = "[email protected]"
auth.password = "JQR1Nwns7XovcgVL"
compression = "none"
encoding.codec = "json"
encoding.timestamp_format = "rfc3339"
healthcheck.enabled = false
# Vector's GraphQL API (disabled by default)
# Uncomment to try it out with the `vector top` command or
# in your browser at http://localhost:8686
#[api]
#enabled = true
#address = "127.0.0.1:8686"
通过命令行窗口进入到Vector安装目录bin,如:D:\Program Files\Vector\config
运行命令 ,加载vector.toml后程序开始执行日志文件采集与输出;
D:\Program Files\Vector\bin>vector.exe --config ..\config\vector.toml
初次加载日志文件,会根据日志大小读取到当前最新的记录行位置,如果文件比较大会加载比较长的时间,当监听到日志文件发生变化,会从上一次读取记录的位置继续加载新生成的日志内容;
点击ZincObjserve控制台界面的“日志”菜单,开始检索Vector输入的日志内容;
Structuring, Shaping, and Transforming Data | Vector
vector 设置大小_【Rust Crate】vector 多能的日志监听工具_weixin_39847732的博客-CSDN博客