forked from danmichaelo/croptool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-server.py
More file actions
20 lines (18 loc) · 726 Bytes
/
check-server.py
File metadata and controls
20 lines (18 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python
# Why this script? See https://phabricator.wikimedia.org/T104799
from __future__ import print_function
import requests
import subprocess
from datetime import datetime
# 1) Gather data
res = requests.get('https://tools.wmflabs.org/croptool/server-statistics')
res.text.split('\n')
items = [line.split(': ') for line in res.text.split('\n')]
items = {i[0]: i[1] for i in items if len(i) == 2}
conncount = int(items.get('fastcgi.active-requests', 0))
# 2) Restart if necessary
if conncount > 150:
now = datetime.now()
now = now.replace(microsecond=0, second=0)
print('{} Restarted. Connection count was: {}\n'.format(now.isoformat(), conncount))
subprocess.call(['webservice', 'restart'])