def httpCall(self, data, apiurl): compresseddata = "" try: f = urllib.urlopen( url = "http://api.borqs.com" + apiurl, data = urllib.urlencode(data) ) compresseddata = f.read() compressedstream = StringIO.StringIO(compresseddata) gzipper = gzip.GzipFile(fileobj=compressedstream) data = gzipper.read() if data.find("10001") == -1: fp = '../logs/' + time.strftime('%Y%m%d%H%M%S',time.localtime(time.time())) os.system("echo ---------------- gcutil ----------------- > " + fp) os.system("jstat -gcutil `cat ~/.bpid/main.pid` >> " + fp) os.system("echo ---------------- gccapacity ------------- >> " + fp) os.system("jstat -gccapacity `cat ~/.bpid/main.pid` >> " + fp) os.system("echo ---------------- compilation ------------ >> " + fp) os.system("jstat -printcompilation `cat ~/.bpid/main.pid` 1000 10 >> " + fp) os.system("echo ---------------- thread stack ----------- >> " + fp) os.system("jstack -l `cat ~/.bpid/main.pid` >> " + fp) os.system("echo ---------------- user occupy cpu ----------- >> " + fp) os.system('top -b -n 1 |grep Cpu | cut -d "," -f 1 | cut -d ":" -f 2 >> ' + fp) os.system("echo ---------------- system occupy cpu ----------- >> " + fp) os.system('top -b -n 1 |grep Cpu | cut -d "," -f 2 >> ' + fp) os.system("echo ---------------- memory use ----------- >> " + fp) os.system('top -b -n 1 |grep Mem | cut -d "," -f 1 | cut -d ":" -f 2 >> ' + fp) os.chdir("/home/wutong/workWT/") os.system("./kill_server.py") os.system("./restart_server.py") except: content = "Except occured, restart account server now!\n"; logger.init_config(path='../logs/', filename='access.log') logging.info(content) # file_object = open('../logs/access.log', 'a') # file_object.writelines(content) # file_object.close() fp = '../logs/' + time.strftime('%Y%m%d%H%M%S',time.localtime(time.time())) os.system("echo ---------------- gcutil ----------------- > " + fp) os.system("jstat -gcutil `cat ~/.bpid/main.pid` >> " + fp) os.system("echo ---------------- gccapacity ------------- >> " + fp) os.system("jstat -gccapacity `cat ~/.bpid/main.pid` >> " + fp) os.system("echo ---------------- compilation ------------ >> " + fp) os.system("jstat -printcompilation `cat ~/.bpid/main.pid` 1000 10 >> " + fp) os.system("echo ---------------- thread stack ----------- >> " + fp) os.system("jstack -l `cat ~/.bpid/main.pid` >> " + fp) os.system("echo ---------------- user occupy cpu ----------- >> " + fp) os.system('top -b -n 1 |grep Cpu | cut -d "," -f 1 | cut -d ":" -f 2 >> ' + fp) os.system("echo ---------------- system occupy cpu ----------- >> " + fp) os.system('top -b -n 1 |grep Cpu | cut -d "," -f 2 >> ' + fp) os.system("echo ---------------- memory use ----------- >> " + fp) os.system('top -b -n 1 |grep Mem | cut -d "," -f 1 | cut -d ":" -f 2 >> ' + fp) os.chdir("/home/wutong/workWT/") os.system("./kill_server.py") os.system("./restart_server.py") return data
import os import time import logging import logger from command import * while True: content = "\nUser occupy cpu: " content += execCmd( 'top -b -n 1 |grep Cpu | cut -d "," -f 1 | cut -d ":" -f 2') content += "\nSystem occupy cpu: " content += execCmd('top -b -n 1 |grep Cpu | cut -d "," -f 2') content += "\nMemory use: " content += execCmd( 'top -b -n 1 |grep Mem | cut -d "," -f 1 | cut -d ":" -f 2') content += " " content += execCmd('top -b -n 1 |grep Mem | cut -d "," -f 2') pid = execCmd('netstat -anp | grep 8080 | awk \'{print $7}\'') index = pid.find('/') if index != -1: pid = pid[0:index] content += "Borqs web server cpu usage: " + execCmd( 'ps aux|grep ' + pid + '|grep -v "grep"|awk \'{print $3}\'') content += "Borqs web server mem usage: " + execCmd( 'ps aux|grep ' + pid + '|grep -v "grep"|awk \'{print $4}\'') logger.init_config(path='../logs/') logging.info(content) # print content time.sleep(10)
def httpCall(self, data, apiurl): compresseddata = "" try: f = urllib.urlopen(url="http://api.borqs.com" + apiurl, data=urllib.urlencode(data)) compresseddata = f.read() compressedstream = StringIO.StringIO(compresseddata) gzipper = gzip.GzipFile(fileobj=compressedstream) data = gzipper.read() if data.find("10001") == -1: fp = '../logs/' + time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) os.system( "echo ---------------- gcutil ----------------- > " + fp) os.system("jstat -gcutil `cat ~/.bpid/main.pid` >> " + fp) os.system( "echo ---------------- gccapacity ------------- >> " + fp) os.system("jstat -gccapacity `cat ~/.bpid/main.pid` >> " + fp) os.system( "echo ---------------- compilation ------------ >> " + fp) os.system( "jstat -printcompilation `cat ~/.bpid/main.pid` 1000 10 >> " + fp) os.system( "echo ---------------- thread stack ----------- >> " + fp) os.system("jstack -l `cat ~/.bpid/main.pid` >> " + fp) os.system( "echo ---------------- user occupy cpu ----------- >> " + fp) os.system( 'top -b -n 1 |grep Cpu | cut -d "," -f 1 | cut -d ":" -f 2 >> ' + fp) os.system( "echo ---------------- system occupy cpu ----------- >> " + fp) os.system('top -b -n 1 |grep Cpu | cut -d "," -f 2 >> ' + fp) os.system("echo ---------------- memory use ----------- >> " + fp) os.system( 'top -b -n 1 |grep Mem | cut -d "," -f 1 | cut -d ":" -f 2 >> ' + fp) os.chdir("/home/wutong/workWT/") os.system("./kill_server.py") os.system("./restart_server.py") except: content = "Except occured, restart account server now!\n" logger.init_config(path='../logs/', filename='access.log') logging.info(content) # file_object = open('../logs/access.log', 'a') # file_object.writelines(content) # file_object.close() fp = '../logs/' + time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) os.system("echo ---------------- gcutil ----------------- > " + fp) os.system("jstat -gcutil `cat ~/.bpid/main.pid` >> " + fp) os.system("echo ---------------- gccapacity ------------- >> " + fp) os.system("jstat -gccapacity `cat ~/.bpid/main.pid` >> " + fp) os.system("echo ---------------- compilation ------------ >> " + fp) os.system( "jstat -printcompilation `cat ~/.bpid/main.pid` 1000 10 >> " + fp) os.system("echo ---------------- thread stack ----------- >> " + fp) os.system("jstack -l `cat ~/.bpid/main.pid` >> " + fp) os.system("echo ---------------- user occupy cpu ----------- >> " + fp) os.system( 'top -b -n 1 |grep Cpu | cut -d "," -f 1 | cut -d ":" -f 2 >> ' + fp) os.system( "echo ---------------- system occupy cpu ----------- >> " + fp) os.system('top -b -n 1 |grep Cpu | cut -d "," -f 2 >> ' + fp) os.system("echo ---------------- memory use ----------- >> " + fp) os.system( 'top -b -n 1 |grep Mem | cut -d "," -f 1 | cut -d ":" -f 2 >> ' + fp) os.chdir("/home/wutong/workWT/") os.system("./kill_server.py") os.system("./restart_server.py") return data
#!/usr/bin/python import os import time import logging import logger from command import * while True: content = "\nUser occupy cpu: " content += execCmd('top -b -n 1 |grep Cpu | cut -d "," -f 1 | cut -d ":" -f 2') content += "\nSystem occupy cpu: " content += execCmd('top -b -n 1 |grep Cpu | cut -d "," -f 2') content += "\nMemory use: " content += execCmd('top -b -n 1 |grep Mem | cut -d "," -f 1 | cut -d ":" -f 2') content += " " content += execCmd('top -b -n 1 |grep Mem | cut -d "," -f 2') pid = execCmd('netstat -anp | grep 8080 | awk \'{print $7}\'') index = pid.find('/') if index != -1: pid = pid[0:index] content += "Borqs web server cpu usage: " + execCmd('ps aux|grep ' + pid + '|grep -v "grep"|awk \'{print $3}\'') content += "Borqs web server mem usage: " + execCmd('ps aux|grep ' + pid + '|grep -v "grep"|awk \'{print $4}\'') logger.init_config(path='../logs/') logging.info(content) # print content time.sleep(10)