summaryrefslogtreecommitdiff
path: root/tracker.jordan.im/update-stats.py
diff options
context:
space:
mode:
Diffstat (limited to 'tracker.jordan.im/update-stats.py')
-rwxr-xr-xtracker.jordan.im/update-stats.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tracker.jordan.im/update-stats.py b/tracker.jordan.im/update-stats.py
new file mode 100755
index 0000000..bb6a977
--- /dev/null
+++ b/tracker.jordan.im/update-stats.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python3
+
+import fileinput
+import subprocess
+import sys
+
+INDEX_PATH = '/var/www/html/tracker.jordan.im/index.html'
+
+stats = dict.fromkeys(['torrents', 'connections', 'uptime'])
+
+conn = subprocess.run(
+ ['curl',
+ 'http://127.0.0.1:6969/stats?format=txt&mode=conn'],
+ stdout=subprocess.PIPE,
+)
+conn = conn.stdout.decode("utf-8").split('\n')
+stats['uptime'] = int(int(conn[2].split()[0]) / 3600)
+stats['connections'] = conn[3].split()[2]
+
+bare = subprocess.run(
+ ['curl', 'http://127.0.0.1:6969/stats?format=txt'],
+ stdout=subprocess.PIPE
+)
+bare = bare.stdout.decode("utf-8").split('\n')
+stats['torrents'] = bare[2].split()[2]
+
+s = (
+ f'The tracker has been online for {stats["uptime"]} hrs, '
+ f'serving {stats["torrents"]} torrents '
+ f'with {stats["connections"]} connections per second.\n'
+)
+
+for line in fileinput.input([INDEX_PATH], inplace=True):
+ if line.strip().startswith('The tracker has been'):
+ line = s
+ sys.stdout.write(line)