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

glances.plugins.glances_core   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 74
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Plugin.update() 0 31 4
A Plugin.__init__() 0 7 1
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
introduced by
import missing from __future__ import absolute_import
Loading history...
23
24
import psutil
0 ignored issues
show
introduced by
import missing from __future__ import absolute_import
Loading history...
introduced by
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
Coding Style introduced by
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
Coding Style introduced by
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