zoukankan      html  css  js  c++  java
  • filebeat

    参考:
    【1】filebeat 配置文件详解https://blog.csdn.net/chengxuyuanyonghu/article/details/54378778
    【2】ELK-filebeat 采集配置与实现https://blog.csdn.net/fd2025/article/details/80289499

    一、Filebeat简介
    Filebeat是本地文件的日志数据采集器,可监控日志目录或特定日志文件(tail file),并将它们转发给Elasticsearch或Logstatsh进行索引、kafka等。带有内部模块(auditd,Apache,Nginx,System和MySQL),可通过一个指定命令来简化通用日志格式的收集,解析和可视化。

    二、安装使用(windows和linux安装包)
    1.下载并解压filebeat
    下载地址:https://www.elastic.co/cn/downloads/beats/filebeat

    2.编辑配置文件filebeat.yml
    filebeat 配置
    采用YAML语言作为其配置语法。它的基本语法规则如下:

    大小写敏感
    使用缩进表示层级关系
    缩进时不允许使用Tab键,只允许使用空格
    缩进的空格数据不重要,只要相同层级的元素左侧对齐即可

    # ============================== Filebeat inputs ===============================
    filebeat.config.inputs:
      enable: true
      path: ${path.config}/input.yml
      reload.enabled: true
      reload.period: 2s
    
    # ============================== Filebeat modules ==============================
    
    filebeat.config.modules:
      path: ${path.config}/modules.d/*.yml
      reload.enabled: true
      reload.period: 10s
    
    # ======================= Elasticsearch template setting =======================
    
    setup.template.settings:
      index.number_of_shards: 3
      index.number_of_replicas: 1
      
    # 允许自动生成index模板
    setup.template.enabled: true
    # # 生成index模板时字段配置文件
    setup.template.fields: fields.yml
    # # 如果存在模块则覆盖
    setup.template.overwrite: true
    # # 生成index模板的名称
    setup.template.name: "ops_log" 
    # # 生成index模板匹配的index格式 
    setup.template.pattern: "ops-*" 
    #索引生命周期管理ilm功能默认开启,开启的情况下索引名称只能为filebeat-*, 通过setup.ilm.enabled: false进行关闭;
    setup.ilm.pattern: "{now/d}"
    setup.ilm.enabled: false
    # ================================== General ===================================
    
    # ---------------------------- Elasticsearch Output ----------------------------
    output.elasticsearch:
      # Array of hosts to connect to.
      hosts: ["localhost:9200"]
      index: "%{[fields.source]}-*"
      indices:
        - index: "ops-systemlog-%{+yyyy.MM.dd}"
          when.equals: 
            fields: 
              source: "ops-systemlog"
        #- index: "opslog-operationlog-%{+yyyy.MM.dd}"
        - index: "ops-operationlog-%{+yyyy.MM.dd}"
          when.equals:
            fields:
              #source: "operationlog"
              source: "ops-operationlog"
    
    # ================================= Processors =================================
    processors:
      #...
      - script:
          lang: javascript
          id: my_filter
          tag: enable
          source: >
            function process(event) {
                //提取时间值
                var str= event.Get("message");
                var time =str.split(" ").slice(0,2).join(" ");
                event.Put("start_time",time);
            }
     
      - timestamp:
          # 格式化时间值 给 时间戳 
          field: start_time
          layouts:
            - '2006-01-02 15:04:05'
            - '2006-01-02 15:04:05.999'
          test:
            - '2019-06-22 16:33:51'

    input.yml

    #filebeat.input:
    - type: log
    
      # Change to true to enable this input configuration.
      enabled: true
    
      # Paths that should be crawled and fetched. Glob based paths.
      paths:
        - E:junxueELK_demo03demo01system*.txt
      tags: "c7f1771f-0c8f-4c75-9d71-3b8c4b6bd191"
      fields: 
        source: ops-systemlog
       #tags: ["GUID"]
        #- /var/log/*.log
        #- c:programdataelasticsearchlogs*
      #include_l ines: ['^ERROR']
        
    - type: log
      enabled: true
      paths: 
        - E:junxueELK_demo03demo02operation*.txt
        #- E:junxueELK_demo02demo02junxue*.txt
      tags: "c7f1771f-0c8f-4c75-9d71-3b8c4b6bd190"
      fields: 
        #source: operationlog
        source: ops-operationlog

    3.启动

    linux

    sudo ./filebeat -e -c filebeat.yml

    window

    .filebeat.exe -e -c filebeat.yml

    三、配置文件详细说明

    filebeat:
      # List of prospectors to fetch data.
      prospectors:
     
          # 指定要监控的日志,可以指定具体得文件或者目录
          paths:
            - /var/log/*.log  (这是默认的)(自行可以修改)(比如我放在/home/hadoop/app.log里)
            #- c:programdataelasticsearchlogs*
          # 指定被监控的文件的编码类型,使用plain和utf-8都是可以处理中文日志的
          #encoding: plain
          # 指定文件的输入类型log(默认)或者stdin
          input_type: log   
          # 排除指定符合正则表达式的行 DEBUG TRACE INFO
          # exclude_lines: ["^DBG"]
          # 包含输入中符合正则表达式列表的那些行(默认包含所有行),include_lines执行完毕之后会执行exclude_lines
          # include_lines: ["^ERR", "^WARN"]
          # Exclude files. A list of regular expressions to match. Filebeat drops the files that
          # are matching any regular expression from the list. By default, no files are dropped.
          # 忽略掉符合正则表达式列表的文件
          # exclude_files: [".gz$"]
          # 这个得意思就是会在es中多添加一个字段,格式为 "filelds":{"level":"debug"}
          #fields:
          #  level: debug
          #  review: 1
          # true/false 额外字段是否存放至根目录
          #fields_under_root: false   
          # 设定Elasticsearch输出时的document的type字段 可以用来给日志进行分类。Default: log
          #document_type: log
          # Filebeat以多快的频率去prospector指定的目录下面检测文件更新(比如是否有新增文件)
          # 如果设置为0s,则Filebeat会尽可能快地感知更新(占用的CPU会变高)。默认是10s
          #scan_frequency: 10s
     
          # 每个harvester监控文件时,使用的buffer的大小
          #harvester_buffer_size: 16384
     
          # 日志文件中增加一行算一个日志事件,max_bytes限制在一次日志事件中最多上传的字节数,多出的字节会被丢弃
          #max_bytes: 10485760
          #如果json 为多⾏格式时,指定⼀个root key,以进⾏标识
          #json.message_key:
           
           #false/true是否覆盖beat中的字段
           #json.overwrite_keys:false
           
           #false/true 解析失败时是否存储解析失败信息
           #json.add_error_key:false
  • 相关阅读:
    入门MySQL——基础语句篇
    装饰者模式
    (19)IO流之字符流FileReader和FileWriter,缓冲字符流---缓冲输入字符流BufferedReader和缓冲输出字符流BufferedWriter
    (18)IO流之字节缓冲路
    (17)IO中的异常处理
    (16)IO流之输入字节流FileInputStream和输出字节流FielOutputStream
    (15)IO流之File
    (14)jdk1.5开始的一些新特性:静态导入,增强for循环,可变参数,自动装箱/拆箱,枚举类型
    (13)正则表达式
    (12)泛型
  • 原文地址:https://www.cnblogs.com/dhName/p/15496231.html
Copyright © 2011-2022 走看看