-
Notifications
You must be signed in to change notification settings - Fork 0
/
collector.py
35 lines (29 loc) · 840 Bytes
/
collector.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
import urllib2
import sys
import os.path
import time
from datetime import datetime
interval = 10.0
outputFile = 'data.txt'
if len(sys.argv) < 4:
raise Exception("Not enough number of arguments passed")
if len(sys.argv) == 4:
interval = float(sys.argv[3])
address = sys.argv[1] + '/stats'
if os.path.isfile(outputFile):
output = open(outputFile, 'r+')
output.truncate(0)
else:
output = open(outputFile, 'w')
while True:
stats = urllib2.urlopen(address)
line = stats.read().split("\n")
for i in range(len(line)-1):
digit = line[i].split(": ")
if (i == 0):
ts = int(digit[1])
output.write(datetime.utcfromtimestamp(ts).strftime('%H:%M') + "\t")
else:
output.write(digit[1] + "\t")
output.write("\n")
time.sleep(interval)