Test Failed
Push — develop ( d7cf39...faa4bd )
by Nicolas
04:34 queued 10s
created

glances/plugins/glances_processcount.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
"""Process count plugin."""
21
22
from glances.processes import glances_processes
0 ignored issues
show
import missing from __future__ import absolute_import
Loading history...
23
from glances.plugins.glances_plugin import GlancesPlugin
0 ignored issues
show
import missing from __future__ import absolute_import
Loading history...
24
25
# Define the history items list
26
items_history_list = [{'name': 'total',
0 ignored issues
show
Coding Style Naming introduced by
The name items_history_list does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
27
                       'description': 'Total number of processes',
28
                       'y_unit': ''},
29
                      {'name': 'running',
30
                       'description': 'Total number of running processes',
31
                       'y_unit': ''},
32
                      {'name': 'sleeping',
33
                       'description': 'Total number of sleeping processes',
34
                       'y_unit': ''},
35
                      {'name': 'thread',
36
                       'description': 'Total number of threads',
37
                       'y_unit': ''}]
38
39
40
class Plugin(GlancesPlugin):
41
    """Glances process count plugin.
42
43
    stats is a list
44
    """
45
46
    sort_for_human = {'io_counters': 'disk IO',
47
                      'cpu_percent': 'CPU consumption',
48
                      'memory_percent': 'memory consumption',
49
                      'cpu_times': 'process time',
50
                      'username': 'user name',
51
                      'name': 'process name',
52
                      None: 'None'}
53
54
    def __init__(self, args=None, config=None):
55
        """Init the plugin."""
56
        super(Plugin, self).__init__(args=args,
57
                                     config=config,
58
                                     items_history_list=items_history_list)
59
60
        # We want to display the stat in the curse interface
61
        self.display_curse = True
62
63
        # Note: 'glances_processes' is already init in the glances_processes.py script
0 ignored issues
show
This line is too long as per the coding-style (86/80).

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

Loading history...
64
65
    def update(self):
66
        """Update processes stats using the input method."""
67
        # Init new stats
68
        stats = self.get_init_value()
69
70
        if self.input_method == 'local':
71
            # Update stats using the standard system lib
72
            # Here, update is call for processcount AND processlist
73
            glances_processes.update()
74
75
            # Return the processes count
76
            stats = glances_processes.getcount()
77
        elif self.input_method == 'snmp':
78
            # Update stats using SNMP
79
            # Not avalaible
80
            pass
81
82
        # Update the stats
83
        self.stats = stats
84
85
        return self.stats
86
87
    def msg_curse(self, args=None, max_width=None):
88
        """Return the dict to display in the curse interface."""
89
        # Init the return message
90
        ret = []
91
92
        # Only process if stats exist and display plugin enable...
93
        if args.disable_process:
94
            msg = "PROCESSES DISABLED (press 'z' to display)"
95
            ret.append(self.curse_add_line(msg))
96
            return ret
97
98
        if not self.stats:
99
            return ret
100
101
        # Display the filter (if it exists)
102
        if glances_processes.process_filter is not None:
103
            msg = 'Processes filter:'
104
            ret.append(self.curse_add_line(msg, "TITLE"))
105
            msg = ' {} '.format(glances_processes.process_filter)
106
            if glances_processes.process_filter_key is not None:
107
                msg += 'on column {} '.format(glances_processes.process_filter_key)
0 ignored issues
show
This line is too long as per the coding-style (83/80).

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

Loading history...
108
            ret.append(self.curse_add_line(msg, "FILTER"))
109
            msg = '(\'ENTER\' to edit, \'E\' to reset)'
110
            ret.append(self.curse_add_line(msg))
111
            ret.append(self.curse_new_line())
112
113
        # Build the string message
114
        # Header
115
        msg = 'TASKS'
116
        ret.append(self.curse_add_line(msg, "TITLE"))
117
        # Compute processes
118
        other = self.stats['total']
119
        msg = '{:>4}'.format(self.stats['total'])
120
        ret.append(self.curse_add_line(msg))
121
122
        if 'thread' in self.stats:
123
            msg = ' ({} thr),'.format(self.stats['thread'])
124
            ret.append(self.curse_add_line(msg))
125
126
        if 'running' in self.stats:
127
            other -= self.stats['running']
128
            msg = ' {} run,'.format(self.stats['running'])
129
            ret.append(self.curse_add_line(msg))
130
131
        if 'sleeping' in self.stats:
132
            other -= self.stats['sleeping']
133
            msg = ' {} slp,'.format(self.stats['sleeping'])
134
            ret.append(self.curse_add_line(msg))
135
136
        msg = ' {} oth '.format(other)
137
        ret.append(self.curse_add_line(msg))
138
139
        # Display sort information
140
        try:
141
            sort_human = self.sort_for_human[glances_processes.sort_key]
142
        except KeyError:
143
            sort_human = glances_processes.sort_key
144
        if glances_processes.auto_sort:
145
            msg = 'sorted automatically'
146
            ret.append(self.curse_add_line(msg))
147
            msg = ' by {}'.format(sort_human)
148
        else:
149
            msg = 'sorted by {}'.format(sort_human)
150
        ret.append(self.curse_add_line(msg))
151
152
        # Return the message with decoration
153
        return ret
154