fluentd 镜像构建与常用配置
目录
镜像
基础镜像
quay.io/fluentd_elasticsearch/fluentd:v2.9.0. 基础镜像 Dockerfile 项目地址
构建自己的镜像
|
|
配置
基本命令
配置文件主要由以下命令组成:
- source: 确定输入源
- match: 确定输出目标
- filter: 确定事件处理管道
- system: 设置系统范围的配置
- label: 对输出和内部过滤器进行分组路由
- include: 包含其他配置文件
输入插件
in_tail
in_tail 输入插件允许 Fluentd 从文本文件的尾部读取事件。它的行为类似于tail -F命令。
安装
内置插件,无需安装。
示例与参数
示例:
|
|
关键参数表:
名称 | 类型 | 默认 | 版本 | 说明 |
---|---|---|---|---|
@type | string | tail | 值必须是 tail | |
tag | string | required parameter | 0.14.0 | 事件的标签 |
path | string | required parameter | 0.14.0 | 读取路径,多个路径以',‘分隔 |
exclude_path | array | [] | 0.14.0 | 监听列表中排出文件的路径 |
refresh_interval | time | 60(seconds) | 0.14.0 | 刷新监视文件列表的间隔,当路径包含 * 时使用 |
read_from_head | bool | false | 0.14.0 | 从文件头而不是底部开始读取日志 |
read_lines_limit | integer | 1000 | 0.14.0 | 每次 IO 读取的行数 |
pos_file | string | nil | 0.14.0 | 强烈建议使用此参数,fluentd 会将其最后一次读取的位置记录到该文件中。一个源的多个位置可以记录在一个 pos_file 中。不要在多个 in_tail 输入源配置相同的 pos_file,这样会导致不可预知的错误。 |
指令 | required | 日志的格式,in_tail 使用解析器插件来解析当前日志。内置解析器见下表。 |
内置解析器:
- regexp
- apache2
- apache_error
- nginx
- syslog
- csv
- tsv
- ltsv
- json
- msgpack
- multiline
- none
fluent-plugin-systemd
systemd 输入插件从系统 journal 采集日志
安装
|
|
示例与参数
输入示例:
|
|
关键参数表:
名称 | 类型 | 默认 | 版本 | 说明 |
---|---|---|---|---|
@type | string | systemd | 值必须是 systemd | |
path | string | /var/log/journal | systemd journal 日志路径 | |
matches | array | 设置该配置项过滤出需要采集的日志,如 kernel 日志或特定 service 的日志 | ||
storage | plugin | 配置存储插件来存储 journald 游标 | ||
read_from_head | bool | false | true 表示从头开始读,否则从末尾读,如果 cursor 存在则忽略该配置 | |
entry | filter | 可以用来转换字段大小写,移除开头的下划线等 | ||
tag | string | required | 该输入源的事件添加标签 |
systemd filter 插件对 journal 日志进行处理
过滤示例:
|
|
过滤插件
fluent-plugin-kubernetes_metadata_filter
Kubernetes元数据插件过滤器使用pod和名称空间元数据丰富容器日志记录。
安装
|
|
示例与参数
配置示例:
|
|
输入示例:
|
|
输出示例:
|
|
关键参数表:
名称 | 类型 | 默认 | 说明 |
---|---|---|---|
@type | string | kubernetes_metadata | 必须为 kubernetes_metadata |
kubernetes_url | string | apiserver url,如果在 pod 里可以默认读取对应的环境变量 | |
apiVersion | string | v1 | 使用的 api 版本 |
ca_file | string | 用于Kubernetes服务器证书验证的CA文件的路径 | |
verify_ssl | bool | true | 验证SSL证书 |
client_cert | string | path to a client cert file to authenticate to the API server | |
client_key | string | path to a client key file to authenticate to the API server | |
tag_to_kubernetes_name_regexp | string | 用于从当前fluentd标签提取kubernetes元数据(pod名称,容器名称,名称空间)的正则表达式。 | |
cache_size | int | 1000 | k8s 元数据缓存大小,用来减少对API服务器的请求 |
cache_ttl | int | 3600 | 每个缓存元素的 TTL(单位为秒),负值表示禁用 TTL |
watch | bool | true | 监听 k8s 上的 pods 元数据更新 |
watch_retry_interval | int | 10 | 观察连接失败时,重试退避的时间间隔(以秒为单位)。 |
annotation_match | array | [] | 与 annotations 字段名称匹配的正则表达式数组。匹配的 annotation 将添加到日志记录。默认不采集 annotation 数据。 |
lookup_from_k8s_field | bool | true | 如果存在kubernetes字段,从给定的子字段中查找元数据,例如kubernetes.namespace_name,kubernetes.pod_name等。 |
skip_labels | bool | false | 不采集元数据里的所有标签字段 |
skip_container_metadata | bool | false | 跳过部分容器元数据的采集,不会跳过 container_image,container_image_id 字段。 |
skip_master_url | bool | false | 不采集元数据里的 master_url 字段 |
skip_namespace_metadata | bool | false | 从元数据中跳过namespace_id字段。 |
输出插件
fluent-plugin-elasticsearch
fluent-plugin-kafka
安装
|
|
input 示例与参数
示例:
|
|
关键参数表:
名称 | 类型 | 默认 | 说明 |
---|
output 示例与参数
示例:
|
|
关键参数表:
名称 | 类型 | 默认 | 说明 |
---|---|---|---|
topic_key | string | 日志记录的那个字段可以用来表示 topic | |
default_topic | string | 这个一定要设置 |
使用 fluent-plugin-prometheus插件监控
使用 prometheus 插件暴露 fluentd 的指标。
安装
|
|
使用
prometheus input plugin
必须配置该插件来暴露其他插件采集的指标
示例:
|
|
关键参数表:
名称 | 类型 | 默认 | 说明 |
---|---|---|---|
@type | string | 必须为 prometheus | |
bind | string | 0.0.0.0 | binding interface |
port | int | 24231 | 监听的端口 |
metrics_path | string | /metrics | metrics HTTP endpoint |
aggregated_metrics_path | string | /aggregated_metrics | 如果使用多个 woker 模式,每个 worker 监听 port+fluent_worker_id 端口,为了一次采集所有 worker 的数据,可以直接使用该地址采集 |
prometheus_monitor input plugin
该插件收集 fluentd 的内部指标。
示例:
|
|
关键参数表:
名称 | 类型 | 默认 | 说明 |
---|---|---|---|
labels | 额外的为该指标添加标签 | ||
interval | int | 5 | 更新monitor_agent信息的时间间隔(以秒为单位) |
采集的指标:
名称 | 类型 | 解释 |
---|---|---|
fluentd_status_buffer_queue_length | ||
fluentd_status_buffer_total_bytes | ||
fluentd_status_buffer_newest_timekey | ||
fluentd_status_buffer_oldest_timekey | ||
fluentd_status_retry_count |
prometheus_output_monitor input plugin
该插件收集Fluentd中输出插件的内部指标。跟 prometheus_monitor 相似,但专门用于输出插件。有很多 prometheus_monitor 不具备的指标,例如 num_errors, retry_wait 等。
示例:
|
|
关键参数表:
名称 | 类型 | 默认 | 说明 |
---|---|---|---|
labels | 额外的为该指标添加标签 | ||
interval | int | 5 | 更新monitor_agent信息的时间间隔(以秒为单位) |
采集的指标:
名称 | 类型 | input/output/buffer | 解释 |
---|---|---|---|
fluentd_output_status_retry_count | output | ||
fluentd_output_status_num_error | output | ||
fluentd_output_status_emit_count | output | ||
fluentd_output_status_retry_wait | output | ||
fluentd_output_status_emit_records | output | ||
fluentd_output_status_write_count | output | ||
fluentd_output_status_rollback_count | output | ||
fluentd_output_status_flush_time_count | output | ||
fluentd_output_status_slow_flush_count | output | ||
fluentd_output_status_buffer_total_bytes | buffer | ||
fluentd_output_status_buffer_stage_length | buffer | ||
fluentd_output_status_buffer_stage_byte_size | buffer | ||
fluentd_output_status_buffer_queue_length | buffer | ||
fluentd_output_status_buffer_queue_byte_size | buffer | ||
fluentd_output_status_buffer_newest_timekey | buffer | ||
fluentd_output_status_buffer_oldest_timekey | buffer | ||
fluentd_output_status_buffer_available_space_ratio | buffer |
prometheus_tail_monitor input plugin
该插件收集 fluentd 中 in_tail 插件的内部指标。
示例:
|
|
关键参数表:
名称 | 类型 | 默认 | 说明 |
---|---|---|---|
额外的为该指标添加标签 | |||
interval | int | 5 | 更新monitor_agent信息的时间间隔(以秒为单位) |
采集的指标:
名称 | 类型 | 解释 |
---|---|---|
fluentd_tail_file_position | 插件从文件读取的当前字节 | |
fluentd_tail_file_inode | 文件的 inode 值 |
指标默认包含的标签:
名称 | 解释 |
---|---|
plugin_id | 给插件配置的 @id 值 |
type | 插件名称。当前只支持 in_tail |
path | 文件路径 |
prometheus filter/output plugin
过滤/输出插件都从记录中检测指标,只需读取记录,不影响记录的值。
支持的指标类型
counter type
示例:
|
|
关键参数表:
名称 | required/optional | 说明 |
---|---|---|
name | required | 指标名称 |
type | required | 指标类型 |
desc | required | 指标描述 |
key | optional | 使用该键名对应的值计算 counter,若未设置或为空,counter 每次加 1 |
optional | 额外添加的标签 |
gauge type
示例:
|
|
关键参数表:
名称 | required/optional | 说明 |
---|---|---|
name | required | 指标名称 |
type | required | 指标类型 |
desc | required | 指标描述 |
key | required | 使用该键名对应的值作为 gauge 的值 |
optional | 额外添加的标签 |
summary type
示例:
|
|
关键参数表:
名称 | required/optional | 说明 |
---|---|---|
name | required | 指标名称 |
type | required | 指标类型 |
desc | required | 指标描述 |
key | required | 使用该键名对应的值作为 summary 的值 |
optional | 额外添加的标签 |
histogram type
示例:
|
|
关键参数表:
名称 | required/optional | 说明 |
---|---|---|
name | required | 指标名称 |
type | required | 指标类型 |
desc | required | 指标描述 |
key | required | 使用该键名对应的值作为指标的值 |
buckets | optional | buckets of record for instrumentation |
optional | 额外添加的标签 |
filter 配置示例
|
|
output 配置示例
|
|
配置面板
grafana 面板配置如下,支持多个数据源
|
|