cup.services package

Submodules

cup.services.heartbeat module

author:Guannan Ma maguannan@baidu.com @mythmgn
create_date:2014
last_date:2014
descrition:heartbeat related module
class cup.services.heartbeat.Device(name)[source]

Bases: object

Base class for all devices in heartbeat service

get_last_healthy()[source]

get last_healthy time of the device

get_name()[source]

get name

serilize()[source]

serilize device info

set_last_healthy()[source]

set last_healthy time

class cup.services.heartbeat.HeartbeatService(judge_lost_in_sec, keep_lost=False)[source]

Bases: object

HeartBeat service

activate(key, device)[source]

activate a device in HeartBeat Service. Add one if it’s new to hbs.

adjust_judge_lost_time(time_in_sec)[source]

adjust judge_lost_in_sec

cleanup_oldlost(dump_file=None)[source]

cleanup old lost devices.

Parameters:dump_file – if dump_file is not None, we will store devices info into dump_file Otherwise, we will cleanup the lost devices only.
get_lost()[source]

get lost devices

refresh(key)[source]
Parameters:key – refresh the device by key
Returns:if key does not exist, return False else, fresh the last_healthy time of the device
class cup.services.heartbeat.LinuxHost(name, init_this_host=False, iface='eth0')[source]

Bases: cup.services.heartbeat.Device

a linux host resource

get_cpu_idle()[source]

get cpu idle rate

get_ip()[source]

return ip information

get_mem_info()[source]
Returns:(mem_inuse, mem_total), in MB
get_net_usage()[source]
Returns:(net_in, net_out)
set_cpu_idle(idle_rate)[source]

set cpu idle rate

set_ip_port(ipaddr)[source]

set ip information

Parameters:ipaddr – ipaddr should be string and something like 10.10.10.1
set_linux_res_bydict(info_dict)[source]
{
‘iface’: ‘eth0’, ‘ipaddr’: ‘10.10.10.1’, ‘port’: 8089, ‘cpu_idle’: 50, ‘mem_inuse’: 1024, # MB ‘mem_total’: 8192, ‘net_in’: 8192, # kb ‘net_out’: 102400, # kb

}

set_mem_usage(mem_inuse, mem_total)[source]

set up mem_inuse and mem_total. Will update any of them if it is not None.

set_net_usage(net_in, net_out)[source]
Parameters:
  • net_in – net_in in kB/s. If net_in is None, will update nothing.
  • net_out – net_out in kB/s. If net_out is None, will update nothing.

Module contents

@author Guannan Ma @mythmgn

Table Of Contents

Previous topic

cup.res package

Next topic

cup.shell package

This Page