引言
Datadog的Vector 是一个高性能的端到端(代理和聚合器)可观察性数据管道,可以让你收集、转换和路由所有的日志和指标。此外,它是开源的。虽然它本身可以作为聚合器,但结合使用Vector.dev和专门的数据存储工具(如Manticore)会更加有效。
让我们看看它们如何协同工作。为此,我们将使用对dpkg.log
的索引示例,这是Debian软件包管理器的标准日志文件。日志本身结构简单,如下所示:
2023-05-31 10:42:55 status triggers-awaited ca-certificates-java:all 20190405ubuntu1.1
2023-05-31 10:42:55 trigproc libc-bin:amd64 2.31-0ubuntu9.9 <none>
2023-05-31 10:42:55 status half-configured libc-bin:amd64 2.31-0ubuntu9.9
2023-05-31 10:42:55 status installed libc-bin:amd64 2.31-0ubuntu9.9
2023-05-31 10:42:55 trigproc systemd:amd64 245.4-4ubuntu3.21 <none>
配置
以下是Vector.dev的配置文件的toml格式示例:
[sources.test_file]
type = "file"
include = [ "/var/log/dpkg.log" ]
[transforms.modify_test_file]
type = "remap"
inputs = [ "test_file" ]
source = """
.vec_timestamp = del(.timestamp)"""
[sinks.manticore]
type = "elasticsearch"
inputs = [ "modify_test_file" ]
endpoints = ["http://127.0.0.1:9308"]
bulk.index = "dpkg_log"
请注意,在这个示例中,我们假设Manticore使用其默认的http端口9308。如果你使用的是自定义的http端口,你应该相应地更改你的Vector.dev配置。还要注意,我们在配置中添加了transforms
部分,以重命名默认的timestamp
字段,因为它是Manticore中的保留字。
结果
现在只需使用上述配置启动Vector.dev,来自dpkg日志的数据将被传递到Manticore并正确索引。
以下是创建的表的结果模式和插入文档的示例:
mysql> DESCRIBE dpkg_log;
+-----------------+---------+--------------------+
| Field | Type | Properties |
+-----------------+---------+--------------------+
| id | bigint | |
| file | text | indexed stored |
| host | text | indexed stored |
| message | text | indexed stored |
| source_type | text | indexed stored |
| vec_timestamp | text | indexed stored |
+-----------------+---------+--------------------+
mysql> SELECT * FROM testlog_3 LIMIT 3\G
*************************** 1. row ***************************
id: 7856533729353672195
file: /var/log/dpkg.log
host: logstash-787f68f6f-nhdd2
message: 2023-06-05 14:03:04 startup archives install
source_type: file
vec_timestamp: 2023-08-04T15:32:50.203091741Z
*************************** 2. row ***************************
id: 7856533729353672196
file: /var/log/dpkg.log
host: logstash-787f68f6f-nhdd2
message: 2023-06-05 14:03:04 install base-passwd:amd64 <none> 3.5.47
source_type: file
vec_timestamp: 2023-08-04T15:32:50.203808861Z
*************************** 3. row ***************************
id: 7856533729353672197
file: /var/log/dpkg.log
host: logstash-787f68f6f-nhdd2
message: 2023-06-05 14:03:04 status half-installed base-passwd:amd64 3.5.47
source_type: file
vec_timestamp: 2023-08-04T15:32:50.203814031Z
结论
因此,通过本指南中概述的集成,你现在可以轻松有效地通过与Datadog的Vector结合使用Manticore来索引你的日志数据。Vector.dev和Manticore之间的这种协同不仅提供了一种管理日志数据的简化方法,还通过允许转换和路由来扩展功能。无论你是处理简单还是复杂的日志结构,这种集成都提供了一个强大的解决方案,使收集、转换和存储数据的过程更加简单和高效。