psutil不能获取计算板网卡流量.

This commit is contained in:
lijia
2019-08-08 19:12:32 +08:00
parent 0f54e47ebc
commit d5f4683fcc
8 changed files with 71 additions and 38 deletions

View File

@@ -1,5 +1,5 @@
{
"local_chassis_node": "mcn_1",
"local_chassis_node": "mcn1",
"interface_list": [{
"dev_name": "eth0",
"dev_type": "marsio",
@@ -11,6 +11,6 @@
}, {
"dev_name": "lo",
"dev_type": "pcap",
"flow_type": "post"
"flow_type": "mirror"
}]
}

View File

@@ -2,27 +2,27 @@
"tsg_chassis_ip": [{
"type": "mxn",
"name": "mxn",
"id": 100,
"ip": "192.168.100.5"
}, {
"type": "mcn",
"name": "mcn1",
"id": 0,
"ip": "192.168.200.5"
"ip": "192.168.100.1"
}, {
"type": "mcn",
"name": "mcn_1",
"name": "mcn2",
"id": 1,
"ip": "192.168.200.1"
"ip": "192.168.100.2"
}, {
"type": "mcn",
"name": "mcn_2",
"name": "mcn3",
"id": 2,
"ip": "192.168.200.2"
"ip": "192.168.100.3"
}, {
"type": "mcn",
"name": "mcn_3",
"name": "mcn4",
"id": 3,
"ip": "192.168.200.3"
}, {
"type": "mcn",
"name": "mcn_4",
"id": 4,
"ip": "192.168.200.4"
"ip": "192.168.100.4"
}]
}

14
pkg.sh
View File

@@ -1,9 +1,7 @@
rm -rf ./py_temp/*
pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_src/tsg_software_reboot.py
pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_src/tsg_hardware_reboot.py
pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_src/tsg_diagnose.py
pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_src/tsg_monit_device.py
pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_src/tsg_monit_stream.py
pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_src/tsg_update_tags.py
pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_tools/tsg_iterate_interface_list.py
pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_cmd/tsg_software_reboot.py
pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_cmd/tsg_hardware_reboot.py
pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_cmd/tsg_diagnose.py
pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_tools/tsg_monit_interface.py
pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_tools/tsg_monit_stream.py
pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_tools/tsg_update_tags.py

View File

@@ -1,6 +1,8 @@
#coding=utf-8
import sys
import re
import syslog
import subprocess
##define KERN_EMERG "<0>" /* system is unusable */
##define KERN_ALERT "<1>" /* action must be taken immediately */
@@ -21,7 +23,8 @@ def system_cmd_run(cmd_str):
for cmd in dangerous_cmd:
pattern = "\s*%s" %(cmd)
if re.match(pattern, cmd_str) != "":
match_str = re.match(pattern, cmd_str)
if not match_str is None:
print("can't run this cmd:%s" %(cmd_str))
sys.exit(1)
@@ -30,23 +33,28 @@ def system_cmd_run(cmd_str):
except Exception as e:
#if exitcode != 0:
# output = ""
return 1, e.message
print(e)
return 1, e
return exitcode, output
def tsg_hardware_reboot():
#G_LOCAL_NODE_NAME = get_local_node_name()
G_LOCAL_NODE_NAME = "TSG_MXN"
system_cmd_run("rm /tmp/tttt")
G_LOCAL_NODE_NAME = "TSG_MCN1"
log_handle = syslog.openlog(G_LOCAL_NODE_NAME)
msg = "[%s] %s" %(MSG_PREFIX[syslog.LOG_ERR], "hardware reboot error, cant't run this command in test period!")
syslog.syslog(syslog.LOG_ERR, msg)
print (msg)
return 1
msg = "[%s] %s" %(MSG_PREFIX[syslog.LOG_NOTICE], "call tsg_hardware_reboot...")
syslog.syslog(syslog.LOG_NOTICE, msg)
ret = system_cmd_run("reboot")
if ret != 0:
log_handle = syslog.openlog(G_LOCAL_NODE_NAME)
msg = "[%s] %s" %(MSG_PREFIX[syslog.LOG_NOTICE], "tsg_hardware_reboot error!")
syslog.syslog(syslog.LOG_NOTICE, msg)
print (msg)
return 1
return 0
if __name__ == '__main__':
fun_res_code = tsg_hardware_reboot()
sys.exit(fun_res_code)

View File

@@ -4,6 +4,7 @@ import sys
import syslog
import subprocess
import time
import re
##define KERN_EMERG "<0>" /* system is unusable */
##define KERN_ALERT "<1>" /* action must be taken immediately */
@@ -46,7 +47,8 @@ def system_cmd_run(cmd_str):
for cmd in dangerous_cmd:
pattern = "\s*%s" %(cmd)
if re.match(pattern, cmd_str) != "":
match_str = re.match(pattern, cmd_str)
if not match_str is None:
print("can't run this cmd:%s" %(cmd_str))
sys.exit(1)
@@ -143,7 +145,11 @@ def tsg_stop_app_process(module_name, extra_progs, stop_method, check_method):
return res_code
def tsg_start_app_process_by_exec_call(module_name, module_cwd, module_exe, check_method):
os.chdir( module_cwd )
try:
os.chdir(module_cwd)
except Exception as e:
print("%s" %(e))
return 1
cmd_str = "./%s" %(module_exe)
ret_code, output = system_cmd_run(cmd_str)

View File

@@ -0,0 +1,19 @@
echo "ttt,device=ens1f4,flow_type=inline,node=mcn_1 PhyRXBits=1001i,PhyRXError=0i,PhyRXFrame=101i,PhyRXMissed=0i,PhyRXNoBUF=0i,PhyTXBits=801i,PhyTXError=0i,PhyTXFrame=201i,UsrRXDrops=0i,UsrTXDrops=0i" | nc -u 127.0.0.1 8126
echo "ttt,device=ens1f4,flow_type=inline,node=mcn_2 PhyRXBits=1001i,PhyRXError=0i,PhyRXFrame=101i,PhyRXMissed=0i,PhyRXNoBUF=0i,PhyTXBits=801i,PhyTXError=0i,PhyTXFrame=201i,UsrRXDrops=0i,UsrTXDrops=0i" | nc -u 127.0.0.1 8126
echo "ttt,device=ens1f4,flow_type=inline,node=mcn_3 PhyRXBits=1001i,PhyRXError=0i,PhyRXFrame=101i,PhyRXMissed=0i,PhyRXNoBUF=0i,PhyTXBits=801i,PhyTXError=0i,PhyTXFrame=201i,UsrRXDrops=0i,UsrTXDrops=0i" | nc -u 127.0.0.1 8126
echo "ttt,device=ens1f4,flow_type=inline,sn=CBT2201925000001,node=mcn_1 PhyRXBits=1001i,PhyRXError=0i,PhyRXFrame=101i,PhyRXMissed=0i,PhyRXNoBUF=0i,PhyTXBits=801i,PhyTXError=0i,PhyTXFrame=201i,UsrRXDrops=0i,UsrTXDrops=0i" | nc -u 127.0.0.1 8126
echo "ttt,device=ens1f4,flow_type=inline,sn=CBT2201925000002,node=mcn_2 PhyRXBits=1001i,PhyRXError=0i,PhyRXFrame=101i,PhyRXMissed=0i,PhyRXNoBUF=0i,PhyTXBits=801i,PhyTXError=0i,PhyTXFrame=201i,UsrRXDrops=0i,UsrTXDrops=0i" | nc -u 127.0.0.1 8126
echo "ttt,device=ens1f4,flow_type=inline,sn=CBT2201925000003,node=mcn_3 PhyRXBits=1001i,PhyRXError=0i,PhyRXFrame=101i,PhyRXMissed=0i,PhyRXNoBUF=0i,PhyTXBits=801i,PhyTXError=0i,PhyTXFrame=201i,UsrRXDrops=0i,UsrTXDrops=0i" | nc -u 127.0.0.1 8126
echo "ttt,device=ens1f4,flow_type=mirror,sn=CBT2201925000001,node=mcn_3 PhyRXBits=1001i,PhyRXError=0i,PhyRXFrame=101i,PhyRXMissed=0i,PhyRXNoBUF=0i,PhyTXBits=801i,PhyTXError=0i,PhyTXFrame=201i,UsrRXDrops=0i,UsrTXDrops=0i" | nc -u 127.0.0.1 8126
echo "ttt,device=ens1f4,flow_type=mirror,sn=CBT2201925000002,node=mcn_3 PhyRXBits=1001i,PhyRXError=0i,PhyRXFrame=101i,PhyRXMissed=0i,PhyRXNoBUF=0i,PhyTXBits=801i,PhyTXError=0i,PhyTXFrame=201i,UsrRXDrops=0i,UsrTXDrops=0i" | nc -u 127.0.0.1 8126
echo "ttt,device=ens1f4,flow_type=mirror,sn=CBT2201925000003,node=mcn_3 PhyRXBits=1001i,PhyRXError=0i,PhyRXFrame=101i,PhyRXMissed=0i,PhyRXNoBUF=0i,PhyTXBits=801i,PhyTXError=0i,PhyTXFrame=201i,UsrRXDrops=0i,UsrTXDrops=0i" | nc -u 127.0.0.1 8126

View File

@@ -54,7 +54,9 @@ if __name__ == '__main__':
global telegraf_client
global logger
arg_options = setup_argv_parser()
comm_arg_parser = setup_common_args()
arg_options = comm_arg_parser.parse_args()
logger = logger_init(arg_options.log_level)
telegraf_server_ip = arg_options.telegraf_ip

View File

@@ -319,7 +319,7 @@ def get_and_send_app_traffic():
# Check Parameters
try:
applist = app_symbol_load()
print("##### %s" %(applist))
#print("##### %s" %(applist))
if len(applist) == 0:
print("monit_stream: error: no running application.")
sys.exit(1)