Esempio n. 1
0
 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()
Esempio n. 2
0
 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()
Esempio n. 3
0
    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
Esempio n. 4
0
 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())
Esempio n. 5
0
 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()
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)