Skip to content

Commit e2a8537

Browse files
committed
add: netstat connection monitor script.
1 parent 4e60c95 commit e2a8537

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

monitor_server/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python
2+
# -*- coding:utf-8 -*-
3+
__author__ = 'MFC'
4+
__time__ = '18/11/26 15:51'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
# -*- coding:utf-8 -*-
3+
__author__ = 'MFC'
4+
__time__ = '18/11/26 15:52'
5+
6+
import time
7+
import os
8+
9+
"""
10+
脚本: 监控服务器连接状态
11+
12+
usage:
13+
In terminal:
14+
python netstat_connection.py
15+
16+
end:
17+
Ctrl + C
18+
19+
### 查看并发连接数
20+
#### netstat -nat|grep ESTABLISHED|wc -l
21+
22+
### 查看其他类型连接数
23+
#### netstat -nat|grep CLOSE_WAIT|wc -l
24+
"""
25+
26+
while True:
27+
time.sleep(0.5) # 单位:秒
28+
os.system("clear")
29+
os.system("netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'")

0 commit comments

Comments
 (0)