Test Failed
Push — develop ( 3e7080...29e3c5 )
by Nicolas
03:08
created

glances/plugins/glances_core.py (5 issues)

1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of Glances.
4
#
5
# Copyright (C) 2019 Nicolargo <[email protected]>
6
#
7
# Glances is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU Lesser General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Glances is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Lesser General Public License for more details.
16
#
17
# You should have received a copy of the GNU Lesser General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20
"""CPU core plugin."""
21
22
from glances.plugins.glances_plugin import GlancesPlugin
0 ignored issues
show
import missing from __future__ import absolute_import
Loading history...
23
24
import psutil
0 ignored issues
show
import missing from __future__ import absolute_import
Loading history...
Unable to import 'psutil'
Loading history...
25
26
27
class Plugin(GlancesPlugin):
28
    """Glances CPU core plugin.
29
30
    Get stats about CPU core number.
31
32
    stats is integer (number of core)
33
    """
34
35
    def __init__(self, args=None, config=None):
36
        """Init the plugin."""
37
        super(Plugin, self).__init__(args=args, config=config)
38
39
        # We dot not want to display the stat in the curse interface
40
        # The core number is displayed by the load plugin
41
        self.display_curse = False
42
43
    def update(self):
44
        """Update core stats.
45
46
        Stats is a dict (with both physical and log cpu number) instead of a integer.
0 ignored issues
show
This line is too long as per the coding-style (85/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
47
        """
48
        # Init new stats
49
        stats = self.get_init_value()
50
51
        if self.input_method == 'local':
52
            # Update stats using the standard system lib
53
54
            # The psutil 2.0 include psutil.cpu_count() and psutil.cpu_count(logical=False)
0 ignored issues
show
This line is too long as per the coding-style (91/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
55
            # Return a dict with:
56
            # - phys: physical cores only (hyper thread CPUs are excluded)
57
            # - log: logical CPUs in the system
58
            # Return None if undefine
59
            try:
60
                stats["phys"] = psutil.cpu_count(logical=False)
61
                stats["log"] = psutil.cpu_count()
62
            except NameError:
63
                self.reset()
64
65
        elif self.input_method == 'snmp':
66
            # Update stats using SNMP
67
            # http://stackoverflow.com/questions/5662467/how-to-find-out-the-number-of-cpus-using-snmp
68
            pass
69
70
        # Update the stats
71
        self.stats = stats
72
73
        return self.stats
74