当前位置:网站首页>【tcp】服务器上tcp连接状态json形式输出
【tcp】服务器上tcp连接状态json形式输出
2022-07-05 10:18:00 【HunterMichaelG】
print_tcp_conection.sh
#!/bin/bash
STATS=(UNKNOWN:0 ESTABLISHED:0 SYN_SENT:0 SYN_RECV:0 FIN_WAIT1:0 FIN_WAIT2:0 TIME_WAIT:0 CLOSED:0 CLOSE_WAIT:0 LAST_ACK:0 LISTEN:0 CLOSING:0)
CONN="$(awk '{print $4}' /proc/net/tcp /proc/net/tcp6 | grep -v st | sort | uniq -c | sed -e s/' 0'/' '/g -e s/'A'/'10'/g -e s/'B'/'11'/g | awk '{print $2":"$1}')"
if [ ! -z "$CONN" ];then
for s in $CONN
do
STATS[${s%%:*}]=${STATS[${s%%:*}]%%:*}":"${s#*:}
done
fi
echo ${STATS[@]} | sed -e s/' '/',"'/g -e s/':'/'":'/g -e s/^/'{"tcp_conn":{"'/g -e s/'WAIT_'/'WAIT'/g -e s/'$'/'}}'/g
# sh print_tcp_conection.sh
{"tcp_conn":{"UNKNOWN":0,"ESTABLISHED":4,"SYN_SENT":0,"SYN_RECV":0,"FIN_WAIT1":0,"FIN_WAIT2":0,"TIME_WAIT":0,"CLOSED":0,"CLOSE_WAIT":0,"LAST_ACK":0,"LISTEN":6,"CLOSING":0}}
# sh print_tcp_conection.sh | python -m json.tool
{
"tcp_conn": {
"CLOSED": 0,
"CLOSE_WAIT": 0,
"CLOSING": 0,
"ESTABLISHED": 4,
"FIN_WAIT1": 0,
"FIN_WAIT2": 0,
"LAST_ACK": 0,
"LISTEN": 6,
"SYN_RECV": 0,
"SYN_SENT": 0,
"TIME_WAIT": 0,
"UNKNOWN": 0
}
}
边栏推荐
- @JsonAdapter注解使用
- Write double click event
- Dedecms website building tutorial
- Customize the left sliding button in the line in the applet, which is similar to the QQ and Wx message interface
- NAS与SAN
- 横向滚动的RecycleView一屏显示五个半,低于五个平均分布
- IDEA新建sprintboot项目
- 手机厂商“互卷”之年:“机海战术”失灵,“慢节奏”打法崛起
- Learning note 4 -- Key Technologies of high-precision map (Part 2)
- Shortcut keys for vscode
猜你喜欢
Apple 5g chip research and development failure? It's too early to get rid of Qualcomm
How do programmers live as they like?
最全是一次I2C总结
Fluent generates icon prompt logo widget
《微信小程序-基础篇》小程序中的事件与冒泡
What is the origin of the domain knowledge network that drives the new idea of manufacturing industry upgrading?
Advanced opencv:bgr pixel intensity map
钉钉、企微、飞书学会赚钱了吗?
Ad20 make logo
Learning notes 5 - high precision map solution
随机推荐
Window下线程与线程同步总结
The horizontally scrolling recycleview displays five and a half on one screen, lower than the average distribution of five
如何判断线程池已经执行完所有任务了?
Workmanager learning 1
一个程序员的职业生涯到底该怎么规划?
TSQL–标示列、GUID 、序列
C#实现获取DevExpress中GridView表格进行过滤或排序后的数据
Learning note 4 -- Key Technologies of high-precision map (Part 2)
Detailed explanation of the use of staticlayout
How to plan the career of a programmer?
Redis如何实现多可用区?
SQL Server 监控统计阻塞脚本信息
小程序中自定义行内左滑按钮,类似于qq和wx消息界面那种
Zblogphp breadcrumb navigation code
Dedecms website building tutorial
C语言实现QQ聊天室小项目 [完整源码]
Error: module not found: error: can't resolve 'xxx' in 'XXXX‘
Have you learned to make money in Dingding, enterprise micro and Feishu?
Pseudo class elements -- before and after
Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born