packetbeat网络流量分析
安装部署
# yum install libpcap
# rpm -ivh http://www.nmon.net/packages/rpm6/x86_64/PF_RING/pfring-6.1.1-83.x86_64.rpm
# rpm -ivh https://download.elasticsearch.org/beats/packetbeat/packetbeat-5.0.0-x86_64.rpm# curl -XPUT 'http://localhost:9200/_template/packetbeat' -d@/etc/packetbeat/packetbeat.template.json配置示例
interfaces:
device: any
type: af_packet
snaplen: 65536 # 保证大过 MTU 即可,所以公网抓包的话可以改成 1514
buffer_size_mb: 30 # 该参数仅在 af_packet 时有效,表示在 linux 内核空间和用户空间之间开启多大共享内存,可以减低 CPU 消耗
with_vlans: false # 在生成抓包语句的时候,是否带上 vlan 标示。示例:"port 80 or port 3306 or (vlan and (port 80 or port 3306))"
protocols:
dns:
ports: [53]
send_request: false # 通用配置:是否将原始的 request 字段内容都发给 ES
send_response: false # 通用配置:是否将原始的 response 字段内容都发给 ES
transaction_timeout: "10s" # 通用配置:超过 10 秒的不再等待响应,直接认定为一个事务,发送给 ES
include_additionals: false # DNS 专属配置:是否带上 dns.additionals 字段
include_authorities: false # DNS 专属配置:是否带上 dns.authority 字段
http:
ports: [80, 8080] # 抓包的监听端口
hide_keywords: ["password","passwd"] # 对 GET 方法的请求参数,POST 方法的顶层参数里的指定关键信息脱敏。注意:如果你又开启了 send_request,request 字段里的并不会脱敏"
redact_authorization: true # 对 header 中的 Authorization 和 Proxy-Authorization 内容做模糊处理。道理和上一条类似
send_headers: ["User-Agent"] # 只在 headers 对象里记录指定的 header 字段内容
send_all_headers: true # 在 headers 对象里记录所有 header 字段内容
include_body_for: ["text/html"] # 在开启 send_response 的前提下,只记录某些类别的响应体内容
split_cookie: true # 将 headers 对象里的 Cookie 或 Set-Cookie 字段内容再继续做 KV 切割
real_ip_header: "X-Forwarded-For" # 将 headers 对象里的指定字段内容设为 client_location 和 real_ip 字段
memcache:
ports: [11211]
parseunknown: false
maxvalues: 0
maxbytespervalue: 100
udptransactiontimeout: 10000
mysql:
ports: [3306]
max_rows: 10 # 发送给 ES 的 SQL 内容最多为 10 行
max_row_length: 1024 # 发送给 ES 的 SQL 内容每行最长为 1024 字节
cassandra:
send_request_header: true # 在开启了 send_request 的前提下,记录 cassandra_request.request_headers 字段
send_response_header: true
compressor: "snappy"
ignored_ops: ["SUPPORTED","OPTIONS"] # 不记录部分操作
amqp:
ports: [5672]
max_body_length: 1000 # 超长的都截断掉
parse_headers: true
parse_arguments: false
hide_connection_information: true # 不记录打开、关闭连接之类的信息
thrift:
transport_type: socket # Thrift 传输类型,"socket" 或 "framed"
protocol_type: binary
idl_files: ["shared.thrift"] # 一般来说默认内置的 IDL 文件已经足够了
string_max_size: 200 # 参数或返回值中字符串的最大长度,超长的都截断掉
collection_max_size: 15 # Thrift 的 list, map, set, structure 结构中的元素个数上限,超过的元素丢弃
capture_reply: true # 为了节省资源,可以设置 false,只解析响应中的方法名称,其余信息丢弃
obfuscate_strings: true # 把所有方法参数、返回码、异常结构中的字符串都用 * 代替
drop_after_n_struct_fields: 500 # 在 packetbeat 结束整个事务之前,一个结构体最多能存多少个字段。该配置主要考虑节约内存
monogodb:
max_docs: 10 # 设置 send_response 前提下,response 字段最多保存多少个文档。超长的都截断掉。不限则设为 0
max_doc_length: 5000 # response 字段里每个文档的最大字节数。超长截断。不限则设为 0
procs:
enabled: true
monitored:
- process: mysqld
cmdline_grep: mysqld
- process: app # 设置发送给 ES 的数据中进程名字段的内容
cmdline_grep: gunicorn # 从 /proc/<pid>/cmdline 中过滤实际进程名的字符串
output:
...字段
dashboard 效果
Kibana3 topology

小贴士

Last updated

