Test Failed
Push — develop ( 66c9ff...e21229 )
by Nicolas
05:06
created

glances/amps/glances_nginx.py (18 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
"""
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 r or R are they interpreted as regular expressions.

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
Nginx AMP
22
=========
23
24
Monitor the Nginx process using the status page.
25
26
How to read the stats
27
---------------------
28
29
Active connections – Number of all open connections. This doesn’t mean number of users.
0 ignored issues
show
This line is too long as per the coding-style (87/80).

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

Loading history...
30
A single user, for a single pageview can open many concurrent connections to your server.
0 ignored issues
show
This line is too long as per the coding-style (89/80).

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

Loading history...
31
Server accepts handled requests – This shows three values.
32
    First is total accepted connections.
33
    Second is total handled connections. Usually first 2 values are same.
34
    Third value is number of and handles requests. This is usually greater than second value.
0 ignored issues
show
This line is too long as per the coding-style (93/80).

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

Loading history...
35
    Dividing third-value by second-one will give you number of requests per connection handled
0 ignored issues
show
This line is too long as per the coding-style (94/80).

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

Loading history...
36
    by Nginx. In above example, 10993/7368, 1.49 requests per connections.
37
Reading – nginx reads request header
38
Writing – nginx reads request body, processes request, or writes response to a client
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...
39
Waiting – keep-alive connections, actually it is active – (reading + writing).
40
This value depends on keepalive-timeout. Do not confuse non-zero waiting value for poor
0 ignored issues
show
This line is too long as per the coding-style (87/80).

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

Loading history...
41
performance. It can be ignored.
42
43
Source reference: https://easyengine.io/tutorials/nginx/status-page/
44
45
Configuration file example
46
--------------------------
47
48
[amp_nginx]
49
# Nginx status page should be enable (https://easyengine.io/tutorials/nginx/status-page/)
0 ignored issues
show
This line is too long as per the coding-style (89/80).

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

Loading history...
50
enable=true
51
regex=\/usr\/sbin\/nginx
52
refresh=60
53
one_line=false
54
status_url=http://localhost/nginx_status
55
"""
56
57
import requests
0 ignored issues
show
import missing from __future__ import absolute_import
Loading history...
Unable to import 'requests'
Loading history...
58
59
from glances.logger import logger
0 ignored issues
show
import missing from __future__ import absolute_import
Loading history...
60
from glances.amps.glances_amp import GlancesAmp
0 ignored issues
show
import missing from __future__ import absolute_import
Loading history...
61
62
63
class Amp(GlancesAmp):
64
    """Glances' Nginx AMP."""
65
66
    NAME = 'Nginx'
67
    VERSION = '1.0'
68
    DESCRIPTION = 'Get Nginx stats from status-page'
69
    AUTHOR = 'Nicolargo'
70
    EMAIL = '[email protected]'
71
72
    # def __init__(self, args=None):
73
    #     """Init the AMP."""
74
    #     super(Amp, self).__init__(args=args)
75
76
    def update(self, process_list):
0 ignored issues
show
The argument process_list seems to be unused.
Loading history...
77
        """Update the AMP"""
78
        # Get the Nginx status
79
        logger.debug('{}: Update stats using status URL {}'.format(self.NAME, self.get('status_url')))
0 ignored issues
show
This line is too long as per the coding-style (102/80).

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

Loading history...
Use formatting in logging functions and pass the parameters as arguments
Loading history...
80
        res = requests.get(self.get('status_url'))
81
        if res.ok:
82
            # u'Active connections: 1 \nserver accepts handled requests\n 1 1 1 \nReading: 0 Writing: 1 Waiting: 0 \n'
0 ignored issues
show
This line is too long as per the coding-style (118/80).

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

Loading history...
83
            self.set_result(res.text.rstrip())
84
        else:
85
            logger.debug('{}: Can not grab status URL {} ({})'.format(self.NAME, self.get('status_url'), res.reason))
0 ignored issues
show
This line is too long as per the coding-style (117/80).

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

Loading history...
Use formatting in logging functions and pass the parameters as arguments
Loading history...
86
87
        return self.result()
88