Skip to content

Commit 90ff840

Browse files
authored
Update LoongCollector input_static_file_onetime docs (alibaba#2413)
* add doc Change-Id: I348ba35f7e13189691909384b71017a1ef46eb13 Co-developed-by: Cursor <noreply@cursor.com> * polish Change-Id: Ida630f6d1dc4a1a426b0570b35894ccc00097b4a Co-developed-by: Cursor <noreply@cursor.com> * polish Change-Id: I5fc5360c9c920e373749223dab8685e4a3ea7203 Co-developed-by: Cursor <noreply@cursor.com>
1 parent 5a1dcd4 commit 90ff840

5 files changed

Lines changed: 214 additions & 26 deletions

File tree

docs/cn/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* [什么是输入插件](plugins/input/inputs.md)
4242
* 原生输入插件
4343
* [文本日志](plugins/input/native/input-file.md)
44+
* [一次性文件采集](plugins/input/native/input-static-file-onetime.md)
4445
* [容器标准输出](plugins/input/native/input-container-stdio.md)
4546
* [eBPF网络可观测数据](plugins/input/native/input-network-observer.md)
4647
* [eBPF进程安全数据](plugins/input/native/input-process-security.md)

docs/cn/plugins/input/inputs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
| 名称 | 提供方 | 功能简介 |
1919
| ------------------------------------------------------------------------------ | -------- | ------------------------------------- |
2020
| `input_file`<br>[文本日志](native/input-file.md) | SLS 官方 | 文本采集。 |
21+
| `input_static_file_onetime`<br>[一次性文件采集](native/input-static-file-onetime.md) | SLS 官方 | 一次性文件采集。 |
2122
| `input_container_stdio`<br> [容器标准输出](native/input-container-stdio.md) | SLS 官方 | 从容器标准输出/标准错误流中采集日志。 |
2223
| `input_file_security`<br>[文件安全数据](native/input-file-security.md) | SLS 官方 | 文件安全数据采集。 |
2324
| `input_network_observer`<br>[网络可观测数据](native/input-network-observer.md) | SLS 官方 | 网络可观测数据采集。 |
Lines changed: 210 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,232 @@
1-
# 一次性文件采集(原生插件)
1+
# 一次性文件采集
22

33
## 简介
44

5-
`input_static_file_onetime` 插件对匹配到的文件集合执行一次性读取并输出,适用于历史文件或批量补采场景
5+
`input_static_file_onetime`插件是LoongCollector的OneTime类型输入插件,专门用于一次性文件采集任务。与常规的`input_file`插件不同,该插件执行一次后即完成采集任务,不会持续监控文件变化,适用于历史文件采集、数据迁移、批量数据处理等场景
66

77
## 版本
88

99
[Beta](../../stability-level.md)
1010

11+
## 版本说明
12+
13+
* 推荐版本:暂无(可使用edge版体验)
14+
15+
## 核心特性
16+
17+
### OneTime执行模式
18+
- **一次性执行**:插件启动后扫描指定路径下的所有匹配文件,完成采集后自动停止
19+
- **批量处理**:支持同时处理大量文件,无需持续监控
20+
- **资源优化**:避免长期占用系统资源,适合批处理场景
21+
22+
### 强大的文件发现能力
23+
- **通配符支持**:支持`*``**`通配符进行文件路径匹配
24+
- **递归搜索**:支持深度目录搜索,可配置最大搜索深度
25+
- **黑名单过滤**:支持文件路径、文件名、目录黑名单过滤
26+
27+
1128
## 配置参数
1229

13-
| 参数 | 类型 | 必填 | 默认值 | 说明 |
30+
### 全局配置参数(必填)
31+
32+
| **参数** | **类型** | **是否必填** | **默认值** | **说明** |
1433
| --- | --- | --- | --- | --- |
15-
| Type | string || / | 固定为 `input_static_file_onetime` |
16-
| FilePaths | [string] || / | 文件路径,支持 `*``**``**` 仅用于文件前缀的目录匹配且最多出现一次 |
17-
| MaxDirSearchDepth | uint || 0 | `**` 的最大目录递归深度 |
18-
| ExcludeFilePaths | [string] ||| 文件路径黑名单(绝对路径,支持 `*`|
19-
| ExcludeFiles | [string] ||| 文件名黑名单(支持 `*`|
20-
| ExcludeDirs | [string] ||| 目录黑名单(绝对路径,支持 `*`|
21-
| FileEncoding | string || utf8 | 文件编码,支持 utf8、gbk |
22-
| TailSizeKB | uint || 1024 | 初次生效时相对文件结尾的起始偏移(KB),小于文件大小时从尾部回溯 |
23-
| Multiline | object ||| 多行聚合选项,支持 custom 与 JSON,见下表 |
24-
| Tags | map[string]string ||| Tag 重命名/删除配置,含 `__default__` 语义 |
25-
26-
多行聚合选项:
27-
28-
| 参数 | 类型 | 必填 | 默认值 | 说明 |
34+
| ExcutionTimeout | uint || / | OneTime配置执行超时时间(秒)。取值范围:600~604800(10分钟~1周)。超过此时间配置将自动过期并被删除。 |
35+
36+
### 插件配置参数
37+
38+
| **参数** | **类型** | **是否必填** | **默认值** | **说明** |
39+
| --- | --- | --- | --- | --- |
40+
| Type | string || / | 插件类型。固定为input\_static\_file\_onetime。 |
41+
| FilePaths | []string || / | 待采集的文件路径列表(目前仅限1个路径)。支持使用\*\*\*通配符。 |
42+
| MaxDirSearchDepth | int || 0 | 文件路径中\*\*通配符匹配的最大目录深度。取值范围为0~1000。 |
43+
| ExcludeFilePaths | []string ||| 文件路径黑名单。支持使用\*通配符。 |
44+
| ExcludeFiles | []string ||| 文件名黑名单。支持使用\*通配符。 |
45+
| ExcludeDirs | []string ||| 目录黑名单。支持使用\*通配符。 |
46+
| FileEncoding | string || utf8 | 文件编码格式。可选值包括utf8和gbk。 |
47+
| Multiline | object ||| 多行聚合选项。详见表1。 |
48+
| AppendingLogPositionMeta | bool || false | 是否在日志中添加该条日志所属文件的元信息,包括\_\_tag\_\_:\_\_inode\_\_字段和\_\_file\_offset\_\_字段。 |
49+
| Tags | map[string]string ||| 重命名或删除tag。map中的key为原tag名,value为新tag名。若value为空,则删除原tag。 |
50+
51+
* 表1:多行聚合选项
52+
53+
| **参数** | **类型** | **是否必填** | **默认值** | **说明** |
2954
| --- | --- | --- | --- | --- |
30-
| Mode | string || custom | custom 或 JSON |
31-
| StartPattern | string | 当 Mode=custom 时至少填一项 || 行首正则 |
32-
| ContinuePattern | string | || 行续正则 |
33-
| EndPattern | string | || 行尾正则 |
34-
| UnmatchedContentTreatment | string || single_line | discard 或 single_line |
55+
| Mode | string || custom | 多行聚合模式。可选值包括custom和JSON。 |
56+
| StartPattern | string | 当Multiline.Mode取值为custom时,至少1个必填 || 行首正则表达式。 |
57+
| ContinuePattern | string | || 行继续正则表达式。 |
58+
| EndPattern | string | || 行尾正则表达式。 |
59+
| UnmatchedContentTreatment | string || single_line | 对于无法匹配的日志段的处理方式,可选值如下:<ul><li>discard:丢弃</li><li>single_line:将不匹配日志段的每一行各自存放在一个单独的事件中</li></ul> |
60+
61+
62+
63+
## 使用场景
64+
65+
### 历史文件采集
66+
- **日志归档**:将历史日志文件批量采集到新的存储系统
67+
- **数据备份**:对重要历史数据进行备份采集
68+
- **合规审计**:满足数据保留和审计要求
69+
70+
### 数据迁移与处理
71+
- **数据迁移**:将数据从旧系统迁移到新系统
72+
- **数据分析**:对数据进行批量分析处理
73+
- **数据清洗**:对数据进行格式化和清洗
74+
- **数据转换**:将数据转换为新的格式
75+
76+
### 临时采集任务
77+
- **一次性采集**:执行临时的一次性数据采集任务
78+
- **测试验证**:用于测试和验证采集配置
3579

36-
注意:如果配置发生变化将重置文件集合和读取进度,重启开始一次性采集任务;配置启用后,文件集合会在启动阶段计算并读取,后续新增文件不会纳入集合。
3780

3881
## 样例
3982

83+
### 基础历史文件采集
84+
85+
采集 `/var/log/history `目录下所有 `.log `文件,并将结果输出至stdout。
86+
87+
**配置文件位置**`/opt/loongcollector/conf/onetime_pipeline_config/local/historical_logs.yaml`
88+
4089
```yaml
90+
enable: true
91+
global:
92+
ExcutionTimeout: 3600 # 1小时超时
4193
inputs:
4294
- Type: input_static_file_onetime
43-
FilePaths:
44-
- /data/log/**/*.log
95+
FilePaths:
96+
- /var/log/history/*.log
97+
flushers:
98+
- Type: flusher_stdout
99+
OnlyStdout: true
100+
Tags: true
101+
```
102+
103+
### 递归目录搜索
104+
105+
采集 `/var/log/archive `目录下所有子目录中的 `.log `文件,最大搜索深度为5层。
106+
107+
```yaml
108+
enable: true
109+
global:
110+
ExcutionTimeout: 7200 # 2小时超时
111+
inputs:
112+
- Type: input_static_file_onetime
113+
FilePaths:
114+
- /var/log/archive/**/*.log
45115
MaxDirSearchDepth: 5
116+
flushers:
117+
- Type: flusher_stdout
118+
OnlyStdout: true
119+
Tags: true
120+
```
121+
122+
123+
124+
### 多行日志处理
125+
126+
采集包含多行日志的历史文件,使用正则表达式进行日志聚合。
127+
128+
```yaml
129+
enable: true
130+
global:
131+
ExcutionTimeout: 1800 # 30分钟超时
132+
inputs:
133+
- Type: input_static_file_onetime
134+
FilePaths:
135+
- /var/log/history/*.log
46136
Multiline:
47-
StartPattern: ^\d{4}-\d{2}-\d{2} .*
137+
StartPattern: ^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}
138+
UnmatchedContentTreatment: single_line
139+
flushers:
140+
- Type: flusher_stdout
141+
OnlyStdout: true
142+
Tags: true
48143
```
144+
145+
### 文件过滤配置
146+
147+
采集时排除特定文件和目录。
148+
149+
```yaml
150+
enable: true
151+
global:
152+
ExcutionTimeout: 600 # 10分钟超时
153+
inputs:
154+
- Type: input_static_file_onetime
155+
FilePaths:
156+
- /var/log/**/*.log
157+
ExcludeFiles:
158+
- "*.tmp"
159+
- "*.bak"
160+
ExcludeDirs:
161+
- "/var/log/temp"
162+
- "/var/log/backup"
163+
flushers:
164+
- Type: flusher_stdout
165+
OnlyStdout: true
166+
Tags: true
167+
```
168+
169+
## 性能优化建议
170+
171+
### 文件路径优化
172+
- 使用精确的文件路径匹配,避免过于宽泛的通配符
173+
- 合理设置 `MaxDirSearchDepth `,避免过深的目录搜索
174+
- 使用黑名单过滤不需要的文件,减少处理开销
175+
176+
### 内存管理
177+
- 对于大文件,考虑分批处理
178+
- 合理配置多行日志聚合参数,避免内存溢出
179+
- 监控采集过程中的内存使用情况
180+
181+
### 并发控制
182+
- 根据系统资源情况调整并发处理数量
183+
- 避免同时处理过多大文件
184+
- 合理设置超时参数
185+
186+
## OneTime配置限制与注意事项
187+
188+
### 执行时机与超时机制
189+
1. **执行时机**:OneTime配置在LoongCollector启动时立即执行,不会等待其他条件
190+
2. **超时时间**:必须在global配置中设置`ExcutionTimeout`参数,取值范围:600~604800秒(10分钟~1周)
191+
3. **自动过期**:超过超时时间后,配置将自动过期并被删除,不会重复执行
192+
4. **状态管理**:系统会记录配置的执行状态,避免重复执行相同的配置
193+
194+
### 配置要求
195+
1. **全局配置**:必须在global配置中设置`ExcutionTimeout`参数,否则配置不会生效
196+
2. **配置文件位置**:OneTime配置文件必须放在指定目录下才能被LoongCollector识别
197+
3. **文件完整性**:确保在采集过程中文件不会被修改或删除
198+
4. **权限要求**:确保LoongCollector有足够的文件读取权限
199+
5. **资源消耗**:大量文件采集时注意系统资源使用情况
200+
201+
### 配置文件存放目录
202+
OneTime配置文件必须放在以下目录中:
203+
204+
**默认配置目录**:
205+
- 路径:`{LoongCollector安装目录}/conf/onetime_pipeline_config/local/`
206+
- 例如:`/opt/loongcollector/conf/onetime_pipeline_config/local/`
207+
208+
**自定义配置目录**:
209+
- 可通过环境变量`LOONG_CONF_DIR`自定义配置目录
210+
- 实际路径:`{LOONG_CONF_DIR}/onetime_pipeline_config/local/`
211+
212+
**配置文件命名**:
213+
- 支持`.yaml`和`.json`格式
214+
- 建议使用有意义的文件名,如`historical_log_collection.yaml`
215+
216+
### 使用限制
217+
1. **一次性执行**:每个OneTime配置只能执行一次,执行完成后自动停止
218+
2. **配置隔离**:OneTime配置与常规持续配置完全隔离,不会相互影响
219+
3. **文件发现**:启动时一次性发现所有匹配文件,不会动态监控新文件
220+
4. **错误处理**:执行过程中出现错误不会自动重试,需要重新部署配置
221+
222+
## 与input_file的区别
223+
224+
| 特性 | input_static_file_onetime | input_file |
225+
| --- | --- | --- |
226+
| 执行模式 | OneTime(一次性) | Continuous(持续) |
227+
| 适用场景 | 历史文件批量采集 | 实时日志监控 |
228+
| 资源占用 | 临时占用,采集完成后释放 | 持续占用,长期监控 |
229+
| 文件发现 | 启动时一次性发现所有文件 | 持续监控文件变化 |
230+
| 性能特点 | 批量处理,适合大量文件 | 实时处理,适合持续监控 |
231+
232+
通过合理使用`input_static_file_onetime`插件,可以高效地完成一次性文件采集任务,为历史文件采集、数据迁移、备份和分析提供强有力的支持。

docs/cn/plugins/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| 名称 | 提供方 | 简介 |
88
| ---------------------------------------------------------------------------------------------- | -------- | ------------------------------------- |
99
| `input_file`<br>[文本日志](input/native/input-file.md) | SLS 官方 | 文本采集。 |
10+
| `input_static_file_onetime`<br>[一次性文件采集](input/native/input-static-file-onetime.md) | SLS 官方 | 一次性文件采集。 |
1011
| `input_container_stdio`<br>[容器标准输出](input/native/input-container-stdio.md) | SLS 官方 | 从容器标准输出/标准错误流中采集日志。 |
1112
| `input_file_security`<br>[eBPF 文件安全数据](input/native/input-file-security.md) | SLS 官方 | eBPF 文件安全数据采集。 |
1213
| `input_network_observer`<br>[eBPF 网络可观测数据](input/native/input-network-observer.md) | SLS 官方 | eBPF 网络可观测数据采集。 |

docs/cn/plugins/processor/processors.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
| 输入插件 | 说明 |
5252
|---------|------|
5353
| [`input_file`](../input/native/input-file.md) | 文本日志输入插件 |
54+
| [`input_static_file_onetime`](../input/native/input-static-file-onetime.md) | 一次性文件采集插件 |
5455
| [`input_container_stdio`](../input/native/input-container-stdio.md) | 容器标准输出插件 |
5556
| [`input_observer_network`](../input/native/metric-observer.md) | eBPF网络观测插件 |
5657
| [`input_file_security`](../input/native/input-file-security.md) | 文件安全监控插件 |

0 commit comments

Comments
 (0)