summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlijia <[email protected]>2019-08-08 19:12:32 +0800
committerlijia <[email protected]>2019-08-08 19:12:32 +0800
commitd5f4683fcc139c4e2b25c2f62548cd4215f3c51b (patch)
tree32a0357ab7d5f80b8eb2069d9e7378f20f1d9b1c
parent0f54e47ebc2686460cd1110a06888189a6139fbd (diff)
psutil不能获取计算板网卡流量.
-rw-r--r--deploy_etc/tsg_chassis_interface.json4
-rw-r--r--deploy_etc/tsg_chassis_ip.json24
-rw-r--r--pkg.sh14
-rw-r--r--py_cmd/tsg_hardware_reboot.py32
-rw-r--r--py_cmd/tsg_software_reboot.py10
-rw-r--r--py_test/nc_inserto_influxDB.sh19
-rw-r--r--py_tools/tsg_monit_interface.py (renamed from py_tools/tsg_iterate_interface_list.py)4
-rw-r--r--py_tools/tsg_monit_stream.py (renamed from py_tools/tsg_monit_stream_by_telegraf.py)2
8 files changed, 71 insertions, 38 deletions
diff --git a/deploy_etc/tsg_chassis_interface.json b/deploy_etc/tsg_chassis_interface.json
index 444baa2..f43dc2c 100644
--- a/deploy_etc/tsg_chassis_interface.json
+++ b/deploy_etc/tsg_chassis_interface.json
@@ -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"
}]
} \ No newline at end of file
diff --git a/deploy_etc/tsg_chassis_ip.json b/deploy_etc/tsg_chassis_ip.json
index 06d0973..46e1c6b 100644
--- a/deploy_etc/tsg_chassis_ip.json
+++ b/deploy_etc/tsg_chassis_ip.json
@@ -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"
}]
}
diff --git a/pkg.sh b/pkg.sh
index ae9d405..66771f4 100644
--- a/pkg.sh
+++ b/pkg.sh
@@ -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
diff --git a/py_cmd/tsg_hardware_reboot.py b/py_cmd/tsg_hardware_reboot.py
index 1562ab9..786d166 100644
--- a/py_cmd/tsg_hardware_reboot.py
+++ b/py_cmd/tsg_hardware_reboot.py
@@ -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")
-
- 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
+ G_LOCAL_NODE_NAME = "TSG_MCN1"
+ log_handle = syslog.openlog(G_LOCAL_NODE_NAME)
+ 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)
diff --git a/py_cmd/tsg_software_reboot.py b/py_cmd/tsg_software_reboot.py
index 5ceaf90..efb592c 100644
--- a/py_cmd/tsg_software_reboot.py
+++ b/py_cmd/tsg_software_reboot.py
@@ -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)
diff --git a/py_test/nc_inserto_influxDB.sh b/py_test/nc_inserto_influxDB.sh
new file mode 100644
index 0000000..49f3ff2
--- /dev/null
+++ b/py_test/nc_inserto_influxDB.sh
@@ -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 \ No newline at end of file
diff --git a/py_tools/tsg_iterate_interface_list.py b/py_tools/tsg_monit_interface.py
index f5fc2f9..64a3729 100644
--- a/py_tools/tsg_iterate_interface_list.py
+++ b/py_tools/tsg_monit_interface.py
@@ -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
diff --git a/py_tools/tsg_monit_stream_by_telegraf.py b/py_tools/tsg_monit_stream.py
index 973a3f5..5cf3b50 100644
--- a/py_tools/tsg_monit_stream_by_telegraf.py
+++ b/py_tools/tsg_monit_stream.py
@@ -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)