1 | # -*- coding: utf-8 -*- |
||
0 ignored issues
–
show
|
|||
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 | """ |
||
0 ignored issues
–
show
A suspicious escape sequence
\/ was found. Did you maybe forget to add an r prefix?
Escape sequences in Python are generally interpreted according to rules similar
to standard C. Only if strings are prefixed with The escape sequence that was used indicates that you might have intended to write a regular expression. Learn more about the available escape sequences. in the Python documentation.
Loading history...
|
|||
21 | SystemV AMP |
||
22 | =========== |
||
23 | |||
24 | Monitor the state of the Syste V init system and service. |
||
25 | |||
26 | How to read the stats |
||
27 | --------------------- |
||
28 | |||
29 | Running: Number of running services. |
||
30 | Stopped: Number of stopped services. |
||
31 | Upstart: Number of service managed by Upstart. |
||
32 | |||
33 | Source reference: http://askubuntu.com/questions/407075/how-to-read-service-status-all-results |
||
0 ignored issues
–
show
|
|||
34 | |||
35 | Configuration file example |
||
36 | -------------------------- |
||
37 | |||
38 | [amp_systemv] |
||
39 | # Systemv |
||
40 | enable=true |
||
41 | regex=\/sbin\/init |
||
42 | refresh=60 |
||
43 | one_line=true |
||
44 | service_cmd=/usr/bin/service --status-all |
||
45 | """ |
||
46 | |||
47 | from subprocess import check_output, STDOUT |
||
0 ignored issues
–
show
|
|||
48 | |||
49 | from glances.logger import logger |
||
0 ignored issues
–
show
|
|||
50 | from glances.compat import iteritems |
||
0 ignored issues
–
show
|
|||
51 | from glances.amps.glances_amp import GlancesAmp |
||
0 ignored issues
–
show
|
|||
52 | |||
53 | |||
54 | class Amp(GlancesAmp): |
||
55 | """Glances' Systemd AMP.""" |
||
56 | |||
57 | NAME = 'SystemV' |
||
58 | VERSION = '1.0' |
||
59 | DESCRIPTION = 'Get services list from service (initd)' |
||
60 | AUTHOR = 'Nicolargo' |
||
61 | EMAIL = '[email protected]' |
||
62 | |||
63 | # def __init__(self, args=None): |
||
64 | # """Init the AMP.""" |
||
65 | # super(Amp, self).__init__(args=args) |
||
66 | |||
67 | def update(self, process_list): |
||
0 ignored issues
–
show
|
|||
68 | """Update the AMP""" |
||
69 | # Get the systemctl status |
||
70 | logger.debug('{}: Update stats using service {}'.format(self.NAME, self.get('service_cmd'))) |
||
71 | try: |
||
72 | res = check_output(self.get('service_cmd').split(), stderr=STDOUT).decode('utf-8') |
||
0 ignored issues
–
show
|
|||
73 | except OSError as e: |
||
0 ignored issues
–
show
The name
e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[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...
|
|||
74 | logger.debug('{}: Error while executing service ({})'.format(self.NAME, e)) |
||
75 | else: |
||
76 | status = {'running': 0, 'stopped': 0, 'upstart': 0} |
||
77 | # For each line |
||
78 | for r in res.split('\n'): |
||
0 ignored issues
–
show
The name
r does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[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...
|
|||
79 | # Split per space .* |
||
80 | l = r.split() |
||
0 ignored issues
–
show
The name
l does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[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...
|
|||
81 | if len(l) < 4: |
||
82 | continue |
||
83 | if l[1] == '+': |
||
84 | status['running'] += 1 |
||
85 | elif l[1] == '-': |
||
86 | status['stopped'] += 1 |
||
87 | elif l[1] == '?': |
||
88 | status['upstart'] += 1 |
||
89 | # Build the output (string) message |
||
90 | output = 'Services\n' |
||
91 | for k, v in iteritems(status): |
||
0 ignored issues
–
show
The name
v does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[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...
|
|||
92 | output += '{}: {}\n'.format(k, v) |
||
93 | self.set_result(output, separator=' ') |
||
94 | |||
95 | return self.result() |
||
96 |
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.