一、流量的统计
在不修改源代码的情况下对程序暴露端口流量进行监控统计,可以利用Linux中自带的Iptable添加简单的规则让其起到端口流量统计的作用。
添加需要统计的端口
1、输入监控
iptables -A INPUT -p tcp --dport 8080
2、输出监控
iptables -A OUTPUT -p tcp --sport 8080
查看统计数据
iptables -L -v -n -x
示例结果:
8080端口接收的流量为2885字节,发送的流量是8240字节
Chain INPUT (policy ACCEPT 202 packets, 25187 bytes)
pkts bytes target prot opt in out source destinat