# Path: myDevices/utils/logger.py
# def exception(message):
#     if checkFlood(message):
#         return
#     LOGGER.exception(message)


import psutil
import os
from glob import glob
from time import sleep
from myDevices.utils.logger import exception

class CpuInfo(object):
    """Class for retrieving CPU info"""

    @staticmethod
    def get_cpu_info():
        """Return CPU temperature, load average and usage info as a dict"""
        info = {}
        info['temperature'] = self.get_cpu_temp()
        info["loadavg"] = self.get_load_avg()
        info["usage"] = self.get_cpu_usage()
        return info

    @staticmethod
    def get_cpu_usage():
        """Return dict with overall CPU usage"""
        usage = {}
        try:
            fields = ('user', 'system', 'idle', 'nice', 'iowait', 'irq', 'softirq', 'steal')
            usage = {key: value for key, value in psutil.cpu_times()._asdict().items() if key in fields}
            usage['total'] = round(sum(usage.values()), 2)
        except:

# Path: myDevices/utils/logger.py
# def exception(message):
#     if checkFlood(message):
#         return
#     LOGGER.exception(message)


# Path: myDevices/system/cpu.py
import psutil
import os
from glob import glob
from time import sleep
from myDevices.utils.logger import exception


class CpuInfo(object):
    """Class for retrieving CPU info"""

    @staticmethod
    def get_cpu_info():
        """Return CPU temperature, load average and usage info as a dict"""
        info = {}
        info['temperature'] = self.get_cpu_temp()
        info["loadavg"] = self.get_load_avg()
        info["usage"] = self.get_cpu_usage()
        return info

    @staticmethod
    def get_cpu_usage():
        """Return dict with overall CPU usage"""
        usage = {}
        try:
            fields = ('user', 'system', 'idle', 'nice', 'iowait', 'irq', 'softirq', 'steal')
            usage = {key: value for key, value in psutil.cpu_times()._asdict().items() if key in fields}
            usage['total'] = round(sum(usage.values()), 2)
        except:

            exception('Error getting CPU usage info')