def cpu_rrd(self, sql_cpu): debug = "This is cpu.rrd to perform the debug result :" # mysql configure host_sql = self.host user = self.user password = self.password defaultdb = self.defaultdb # rrdtool host configure host = self.rrdtool_host report_dir = self.rrdtool_dir # conv = converters.conversions.copy() conv[246] = float # convert decimals to floats conn = MySQLdb.connect(host_sql, user, password, defaultdb, conv=conv) cur = conn.cursor() cpu_list = [] cur.execute(sql_cpu) rows = int(cur.rowcount) for i in xrange(rows): row = cur.fetchone() #print row[0],row[1],row[2] a = str(row[0]) l = str(row[1]) timeArray = time.strptime(l, "%Y-%m-%d %H:%M:%S") b = str(int(time.mktime(timeArray))) c = row[2].split(',')[0].strip() d = row[2].split(',')[1].strip() e = row[2].split(',')[2].strip() f = str(row[3]) g = str(row[4]) h = str(row[5]) i = str(row[6]) j = str(row[7]) k = str(row[8]) #cpu_list = [a,b,c,d,e,f,g,h,i,j,k] #print cpu_list for ip in list(host.split(',')): #print cpu_list[1],cpu_list[2] if ip == a: # print report_dir os.chdir(report_dir) os.chdir(ip) # print type(cpu_list[1]) # print type(cpu_list[2]) #db = rrdtool.updatev('cpu.rrd','%s:%s:%s:%s:%s:%s:%s:%s:%s:%s' % (b,c,d,e,f,g,h,i,j,k)) cmd = '/usr/bin/rrdtool updatev cpu.rrd %s:%s:%s:%s:%s:%s:%s:%s:%s:%s' % ( b, c, d, e, f, g, h, i, j, k) db_update = shell.shell_cmd(cmd) print db_update time.sleep(1) print os.getcwd() print "cpu.rrd" conn.close() return (debug + str(db_update))
def cpu_rrd(self,sql_cpu): debug = "This is cpu.rrd to perform the debug result :" # mysql configure host_sql = self.host user = self.user password = self.password defaultdb = self.defaultdb # rrdtool host configure host = self.rrdtool_host report_dir = self.rrdtool_dir # conv = converters.conversions.copy() conv[246] = float # convert decimals to floats conn = MySQLdb.connect(host_sql,user,password,defaultdb,conv=conv) cur = conn.cursor() cpu_list = [] cur.execute(sql_cpu) rows = int(cur.rowcount) for i in xrange(rows): row = cur.fetchone() #print row[0],row[1],row[2] a = str(row[0]) l = str(row[1]) timeArray = time.strptime(l, "%Y-%m-%d %H:%M:%S") b = str(int(time.mktime(timeArray))) c = row[2].split(',')[0].strip() d = row[2].split(',')[1].strip() e = row[2].split(',')[2].strip() f = str(row[3]) g = str(row[4]) h = str(row[5]) i = str(row[6]) j = str(row[7]) k = str(row[8]) #cpu_list = [a,b,c,d,e,f,g,h,i,j,k] #print cpu_list for ip in list(host.split(',')): #print cpu_list[1],cpu_list[2] if ip == a : # print report_dir os.chdir(report_dir) os.chdir(ip) # print type(cpu_list[1]) # print type(cpu_list[2]) #db = rrdtool.updatev('cpu.rrd','%s:%s:%s:%s:%s:%s:%s:%s:%s:%s' % (b,c,d,e,f,g,h,i,j,k)) cmd = '/usr/bin/rrdtool updatev cpu.rrd %s:%s:%s:%s:%s:%s:%s:%s:%s:%s' % (b,c,d,e,f,g,h,i,j,k) db_update = shell.shell_cmd(cmd) print db_update time.sleep(1) print os.getcwd() print "cpu.rrd" conn.close() return (debug+str(db_update))
def floatingip_create(user,num): count = 1 while (count < num+1): cmd_neutron = 'neutron floatingip-create %s' % (external) neutrn = shell.shell_cmd(cmd_neutron) if (user == 'admin'): shell.shell_cmd('bash') rc = cf.admin_rc() cmd_source = 'source %s' %(rc) source = shell.shell_cmd(cmd_source) cmd_neutron shell.shell_cmd('exit') print "hello,word" count = count + 1 elif(user == 'kycloud'): pass elif(user == 'kyprivate'): pass elif(user == 'kyp2p'): pass else: print "请输入正确的user"
def mem_rrd(self, sql_mem): debug = "This is mem.rrd to perform the debug result :" # mysql configure host_sql = self.host user = self.user password = self.password defaultdb = self.defaultdb # rrdtool host configure host = self.rrdtool_host report_dir = self.rrdtool_dir conv = converters.conversions.copy() conv[246] = float # convert decimals to floats conn = MySQLdb.connect(host_sql, user, password, defaultdb, conv=conv) cur = conn.cursor() #mem_list = [] cur.execute(sql_mem) rows = int(cur.rowcount) for i in xrange(rows): row = cur.fetchone() a = str(row[0]) m = str(row[1]) timeArray = time.strptime(m, "%Y-%m-%d %H:%M:%S") b = str(int(time.mktime(timeArray))) c = str(row[2]) d = str(row[3]) e = str(row[4]) f = str(row[5]) g = str(row[6]) h = str(row[7]) i = str(row[8]) j = str(row[9]) k = str(row[10]) l = str(row[11]) #mem_list = [a,b,c,d,e,f,g,h,k] #print "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s" %(a,b,c,d,e,f,g,h,i,j,k,l) for ip in list(host.split(',')): if ip == a: #print "%s is %s" %(j,mem_list[0]) os.chdir(report_dir) os.chdir(ip) #print os.getcwd() cmd = '/usr/bin/rrdtool updatev mem.rrd %s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s' % ( b, c, d, e, f, g, h, i, j, k, l) db_update = shell.shell_cmd(cmd) print db_update time.sleep(1) print os.getcwd() print "mem.rrd" conn.close() return (debug + str(db_update))
def mem_rrd(self,sql_mem): debug = "This is mem.rrd to perform the debug result :" # mysql configure host_sql = self.host user = self.user password = self.password defaultdb = self.defaultdb # rrdtool host configure host = self.rrdtool_host report_dir = self.rrdtool_dir conv = converters.conversions.copy() conv[246] = float # convert decimals to floats conn = MySQLdb.connect(host_sql,user,password,defaultdb,conv=conv) cur = conn.cursor() #mem_list = [] cur.execute(sql_mem) rows = int(cur.rowcount) for i in xrange(rows): row = cur.fetchone() a = str(row[0]) m = str(row[1]) timeArray = time.strptime(m, "%Y-%m-%d %H:%M:%S") b = str(int(time.mktime(timeArray))) c = str(row[2]) d = str(row[3]) e = str(row[4]) f = str(row[5]) g = str(row[6]) h = str(row[7]) i = str(row[8]) j = str(row[9]) k = str(row[10]) l = str(row[11]) #mem_list = [a,b,c,d,e,f,g,h,k] #print "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s" %(a,b,c,d,e,f,g,h,i,j,k,l) for ip in list(host.split(',')): if ip == a : #print "%s is %s" %(j,mem_list[0]) os.chdir(report_dir) os.chdir(ip) #print os.getcwd() cmd = '/usr/bin/rrdtool updatev mem.rrd %s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s' % (b,c,d,e,f,g,h,i,j,k,l) db_update = shell.shell_cmd(cmd) print db_update time.sleep(1) print os.getcwd() print "mem.rrd" conn.close() return (debug+str(db_update))
def nic_rrd(self, sql_nic): debug = "This is nic.rrd to perform the debug result :" # mysql configure host_sql = self.host user = self.user password = self.password defaultdb = self.defaultdb # rrdtool host configure host = self.rrdtool_host report_dir = self.rrdtool_dir conv = converters.conversions.copy() conv[246] = float # convert decimals to floats conn = MySQLdb.connect(host_sql, user, password, defaultdb, conv=conv) cur = conn.cursor() nic_list = [] cur.execute(sql_nic) rows = int(cur.rowcount) for i in xrange(rows): row = cur.fetchone() a = str(row[0]) g = str(row[1]) timeArray = time.strptime(g, "%Y-%m-%d %H:%M:%S") b = str(int(time.mktime(timeArray))) c = str(row[2]) d = str(row[4]) e = str(row[3]) f = str(row[5]) # nic_list = [a,b,c,d] print "%s %s %s %s %s %s" % (a, b, c, d, e, f) for j in list(host.split(',')): if j == a: os.chdir(report_dir) os.chdir(j) #print nic_list #db = rrdtool.updatev('nic.rrd','%s:%s:%s:%s:%s' % (b,c,d,e,f)) cmd = '/usr/bin/rrdtool updatev nic.rrd %s:%s:%s:%s:%s' % ( b, c, d, e, f) db_update = shell.shell_cmd(cmd) print db_update time.sleep(1) print os.getcwd() print "nic.rrd" conn.close() return (debug + str(db_update))
def nic_rrd(self,sql_nic): debug = "This is nic.rrd to perform the debug result :" # mysql configure host_sql = self.host user = self.user password = self.password defaultdb = self.defaultdb # rrdtool host configure host = self.rrdtool_host report_dir = self.rrdtool_dir conv = converters.conversions.copy() conv[246] = float # convert decimals to floats conn = MySQLdb.connect(host_sql,user,password,defaultdb,conv=conv) cur = conn.cursor() nic_list = [] cur.execute(sql_nic) rows = int(cur.rowcount) for i in xrange(rows): row = cur.fetchone() a = str(row[0]) g = str(row[1]) timeArray = time.strptime(g, "%Y-%m-%d %H:%M:%S") b = str(int(time.mktime(timeArray))) c = str(row[2]) d = str(row[4]) e = str(row[3]) f = str(row[5]) # nic_list = [a,b,c,d] print "%s %s %s %s %s %s" % (a,b,c,d,e,f) for j in list(host.split(',')): if j == a: os.chdir(report_dir) os.chdir(j) #print nic_list #db = rrdtool.updatev('nic.rrd','%s:%s:%s:%s:%s' % (b,c,d,e,f)) cmd = '/usr/bin/rrdtool updatev nic.rrd %s:%s:%s:%s:%s' % (b,c,d,e,f) db_update = shell.shell_cmd(cmd) print db_update time.sleep(1) print os.getcwd() print "nic.rrd" conn.close() return (debug+str(db_update))
def mem_used(): cmd = "free -m |grep Mem |awk '{print $3}'" mem_used = shell.shell_cmd(cmd) return mem_used[0].split('\n')[0]
def cpu_idle(): cmd = "iostat -c 1 3 |grep -v -e '^[a-z]' -e '^[A-Z]' -e '^$'|awk 'BEGIN{sum=0}{sum +=$6/3}END{print sum}'" cpu_idle = shell.shell_cmd(cmd) return cpu_idle[0].split('\n')[0]
def cpu_loadavg(): cmd = "uptime |awk -F 'load average:' '{print $2}'" cpu_loadavg = shell.shell_cmd(cmd) return cpu_loadavg[0].split('\n')[0]
def cpu_idle(): cmd = "iostat -c 1 3 |grep -v -e '^[a-z]' -e '^[A-Z]' -e '^$'|awk 'BEGIN{sum=0}{sum +=$6/3}END{print sum}'" cpu_idle = shell.shell_cmd(cmd) return cpu_idle[0].split('\n')[0]
def cpu_loadavg(): cmd = "uptime |awk -F 'load average:' '{print $2}'" cpu_loadavg = shell.shell_cmd(cmd) return cpu_loadavg[0].split('\n')[0]
def login_user_num(): cmd = "who -uq|sed -n '/#/ p'|cut -d = -f2" login_user_num = shell.shell_cmd(cmd)[0].split('\n')[0] return login_user_num
def swap_used(): cmd = "free -m |grep 'Swap'|awk '{print $3}'" swap_used = shell.shell_cmd(cmd) return swap_used[0].split('\n')[0]
def mem_buffers_used(): cmd = "free -m |grep 'buffers/cache:'|awk '{print $3}'" mem_buffers_used = shell.shell_cmd(cmd) return mem_buffers_used[0].split('\n')[0]
def mem_total(): cmd = "free -m |grep Mem |awk '{print $2}'" mem_total = shell.shell_cmd(cmd) return mem_total[0].split('\n')[0]
def ip_address(): cmd = "ifconfig eth0|sed -n '/inet / p'|cut -d : -f2|awk '{print $1}'" ip = shell.shell_cmd(cmd) ip_address = ip[0].split('\n') return ip_address[0]
def login_user_num(): cmd = "who -uq|sed -n '/#/ p'|cut -d = -f2" login_user_num = shell.shell_cmd(cmd)[0].split('\n')[0] return login_user_num
def login_user_name(): cmd = "who -uq|sed -n '/[a-z,A-Z]/ p'" login_user_name = shell.shell_cmd(cmd)[0].split('\n')[0] return login_user_name
def mem_used_percent(): cmd = "free -m |grep Mem |awk '{printf $3/$2*100}'" mem_used_percent = shell.shell_cmd(cmd) return mem_used_percent[0].split('\n')[0]
def swap_used_percent(): cmd = "free -m |grep 'Swap'|awk '{print $3/$2*100}'" swap_used_percent = shell.shell_cmd(cmd) return swap_used_percent[0].split('\n')[0]
def login_user_name(): cmd = "who -uq|sed -n '/[a-z,A-Z]/ p'" login_user_name = shell.shell_cmd(cmd)[0].split('\n')[0] return login_user_name
def swap_total(): cmd = "free -m |grep 'Swap'|awk '{print $2}'" swap_total = shell.shell_cmd(cmd) return swap_total[0].split('\n')[0]
def hostname_get(): cmd = "hostname" hostname_get = shell.shell_cmd(cmd)[0].split('\n')[0] return hostname_get
def ip_address(): cmd = "ifconfig eth0|sed -n '/inet / p'|cut -d : -f2|awk '{print $1}'" ip = shell.shell_cmd(cmd) ip_address = ip[0].split('\n') return ip_address[0]