一个轻量级的基于golang开发的数据传输者,用于收集数据常用的beat有下:
数据扭转可能的示例如下
beats【收集数据】 =》 elasticsearch【存储,Ingest Node处理】=》kibana【可视化分析】
beats【收集数据】 =》 logstash【数据处理过滤】=》elasticsearch【存储,Ingest Node处理】=》kibana【可视化分析】
ingest node是elasticsearch的一种节点类型【选举节点、协调节点、数据节点】。可以在数据存储到ES之前对数据进行处理。
默认情况下所有节点都已启用此功能,也可通过node.ingest:false关闭
####################################### 创建Pipeline #######################################
PUT _ingest/pipeline/test
{
  "description": "This is a test pipeline",
  "processors": [
    {
      "set": {
        "field": "custom_field",
        "value": "custom_value"
      }
    },
    {
      "convert": {
        "field": "age",
        "type": "integer"
      }
    }
  ],
  "version": 1
}
##################################### 删除、查询Pipeline #####################################
DELETE _ingest/pipeline/test
GET _ingest/pipeline/test
##################################### 模拟测试Pipeline #####################################
POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "description": "This is a test pipeline",
    "processors": [
      {
        "set": {
          "field": "custom_field",
          "value": "custom_value"
        },
        "geoip":{
          "field": "ip",
          "target_field": "ip_info"
        },
        "user_agent": {
          "field": "agent",
          "target_field": "user_ua"
        },
        "convert": {
          "field": "age",
          "type": "integer",
          "on_failure": [
            {
              "set": {
                "field": "age_conver_error",
                "value": ""
              }
            }
          ]
        }
      }
    ],
    "version": 1
  },
  "docs": [
    {
      "_source": {
        "message": "m m m m m ",
        "age": "xxx18",
        "ip":"124.207.37.189",
        "agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"
      }
    }
  ]
}
POST _ingest/pipeline/test/_simulate
{
  "docs": [
    {
      "_source": {
        "message": "m m m m m "
      }
    }
  ]
}
Pipeline的processors基本上和logstash的filter一一对应
Filebeat是用于转发和集中日志数据的轻量级传送程序,特性有下
filebeat.inputs:
- type: log                 #type的类型有:Log、Stdin、Redis、UDP、Docker、TCP、Syslog、NetFlow
  paths:                    #文件的位置
    - "/var/log/nginx/*"
  encoding: utf-8           #文件编目
  tags: ["txt","web"]       #添加的自定义标签
  fields:                   #添加的自定义字段
    apache: true
  fields_under_root: true   #解析出来的字段是否放在根下,否则在field下
  
output.elasticsearch:       #输出到的es地址,output只能有一个,调试可以启动时用用 -d "publish" 打印
  hosts: ["localhost:9200"]
  
setup.kibana:               #kibana地址,用于导入Dashboard
  host: "localhost:5601"
如果仅使用一次不建议在Filebeat中创建,可直接在elasticsearch中创建
#是否启用template
setup.template.enable: false
#是否每次beats启动就要覆盖以前的template定义
setup.template.overwrite: true
#要向elasticsearch中的创建的template名称
setup.template.name: "nginx"
#要向elasticsearch中的创建的template的pattern
setup.template.pattern: "nginx-*"
#要向elasticsearch中的创建的template的mapping信息
setup.template.fields: "nginx_filed.yml"
可以通过配置打开Dashboard也可以通过命令导入./filebeat setup --dashboards,都是一次性全部导入
#向kibana创建的Dashboard的index名称
setup.dashboards.index: "nginx-*"
#是否启用Dashboard,默认false
setup.dashboards.enabled: true
./filebeat export config     #查看当前配置文件的详细定义
./filebeat export template   #查看当前配置文件使用的template的详细定义
./filebeat export template -E setup.template.fields=nginx_field.yml  #查看指定的template的详细定义
可以通过
./filebeat -e -c filebeat.yml -d "publish"执行时看到详细信息-e:输出到stderr,默认输出到logs/filebeat文件
-d “publish”:输出”publish”的相关日志信息
./filebeat modules list./filebeat modules enable nginx./filebeat modules disable nginxnohup ./filebeat -e -c filebeat.yml -d "publish" &metricbeat用于定期收集操作系统、软件服务的指标数据。存入elasticsearch用于记录度量和聚合数据,具有计划性
./metricbeat modules list./metricbeat modules enable system./metricbeat modules disable systemmetricbeat.yml配置output和Dashboard./metricbeat setup --dashboardsmetricsets和调整收集时间间隔nohup ./metricbeat -e -c metricbeat.yml -d "publish" &用于抓取网络包数据,可以自动解析网络包协议例如ICMP DNS、HTTP、Mysql/PgSQL/MongoDB、Memcache、Thrift、TLS等
packetbeat抓包配置有两种
packetbeat.yml配置output和Dashboardpacketbeat.yml各个模块的参数信息./packetbeat setup --dashboardsnohup ./packetbeat -e -c packetbeat.yml -d "publish" &【注意网卡权限,不行需要用root用户执行】做心跳检测,判断对方是否存活
heartbeat.yml配置output和Dashboardheartbeat.yml各个程序需要的协议./heartbeat setup --dashboardsnohup ./heartbeat -e -c heartbeat.yml -d "publish" &更多社区beat查看链接