filebeat.inputs type 类型详解

在 Filebeat 中,filebeat.inputs 是用于定义数据输入的配置部分,而 type 是每个输入配置中的一个关键字段,用于指定输入的类型。Filebeat 支持多种输入类型,每种类型适用于不同的数据源和场景。以下是常见的 type 类型及其详解:


1. log(默认类型)

  • 用途:从日志文件中收集数据。

  • 配置示例

    yaml
    复制
    filebeat.inputs:
    - type: log
      paths:
        - /var/log/*.log
  • 特点

    • 支持从本地文件系统读取日志文件。

    • 可以监控文件的变化(新增内容、文件轮转等)。

    • 支持多行日志合并(通过 multiline 配置)。


2. stdin

  • 用途:从标准输入(stdin)收集数据。

  • 配置示例

    yaml
    复制
    filebeat.inputs:
    - type: stdin
  • 特点

    • 适用于从管道或命令行输入数据。

    • 通常用于测试或与其他工具集成。


3. container

  • 用途:从容器日志中收集数据。

  • 配置示例

    yaml
    复制
    filebeat.inputs:
    - type: container
      paths:
        - /var/lib/docker/containers/*/*.log
  • 特点

    • 适用于 Docker 或其他容器运行时。

    • 支持解析容器日志的元数据(如容器 ID、镜像名称等)。


4. docker

  • 用途:从 Docker 容器日志中收集数据(旧版,推荐使用 container 类型)。

  • 配置示例

    yaml
    复制
    filebeat.inputs:
    - type: docker
      containers.ids:
        - "*"
  • 特点

    • 适用于 Docker 环境。

    • 支持通过容器 ID 或名称过滤日志。


5. syslog

  • 用途:从 Syslog 服务器收集日志数据。

  • 配置示例

    yaml
    复制
    filebeat.inputs:
    - type: syslog
      protocol.udp:
        host: "localhost:514"
  • 特点

    • 支持 UDP 和 TCP 协议。

    • 适用于从网络设备或服务器收集 Syslog 日志。


6. redis

  • 用途:从 Redis 的慢查询日志或监控日志中收集数据。

  • 配置示例

    yaml
    复制
    filebeat.inputs:
    - type: redis
      hosts: ["localhost:6379"]
      password: "your_password"
  • 特点

    • 支持从 Redis 服务器收集日志。

    • 需要配置 Redis 的连接信息。


7. udp

  • 用途:从 UDP 数据包中收集数据。

  • 配置示例

    yaml
    复制
    filebeat.inputs:
    - type: udp
      host: "localhost:5000"
  • 特点

    • 适用于从网络设备或应用程序接收 UDP 数据。

    • 需要指定监听的端口。


8. tcp

  • 用途:从 TCP 数据流中收集数据。

  • 配置示例

    yaml
    复制
    filebeat.inputs:
    - type: tcp
      host: "localhost:5000"
  • 特点

    • 适用于从网络设备或应用程序接收 TCP 数据。

    • 支持多行日志合并。


9. kafka

  • 用途:从 Kafka 主题中收集数据。

  • 配置示例

    yaml
    复制
    filebeat.inputs:
    - type: kafka
      hosts: ["localhost:9092"]
      topics: ["my_topic"]
  • 特点

    • 支持从 Kafka 消费数据。

    • 需要配置 Kafka 的连接信息和主题。


10. cloudfoundry

  • 用途:从 Cloud Foundry 应用程序日志中收集数据。

  • 配置示例

    yaml
    复制
    filebeat.inputs:
    - type: cloudfoundry
      api_address: "https://api.example.com"
      client_id: "your_client_id"
      client_secret: "your_client_secret"
  • 特点

    • 适用于 Cloud Foundry 平台。

    • 需要配置 API 地址和认证信息。


11. journald

  • 用途:从 systemd 的 journald 日志中收集数据。

  • 配置示例

    yaml
    复制
    filebeat.inputs:
    - type: journald
      paths:
        - /var/log/journal
  • 特点

    • 适用于 Linux 系统,收集 systemd 日志。

    • 支持过滤特定的日志单元或优先级。


12. s3

  • 用途:从 Amazon S3 存储桶中收集日志文件。

  • 配置示例

    yaml
    复制
    filebeat.inputs:
    - type: s3
      queue_url: "https://sqs.amazonaws.com/your-queue"
      bucket_arn: "arn:aws:s3:::your-bucket"
  • 特点

    • 适用于从 S3 存储桶中读取日志文件。

    • 需要配置 AWS 认证信息和 SQS 队列。


13. azure

  • 用途:从 Azure 存储或事件中心收集日志数据。

  • 配置示例

    yaml
    复制
    filebeat.inputs:
    - type: azure
      event_hub:
        connection_string: "your_connection_string"
  • 特点

    • 适用于 Azure 云环境。

    • 支持从 Azure Blob 存储或事件中心收集数据。


14. google-pubsub

  • 用途:从 Google Cloud Pub/Sub 中收集数据。

  • 配置示例

    yaml
    复制
    filebeat.inputs:
    - type: google-pubsub
      project_id: "your_project_id"
      subscription: "your_subscription"
  • 特点

    • 适用于 Google Cloud 环境。

    • 需要配置 Google Cloud 认证信息。


总结:

Filebeat 的 type 类型非常丰富,覆盖了从本地日志文件到云服务的多种数据源。选择合适的 type 可以高效地收集和处理数据。以下是一些常见场景的推荐类型:

  • 本地日志文件log

  • 容器日志container

  • 网络日志syslogudptcp

  • 云服务日志s3azuregoogle-pubsub

  • 消息队列kafka

inputs

log
sdtin

- type: stdin

redis slowlog

- type: redis
  enabled: true
  hosts: ["localhost:6379"]
  password: foobared

  ## How often the input checks for redis slow log.
  #scan_frequency: 10s

  ## Timeout after which time the input should return an error
  #timeout: 1s

  ## Network type to be used for redis connection. Default: tcp
  #network: tcp

  ## 最大并发连接数。默认值:10
  #maxconn: 10

udp

- type: udp
  enabled: true
  #host: 'localhost:8080'
  
  ##通过UDP接收的消息的最大大小 
  #max_message_size: 10KiB

  ##UDP读取缓冲区的大小(以字节为单位)
  #read_buffer: 0

tcp

- type: tcp
  enabled: true

  ## The host and port to receive the new event
  #host: "localhost:9000"

  ## Character used to split new message
  #line_delimiter: "\n"

  ##通过TCP接收消息的最大字节
  #max_message_size: 20MiB

  ##最大并发链接数,0表示无限制。默认:0
  #max_connections: 0

  ##多久关闭处于非活动状态的链接。
  #timeout: 300s

syslog

# Experimental: Config options for the Syslog input
# Accept RFC3164 formatted syslog event via UDP.
#- type: syslog
  #enabled: false
  #protocol.udp:
    # The host and port to receive the new event
    #host: "localhost:9000"

    # Maximum size of the message received over UDP
    #max_message_size: 10KiB

# Accept RFC3164 formatted syslog event via TCP.
#- type: syslog
  #enabled: false

  #protocol.tcp:
    # The host and port to receive the new event
    #host: "localhost:9000"

    # Character used to split new message
    #line_delimiter: "\n"

    # Maximum size in bytes of the message received over TCP
    #max_message_size: 20MiB

    # The number of seconds of inactivity before a remote connection is closed.
    #timeout: 300s

outputs

logstash

output.logstash:
  enabled: true
  hosts: ["127.0.0.1:5044"]

  # Number of workers per Logstash host.
  worker: 1

  # Optionally load-balance events between Logstash hosts. Default is false.
  #loadbalance: false

  # Number of batches to be sent asynchronously to Logstash while processing new batches.
  #pipelining: 2

  ##网络错误后尝试重新连接到Logstash之前等待的秒数。
  #backoff.init: 1s

  #网络错误后尝试连接到Logstash之前等待的最大秒数。默认值为60秒。
  #backoff.max: 60s

  ##可选索引名称。默认索引名设置为filebeat,全部小写。
  #index: 'filebeat'
  
  ##发布失败后重试发布事件的次数。
  #max_retries: 3

  ##单个Logstash请求中要批量处理的最大事件数。默认值为2048。
  #bulk_max_size: 2048

elasticsearch

output.elasticsearch:
  enabled: true
  hosts: ["localhost:9200"]

  ##协议 - either `http` (default) or `https`.
  #protocol: "https"

  ##身份验证凭据-API密钥或用户名/密码
  api_key: "id:api_key"
  username: "elastic"
  password: "changeme"
  
  ##通过索引操作在URL中传递的HTTP参数字典
  #parameters:
    #param1: value1
    #param2: value2

  # Number of workers per Elasticsearch host.
  #worker: 1

  ##可选索引名称。默认值是“filebeat”加上日期并生成[filebeat-]年月日。
  #index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"

  # Optional ingest node pipeline. By default no pipeline will be used.
  #pipeline: ""

  # Optional HTTP path
  #path: "/elasticsearch"

  ##要添加到每个请求的自定义HTTP头
  #headers:
  #  X-My-Header: Contents of the header

  ##尝试索引操作的重试次数。如果索引操作在多次重试后没有成功,则事件将被删除。默认值为3。
  #max_retries: 3

  #单个Elasticsearch批量API索引请求中要批量处理的最大事件数。默认值为50。
  #bulk_max_size: 50

  ##网络错误后尝试重新连接到Elasticsearch之前等待的秒数
  #backoff.init: 1s

  ##网络错误后尝试连接到Elasticsearch之前等待的最大秒数。默认值为60秒。
  #backoff.max: 60s

  ##在请求Elasticsearch失败之前配置HTTP请求超时。
  #timeout: 90

kafka
file

output.file:
  enabled: true
  codec.json:
    pretty: true 
    escape_html: true
  path: "/data/logs/filebeat"
  filename: filebeat_output.log
  rotate_every_kb: 10000
  number_of_files: 7
  permissions: 0600

redis

output.redis:
  enabled: true
  codec.json:
    pretty: false
    escape_html: false
  hosts: ["localhost:6379"]
  key: filebeat
  password: '*****'
  db: 0

  ##发布事件的Redis数据类型。如果数据类型为list,则使用RPUSH命令;如果数据类型为channel,则使用PUBLISH命令。默认值为list。
  datatype: list

  ##发布事件到每个Redis的工作线程数。将此设置与loadbalance选项一起使用。例如,如果有2台主机和3台工作机,则总共启动6台工作机(每个主机3台)。
  worker: 1

  #如果设置为true并且配置了多个hosts或worker,则会将发布的事件负载平衡到所有Redis主机上。
  #如果设置为false,则只向一个主机发送所有事件(随机确定),如果当前选定的主机无法访问,则将切换到另一个主机。
  #默认值为true
  loadbalance: true

  timeout: 5s
  ##发布失败后重试发布事件的次数。在指定的重试次数之后,通常会删除事件。
  max_retries: 3

  ##网络错误后等待多久尝试重新连接到Redis。
  backoff.init: 1s

  ##网络错误后尝试连接到Redis之前等待的最大秒数。默认值为60秒。
  #backoff.max: 60s

  #单个Redis请求或管道中要批量处理的最大事件数。默认值为2048。
  bulk_max_size: 2048

console

output.console:
  enabled: true
  codec.json:
    pretty: false
    escape_html: false

 

 

 

posted @   hanease  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
历史上的今天:
2022-02-26 SpringCloud(2)---入门篇
2022-02-26 SpringCloud(1)---入门篇
2022-02-26 分库分表(2) --- ShardingSphere(理论)
2022-02-26 分库分表(1) --- ShardingSphere(理论)
点击右上角即可分享
微信分享提示