Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 84dff82

Browse files
committed
Add advanced stats support for request_time MeetMe#167
1 parent 6ee2653 commit 84dff82

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

newrelic_plugin_agent/plugins/nginx.py

+19-12
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99

1010
LOGGER = logging.getLogger(__name__)
1111

12-
PATTERN = re.compile(r'^Active connections\:\s(?P<connections>\d+)\s+\n'
13-
r'server accepts handled requests\n\s+(?P<accepts>\d+)'
14-
r'\s+(?P<handled>\d+)\s+(?P<requests>\d+)\s+\nReading\:'
15-
r'\s+(?P<reading>\d+)\s+Writing\:\s+(?P<writing>\d+)'
16-
r'\s+Waiting\:\s+(?P<waiting>\d+)')
12+
PATTERN = re.compile(r'^Active connections: (?P<connections>\d+)\s+[\w ]+\n'
13+
r'\s+(?P<accepts>\d+)'
14+
r'\s+(?P<handled>\d+)'
15+
r'\s+(?P<requests>\d+)'
16+
r'(\s+(?P<time>\d+)|)'
17+
r'\s+Reading:\s+(?P<reading>\d+)'
18+
r'\s+Writing:\s+(?P<writing>\d+)'
19+
r'\s+Waiting:\s+(?P<waiting>\d+)')
1720

1821

1922
class Nginx(base.HTTPStatsPlugin):
@@ -26,17 +29,19 @@ class Nginx(base.HTTPStatsPlugin):
2629
'accepts': 'Requests/Accepted',
2730
'handled': 'Requests/Handled',
2831
'requests': 'Totals/Requests',
32+
'time': 'Requests/Duration',
2933
'reading': 'Connections/Reading',
3034
'writing': 'Connections/Writing',
3135
'waiting': 'Connections/Waiting'}
3236

3337
TYPES = {'connections': '',
34-
'accepts': '',
35-
'handled': '',
36-
'requests': '',
37-
'reading': '',
38-
'writing': '',
39-
'waiting': ''}
38+
'accepts': '',
39+
'handled': '',
40+
'requests': '',
41+
'reading': '',
42+
'time': 'seconds',
43+
'writing': '',
44+
'waiting': ''}
4045

4146
def add_datapoints(self, stats):
4247
"""Add all of the data points for a node
@@ -50,10 +55,12 @@ def add_datapoints(self, stats):
5055
if matches:
5156
for key in self.KEYS.keys():
5257
try:
53-
value = int(matches.group(key))
58+
value = int(matches.group(key) or 0)
5459
except (IndexError, ValueError):
5560
value = 0
5661
if key in self.GAUGES:
5762
self.add_gauge_value(self.KEYS[key], '', value)
5863
else:
5964
self.add_derive_value(self.KEYS[key], '', value)
65+
else:
66+
LOGGER.debug('Stats output: %r', stats)

0 commit comments

Comments
 (0)