Skip to content

Commit

Permalink
# 负载Load 优化,并且支持CentOS6系统
Browse files Browse the repository at this point in the history
  • Loading branch information
Toyo authored Oct 12, 2017
1 parent 0524231 commit 5191d71
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion clients/client-linux.py
Original file line number Diff line number Diff line change
@@ -55,7 +55,15 @@ def get_hdd():
return int(size), int(used)

def get_load():
tmp_load = os.popen("netstat -anp |grep ESTABLISHED |grep python |grep tcp6 |awk '{print $5}' |awk -F ':' '{print $1}' |sort -u |wc -l").read()
system = platform.linux_distribution()
if system[0][:6] == "CentOS":
if system[1][0] == "6":
tmp_load = os.popen("netstat -anp |grep ESTABLISHED |grep tcp |grep '::ffff:' |awk '{print $5}' |awk -F ':' '{print $4}' |sort -u |wc -l").read()
else:
tmp_load = os.popen("netstat -anp |grep ESTABLISHED |grep tcp6 |awk '{print $5}' |awk -F ':' '{print $1}' |sort -u |wc -l").read()
else:
tmp_load = os.popen("netstat -anp |grep ESTABLISHED |grep tcp6 |awk '{print $5}' |awk -F ':' '{print $1}' |sort -u |wc -l").read()

return float(tmp_load)
#return os.getloadavg()[0]

0 comments on commit 5191d71

Please sign in to comment.