Exemplo n.º 1
0
def get_sysinfo():
    """ 取得系统资源使用情况"""
    import system_info
    from multiprocessing import cpu_count
    info = {}
    info['cpu'] = (cpu_count(),int(round(float(system_info.get_cpu_usage()))),system_info.get_cpu_style())
    info['mem'] = system_info.get_mem_usage()
    info['ip'] = system_info.get_ip()
    return info 
Exemplo n.º 2
0
def	get_process_count(level):
	"""根据级别和cpu数量来决定线程数
	"""
	level_dist = {'low':0.3,
				  'middle':0.5,
				  'high':0.8,
				  'power':1}
	#pdb.set_trace()				
	cpus = multiprocessing.cpu_count()
	usage = float(get_cpu_usage()[:-1])*0.01
	cpu_free = cpus	* (1 - usage)	
	pro_num	= int(cpu_free * level_dist[level]) or	1
	print (cpus,usage,cpu_free,pro_num)
	return pro_num
Exemplo n.º 3
0
def	get_process_count(level):
	"""根据级别和cpu数量来决定线程数
	@level_dist
		low	低使用率 10%cpu线程数 
		mid	中等使用率 50%cpu线程数
		high  高使用率 80%cpu线程数
		power	满负载	  所有cpu线程数
	"""
	
	level_dist = {'low':0.3,
				  'mid':0.5,
				  'high':0.8,
				  'power':1}
	#pdb.set_trace()				
	cpus = multiprocessing.cpu_count()
	usage = float(get_cpu_usage()[:-1])*0.01
	cpu_free = cpus	* (1 - usage)	
	pro_num	= int(cpu_free * level_dist[level]) or	1
	
	return pro_num
Exemplo n.º 4
0
def report(start_time):
    """ 转换器向服务器报告状态 """
    cpu_style = get_cpu_style()
    cpu_percent = get_cpu_usage() 
    mem_percent, mem_total = get_mem_usage()
    ip = CONFIG['server']['alias']

    traceback_dict = {}
    for thread_id, frame in sys._current_frames().items():
        traceback_dict[thread_id] = traceback.format_stack(frame)

    # 向服务器报告
    return dict( ip=ip,
            cpu_style=cpu_style, 
            cpu_percent=cpu_percent, 
            mem_total=mem_total, 
            mem_percent=mem_percent, 
            started=start_time, 
            timestamp=int(time.time()),
            traceback=traceback_dict,
            )
Exemplo n.º 5
0
def report(start_time):
    """ 转换器向服务器报告状态 """
    cpu_style = get_cpu_style()
    cpu_percent = get_cpu_usage()
    mem_percent, mem_total = get_mem_usage()
    ip = safe_get_host('server', 'alias')

    traceback_dict = {}
    for thread_id, frame in sys._current_frames().items():
        traceback_dict[thread_id] = traceback.format_stack(frame)

    # 向服务器报告
    return dict(
        ip=ip,
        cpu_style=cpu_style,
        cpu_percent=cpu_percent,
        mem_total=mem_total,
        mem_percent=mem_percent,
        started=start_time,
        timestamp=int(time.time()),
        traceback=traceback_dict,
    )
Exemplo n.º 6
0
def report(start_time):
    """ 转换器向服务器报告状态 """
    cpu_style = get_cpu_style()
    cpu_percent = get_cpu_usage()
    mem_percent, mem_total = get_mem_usage()
    ip = CONFIG['server']['alias']

    traceback_dict = {}
    for thread_id, frame in sys._current_frames().items():
        traceback_dict[thread_id] = traceback.format_stack(frame)

    # 向服务器报告
    return dict(
        ip=ip,
        cpu_style=cpu_style,
        cpu_percent=cpu_percent,
        mem_total=mem_total,
        mem_percent=mem_percent,
        cron_running=ztq_core.cron.CRON_RUNNING,
        started=start_time,
        timestamp=int(time.time()),
        traceback=traceback_dict,
    )