Пример #1
0
    def __init__(self):
        self.is_available = True
        if not hasattr(psutil, "cpu_freq"):
            self.is_available = False
            logging.debug("cpu_freq is not available from psutil")
            return

        Source.__init__(self)

        self.name = 'Frequency'
        self.measurement_unit = 'MHz'
        self.pallet = ('freq light', 'freq dark', 'freq light smooth',
                       'freq dark smooth')

        # Check if psutil.cpu_freq is available.
        # +1 for average frequency
        self.last_measurement = [0] * len(psutil.cpu_freq(True))
        if psutil.cpu_freq(False):
            self.last_measurement.append(0)

        self.top_freq = psutil.cpu_freq().max
        self.max_freq = self.top_freq

        if self.top_freq == 0.0:
            # If top freq not available, take the current as top
            if max(self.last_measurement) >= 0:
                self.max_freq = max(self.last_measurement)

        self.available_sensors = ['Avg']
        for core_id, _ in enumerate(psutil.cpu_freq(True)):
            self.available_sensors.append("Core " + str(core_id))
Пример #2
0
    def __init__(self):
        Source.__init__(self)

        self.name = 'Power'
        self.measurement_unit = 'W'
        self.pallet = ('power light', 'power dark', 'power light smooth',
                       'power dark smooth')

        self.last_probe_time = time.time()
        self.last_probe = rapl_read()
        if not self.last_probe:
            self.is_available = False
            logging.debug("Power reading is not available")
            return
        self.max_power = 1
        self.last_measurement = [0] * len(self.last_probe)

        multi_sensors = []
        for item in self.last_probe:
            name = item.label
            sensor_count = multi_sensors.count(name)
            multi_sensors.append(name)
            if 'package' not in name:
                name += ",Pkg" + str(sensor_count)
            self.available_sensors.append(name)
Пример #3
0
    def __init__(self):
        Source.__init__(self)

        self.name = 'Fan'
        self.measurement_unit = 'RPM'
        self.pallet = ('fan light', 'fan dark', 'fan light smooth',
                       'fan dark smooth')

        sensors_dict = dict()
        try:
            sensors_dict = psutil.sensors_fans()
        except (AttributeError, IOError):
            logging.debug("Unable to create sensors dict")
            self.is_available = False
            return
        if not sensors_dict:
            self.is_available = False
            return

        for key, value in sensors_dict.items():
            sensor_name = key
            for sensor_idx, sensor in enumerate(value):
                sensor_label = sensor.label

                full_name = ""
                if not sensor_label:
                    full_name = sensor_name + "," + str(sensor_idx)
                else:
                    full_name = sensor_label

                logging.debug("Fan sensor name %s", full_name)

                self.available_sensors.append(full_name)

        self.last_measurement = [0] * len(self.available_sensors)
Пример #4
0
    def __init__(self, temp_thresh=None):
        warnings.filterwarnings(
            'ignore',
            '.*FileNotFound.*',
        )
        if not hasattr(psutil, "sensors_temperatures"):
            self.is_available = False
            logging.debug("cpu temperature is not available from psutil")
            return

        Source.__init__(self)

        self.name = 'Temp'
        self.measurement_unit = 'C'
        self.max_last_temp = 0
        self.pallet = ('temp light', 'temp dark', 'temp light smooth',
                       'temp dark smooth')
        self.alert_pallet = ('high temp light', 'high temp dark',
                             'high temp light smooth', 'high temp dark smooth')

        self.max_temp = 10
        sensors_dict = None
        try:
            sensors_dict = OrderedDict(
                sorted(psutil.sensors_temperatures().items()))
        except IOError:
            logging.debug("Unable to create sensors dict")
            self.is_available = False
            return
        multi_sensors = []
        for key, value in sensors_dict.items():
            sensor_name = "".join(key.title().split(" "))
            for sensor_idx, sensor in enumerate(value):
                sensor_label = sensor.label

                full_name = ""
                if not sensor_label:
                    full_name = sensor_name + "," + str(sensor_idx)
                else:
                    full_name = ("".join(sensor_label.title().split(" ")))
                    sensor_count = multi_sensors.count(full_name)
                    multi_sensors.append(full_name)
                    if ('package' not in full_name.lower()
                            and 'physical' not in full_name.lower()):
                        full_name += ",Pkg" + str(sensor_count)

                logging.debug("Temp sensor name %s", full_name)
                self.available_sensors.append(full_name)

        self.last_measurement = [0] * len(self.available_sensors)

        # Set temperature threshold if a custom one is set
        self.temp_thresh = self.THRESHOLD_TEMP
        if temp_thresh is not None:
            if int(temp_thresh) > 0:
                self.temp_thresh = int(temp_thresh)
                logging.debug("Updated custom threshold to %s",
                              self.temp_thresh)
Пример #5
0
    def update(self):
        sample = OrderedDict(sorted(psutil.sensors_temperatures().items()))
        self.last_measurement = []
        for sensor in sample:
            for minor_sensor in sample[sensor]:
                self.last_measurement.append(minor_sensor.current)

        if self.last_measurement:
            self.max_last_temp = max(self.last_measurement)
            # Call check for hooks
            Source.update(self)
Пример #6
0
    def __init__(self):
        if not hasattr(psutil, "cpu_percent"):
            self.is_available = False
            logging.debug("cpu utilization is not available from psutil")
            return

        Source.__init__(self)

        self.name = 'Util'
        self.measurement_unit = '%'
        self.pallet = ('util light', 'util dark', 'util light smooth',
                       'util dark smooth')

        self.last_measurement = [0] * (psutil.cpu_count() + 1)

        self.available_sensors = ['Avg']
        for core_id in range(psutil.cpu_count()):
            self.available_sensors.append("Core " + str(core_id))
Пример #7
0
    def __init__(self):
        Source.__init__(self)

        self.name = 'Util'
        self.measurement_unit = '%'
        self.pallet = ('util light', 'util dark', 'util light smooth',
                       'util dark smooth')

        try:
            self.last_measurement = [0] * (psutil.cpu_count() + 1)
        except AttributeError:
            logging.debug("cpu_freq is not available from psutil")
            self.is_available = False
            return

        self.available_sensors = ['Avg']
        for core_id in range(psutil.cpu_count()):
            self.available_sensors.append("Core " + str(core_id))