Esempio n. 1
0
 def __init__(self, name, init_config, agent_config):
     super(Cpu, self).__init__(name, init_config, agent_config)
     # psutil.cpu_percent and psutil.cpu_times_percent are called in
     # __init__ because the first time these two functions are called with
     # interval = 0.0 or None, it will return a meaningless 0.0 value
     # which you are supposed to ignore.
     psutil.cpu_percent(interval=None, percpu=False)
     psutil.cpu_times_percent(interval=None, percpu=False)
Esempio n. 2
0
 def __init__(self, name, init_config, agent_config, instances):
     super(Cpu, self).__init__(name, init_config, agent_config, instances=instances)
     # psutil.cpu_percent and psutil.cpu_times_percent are called in
     # __init__ because the first time these two functions are called with
     # interval = 0.0 or None, it will return a meaningless 0.0 value
     # which you are supposed to ignore.
     psutil.cpu_percent(interval=None, percpu=False)
     psutil.cpu_times_percent(interval=None, percpu=False)
Esempio n. 3
0
 def __init__(self, name, init_config, agent_config):
     super(Cpu, self).__init__(name, init_config, agent_config)
     process_fs_path_config = init_config.get('process_fs_path', None)
     if process_fs_path_config:
         psutil.PROCFS_PATH = process_fs_path_config
         self.log.debug('The path of the process filesystem set to %s', process_fs_path_config)
     else:
         self.log.debug('The process_fs_path not set. Use default path: /proc')
     # psutil.cpu_percent and psutil.cpu_times_percent are called in
     # __init__ because the first time these two functions are called with
     # interval = 0.0 or None, it will return a meaningless 0.0 value
     # which you are supposed to ignore.
     psutil.cpu_percent(interval=None, percpu=False)
     psutil.cpu_times_percent(interval=None, percpu=False)
Esempio n. 4
0
    def check(self, instance):
        """Capture cpu stats
        """
        num_of_metrics = 0
        dimensions = self._set_dimensions(None, instance)

        if instance is not None:
            send_rollup_stats = instance.get("send_rollup_stats", False)
        else:
            send_rollup_stats = False

        cpu_stats = psutil.cpu_times_percent(interval=None, percpu=False)
        cpu_times = psutil.cpu_times(percpu=False)
        cpu_perc = psutil.cpu_percent(interval=None, percpu=False)

        data = {
            'cpu.user_perc': cpu_stats.user + cpu_stats.nice,
            'cpu.system_perc':
            cpu_stats.system + cpu_stats.irq + cpu_stats.softirq,
            'cpu.wait_perc': cpu_stats.iowait,
            'cpu.idle_perc': cpu_stats.idle,
            'cpu.stolen_perc': cpu_stats.steal,
            'cpu.percent': cpu_perc,
            'cpu.idle_time': cpu_times.idle,
            'cpu.wait_time': cpu_times.iowait,
            'cpu.user_time': cpu_times.user + cpu_times.nice,
            'cpu.system_time':
            cpu_times.system + cpu_times.irq + cpu_times.softirq
        }

        # Call lscpu command to get cpu frequency
        self._add_cpu_freq(data)

        for key, value in data.items():
            if data[key] is None or instance.get(
                    'cpu_idle_only') and 'idle_perc' not in key:
                continue
            self.gauge(key, value, dimensions)
            num_of_metrics += 1

        if send_rollup_stats:
            self.gauge('cpu.total_logical_cores',
                       psutil.cpu_count(logical=True), dimensions)
            num_of_metrics += 1
        log.debug('Collected {0} cpu metrics'.format(num_of_metrics))
Esempio n. 5
0
    def check(self, instance):
        """Capture cpu stats
        """
        num_of_metrics = 0
        dimensions = self._set_dimensions(None, instance)

        if instance is not None:
            send_rollup_stats = instance.get("send_rollup_stats", False)
        else:
            send_rollup_stats = False

        cpu_stats = psutil.cpu_times_percent(interval=None, percpu=False)
        cpu_times = psutil.cpu_times(percpu=False)
        cpu_perc = psutil.cpu_percent(interval=None, percpu=False)

        data = {'cpu.user_perc': cpu_stats.user + cpu_stats.nice,
                'cpu.system_perc': cpu_stats.system + cpu_stats.irq + cpu_stats.softirq,
                'cpu.wait_perc': cpu_stats.iowait,
                'cpu.idle_perc': cpu_stats.idle,
                'cpu.stolen_perc': cpu_stats.steal,
                'cpu.percent': cpu_perc,
                'cpu.idle_time': cpu_times.idle,
                'cpu.wait_time': cpu_times.iowait,
                'cpu.user_time': cpu_times.user + cpu_times.nice,
                'cpu.system_time': cpu_times.system + cpu_times.irq + cpu_times.softirq}

        # Call lscpu command to get cpu frequency
        self._add_cpu_freq(data)

        for key, value in data.items():
            if data[key] is None or instance.get('cpu_idle_only') and 'idle_perc' not in key:
                continue
            self.gauge(key, value, dimensions)
            num_of_metrics += 1

        if send_rollup_stats:
            self.gauge('cpu.total_logical_cores', psutil.cpu_count(logical=True), dimensions)
            num_of_metrics += 1
        log.debug('Collected {0} cpu metrics'.format(num_of_metrics))