-
Notifications
You must be signed in to change notification settings - Fork 2
/
opentracker-stats.py
executable file
·74 lines (54 loc) · 1.73 KB
/
opentracker-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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python
# Is necessary to install python-lxml and curl packages
from lxml import etree
import requests
import time
import os
# InfluxDB server and port (IP:PORT or domain:port)
influxdb_server = 'MyInfluxDB.com:8086'
# Uncomment the line below if you use 'https://' to access to your server
influxdb_server = 'https://' + influxdb_server + "/write"
# Uncomment the line below if you use 'http://' to access to your server
#influxdb_server = 'http://' + influxdb_server + "/write"
# InfluxDB Database name
database = 'testdb'
# InfluxDB Auth
username = 'influx-user'
password = 'AtB73HeTqp'
# OpenTracker statistics url
opentracker_url = 'http://mytracker:6969/stats?mode=everything'
# Data query interval in seconds:
wait = 30
while True:
status = etree.parse(opentracker_url)
stats = status.getroot()
# Uptime
uptime = stats[2].text
# Torrents
torrents = stats[3][0].text
# Peers
peers = stats[4][0].text
# Seeds
seeds = stats[5][0].text
# Completed downloads
completed = stats[6][0].text
# leechers
leechers = int(peers) - int(seeds)
# Uncomment to debug
#print("Uptime: " + uptime)
#print("Torrents: " + torrents)
#print("Peers: " + peers)
#print("Seeds: " + seeds)
#print("Leechers: " + str(leechers))
#print("Completed: " + completed)
# Write to InfluxDB
params = (
('db', database),
('precision', 's'),
('u', username),
('p', password),
)
data = 'uptime value=' + uptime + '\ntorrents value=' + torrents + '\npeers value=' + peers + '\nseeds value=' + seeds + '\nleechers value=' + str(leech$
response = requests.post(influxdb_server, params=params, data=data)
# wait for 15 seconds
time.sleep(wait)