def __init__(self, **kwargs): if kwargs: self.cpu_cores = kwargs['cpu_cores'] self.os_type = kwargs['os_type'] self.memory_mb = kwargs['memory_mb'] self.architecture = kwargs['architecture'] self.load_average = kwargs['load_average'] self.disk_usage = kwargs['disk_usage'] else: self.cpu_cores = sys_assist.get_cpu_core_count() self.os_type = platform.platform() self.memory_mb = sys_assist.get_sys_mem_total_MB() self.architecture = platform.machine() self.load_average = sys_assist.get_load_average() self.disk_usage = sys_assist.get_disk_usage()
def __init__(self, **kwargs): if kwargs: self.cpu_cores = kwargs['cpu_cores'] self.os_type = kwargs['os_type'] self.memory_mb = kwargs['memory_mb'] self.architecture = kwargs['architecture'] self.load_average = kwargs['load_average'] self.disk_usage = kwargs['disk_usage'] self.timestamp = kwargs['timestamp'] else: self.cpu_cores = sys_assist.get_cpu_core_count() self.os_type = platform.platform() self.memory_mb = sys_assist.get_sys_mem_total_MB() self.architecture = platform.machine() self.load_average = sys_assist.get_load_average() self.disk_usage = sys_assist.get_disk_usage() self.timestamp = timeutils.utcnow()
def _send_stats(self, load_ave_interval, disk_usage_interval): """ send system usage data to the coordinator on specified intervals """ time_lapsed = 0 while True: sleep(load_ave_interval) time_lapsed += load_ave_interval cache = ConfigCache() config = cache.get_config() if config: token_header = { "WORKER-ID": config.worker_id, "WORKER-TOKEN": config.worker_token } request_uri = "{0}/worker/{1}/status".format( config.coordinator_uri, config.worker_id) req_body = {'load_average': sys_assist.get_load_average()} if time_lapsed == disk_usage_interval: time_lapsed = 0 req_body.update( {'disk_usage': sys_assist.get_disk_usage()}) try: http_request(request_uri, token_header, jsonutils.dumps(req_body), http_verb='PUT') except requests.RequestException: pass if self.run_once: break
def __init__(self, **kwargs): """ An object can be initialized by passing in a dictionary representation of the data as **kwargs. Otherwise the constructor will retrieve system stats from the machine it is executing on. """ if kwargs: self.cpu_cores = kwargs['cpu_cores'] self.os_type = kwargs['os_type'] self.memory_mb = kwargs['memory_mb'] self.architecture = kwargs['architecture'] self.load_average = kwargs['load_average'] self.disk_usage = kwargs['disk_usage'] self.timestamp = kwargs['timestamp'] else: self.cpu_cores = sys_assist.get_cpu_core_count() self.os_type = platform.platform() self.memory_mb = sys_assist.get_sys_mem_total_MB() self.architecture = platform.machine() self.load_average = sys_assist.get_load_average() self.disk_usage = sys_assist.get_disk_usage() self.timestamp = str(timeutils.utcnow())
def __init__(self, **kwargs): """ An object can be initialized by passing in a dictionary representation of the data as **kwargs. Otherwise the constructor will retrieve system stats from the machine it is executing on. """ if kwargs: self.cpu_cores = kwargs['cpu_cores'] self.os_type = kwargs['os_type'] self.memory_mb = kwargs['memory_mb'] self.architecture = kwargs['architecture'] self.load_average = kwargs['load_average'] self.disk_usage = kwargs['disk_usage'] self.timestamp = kwargs['timestamp'] else: self.cpu_cores = sys_assist.get_cpu_core_count() self.os_type = platform.platform() self.memory_mb = sys_assist.get_sys_mem_total_MB() self.architecture = platform.machine() self.load_average = sys_assist.get_load_average() self.disk_usage = sys_assist.get_disk_usage() self.timestamp = timeutils.utcnow()
def test_get_load_avergae(self): ave = sys_assist.get_load_average() self.assertTrue('1'in ave) self.assertTrue('5'in ave) self.assertTrue('15'in ave)