def mes_mysql(): conn_m = MySQLdb.connect(host=read_xml.get_val()[0], port=int(read_xml.get_val()[1]), user=read_xml.get_val()[2], passwd=read_xml.get_val()[3], db=read_xml.get_val()[4], charset='utf8') return conn_m
def main(): try: time_interval1 = int(read_xml.get_val()[6]) # mysql->table, dashboard.nodes insert_fun() #mysql->table, dashboard.realtidt pp = multiprocessing.Process(target=insert_fun1, args=()) #mysql-table, dashboard.offlinetidt qq = multiprocessing.Process(target=compute, args=( insert_fun2, 0, 0, 0, time_interval1, )) #yy.start() pp.start() qq.start() #yy.join() pp.join() qq.join() except MySQLdb.Error, msg: print "error , conn has gone away", msg sys.exit(1)
def fun_msg(): #根据刷新时间不同,定义2个总信息列表, 初始化列表 list_message = ['0'] path1 = read_xml.get_val()[7] path2 = read_xml.get_val()[8] #扩展列表,汇总所有抓取的信息 list_message.append(hostname) list_message.extend(offlinetidt.Mem_info.fun_memory()) list_message.extend(offlinetidt.swap_info.fun_swap()) list_message.extend(offlinetidt.disk_info.fun_disk(path1)) if path2 is not None: list_message.extend(offlinetidt.disk_info.fun_disk(path2)) else: list_message.extend(['0', '0', '0']) #now_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) list_message.append(get_now_time()) #协程yield yield list_message
date: 2017/3/13 ------------------------------------------------- Change Activity: ------------------------------------------------- """ import MySQLdb import read_xml import socket import os import time import multiprocessing from datetime import datetime, timedelta time_interval = int(read_xml.get_val()[5]) def compute(fun, day=0, hour=0, min=0, second=0): fun() now = datetime.now() period = timedelta(days=day, hours=hour, minutes=min, seconds=second) next_time = now + period while True: time.sleep(day * 24 * 60 * 60) iter_now = datetime.now() if (next_time - iter_now <= period):
import os.path sys.path.append(os.path.join(os.path.dirname(__file__), '..')) import os import socket import time from datetime import datetime, timedelta import nodes.node_info import offlinetidt.disk_info, offlinetidt.Mem_info, offlinetidt.swap_info import realtidt.cpu_stat, realtidt.disk_io_stat, realtidt.net_info import read_xml #从配置文件获取时间计算间隔 c_time = int(read_xml.get_val()[5]) #获取主机名 hostname = socket.gethostname() def get_now_time(): '''获取现在的时间''' ttime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) return ttime def disk_io(): '''获取硬盘读写数据量''' list_disk_io = [] list_disk_io.extend(realtidt.disk_io_stat.disk_io_info()) return list_disk_io def net_io():