Skip to content

Commit

Permalink
Added 99th percentile
Browse files Browse the repository at this point in the history
  • Loading branch information
abhisheknsit committed Sep 25, 2018
1 parent 13e10a8 commit ec709fd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:2.7.14-alpine

WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "./locust_exporter.py"]
25 changes: 15 additions & 10 deletions locust_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import requests
import sys
import time
import os

class LocustCollector(object):
def __init__(self, ep):
Expand All @@ -18,7 +19,7 @@ def collect(self):
try:
response = requests.get(url).content.decode('Utf-8')
except requests.exceptions.ConnectionError:
print("Failed to connect to Locust:", url)
print "Failed to connect to Locust:", url
exit(2)

response = json.loads(response)
Expand All @@ -29,9 +30,17 @@ def collect(self):
metric.add_sample('locust_user_count', value=response['user_count'], labels={})
yield metric

metric = Metric('locust_response_time_95', 'Response Time 95th Percentile', 'gauge')
metric.add_sample('locust_response_time_95', value=response["current_response_time_percentile_95"], labels={})
yield metric
if 'current_response_time_percentile_99' in response:
metric = Metric('locust_response_time_99', 'Response Time 99th Percentile', 'gauge')
metric.add_sample('locust_response_time_99', value=response["current_response_time_percentile_99"], labels={})
yield metric

metric = Metric('locust_errors', 'Locust requests errors', 'gauge')
for err in response['errors']:
metric.add_sample('locust_errors', value=err['occurences'], labels={'path':err['name'], 'method':err['method']})
metric.add_sample('locust_errors', value=err['occurences'], labels={'path':err['name'], 'method':err['method'], 'error': err['error']})
yield metric

if 'slave_count' in response:
Expand Down Expand Up @@ -59,14 +68,10 @@ def collect(self):

if __name__ == '__main__':
# Usage: locust_exporter.py <port> <locust_host:port>
if len(sys.argv) != 3:
print('Usage: locust_exporter.py <port> <locust_host:port>')
exit(1)
else:
try:
start_http_server(int(sys.argv[1]))
REGISTRY.register(LocustCollector(str(sys.argv[2])))
print("Connecting to locust on: " + sys.argv[2])
while True: time.sleep(1)
start_http_server(int(os.environ.get('LISTENER_PORT', 8080)))
REGISTRY.register(LocustCollector(os.environ['LOCUST']))
print "Connecting to locust on: " + os.environ['LOCUST']
while True: time.sleep(1000)
except KeyboardInterrupt:
exit(0)
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
prometheus_client
requests

0 comments on commit ec709fd

Please sign in to comment.