-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path12-log_stats.py
30 lines (24 loc) · 880 Bytes
/
12-log_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
'''Task 12's module.
'''
from pymongo import MongoClient
def print_nginx_request_logs(nginx_collection):
'''Prints stats about Nginx request logs.
'''
print('{} logs'.format(nginx_collection.count_documents({})))
print('Methods:')
methods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE']
for method in methods:
req_count = len(list(nginx_collection.find({'method': method})))
print('\tmethod {}: {}'.format(method, req_count))
status_checks_count = len(list(
nginx_collection.find({'method': 'GET', 'path': '/status'})
))
print('{} status check'.format(status_checks_count))
def run():
'''Provides some stats about Nginx logs stored in MongoDB.
'''
client = MongoClient('mongodb://127.0.0.1:27017')
print_nginx_request_logs(client.logs.nginx)
if __name__ == '__main__':
run()