Packetbeat 是一个实时网络数据包分析工具,与elasticsearch一体来提供应用程序的监控和分析系统。
Packetbeat通过嗅探应用服务器之间的网络通讯,来解码应用层协议类型如HTTP、MySQL、redis等等,关联请求与响应,并记录每个事务有意义的字段。
Packetbeat可以帮助我们快速发现后端应用程序的问题,如bug或性能问题等等,修复排除故障也很快捷。
Packetbeat目前支持的协议有:
HTTP
MySQL
PostgreSQL
Redis
Thrift-RPC
DNS
Packetbeat可以将相关事务直接插入到elasticsearch或redis(不推荐)或logstash。
Packetbeat可以运行在应用服务器上或者独自的服务器。当运行在独自服务器上时,需要从交换机的镜像端口或者窃听设备上获取网络流量。
对第七层信息解码后,Packetbeat关联与请求相关的响应,称之为事务。每个事务,Packetbeat插入一个json格式文档到elasticsearch。然后可通过kibana进行分析展示。
安装
先配置beats yum 源,参见前文。
# yum install packetbeat
1
# yum install packetbeat
配置
选择要从哪个网卡嗅探网络通讯,默认是所有的网络接口。
interfaces:
# Select on which network interfaces to sniff. You can use the "any"
# keyword to sniff on all connected interfaces.
device: any
1
2
3
4
interfaces:
# Select on which network interfaces to sniff. You can use the "any"
# keyword to sniff on all connected interfaces.
device:any
在协议部分,配置端口以便Packetbeat找到每个端口对应的协议。如果使用非标准端口,需要添加上。多个端口以逗号分隔。
protocols:
# Configure which protocols to monitor and on which ports are they
# running. You can disable a given protocol by commenting out its
# configuration.
http:
ports: [80, 8080, 8081, 5000, 8002]
memcache:
ports: [11211]
mysql:
ports: [3306]
redis:
ports: [6379]
pgsql:
ports: [5432]