-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrbh2influx.py
executable file
·115 lines (109 loc) · 5.22 KB
/
rbh2influx.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/python3
# rbh-report to influx publisher
# Andrew Elwell <[email protected]>, July 2020
import time
import subprocess
import csv
import requests
askapgroups = ['askap', 'askaprt', 'casda']
mwagroups = ['mwaops', 'mwasci', 'mwavcs', 'mwaeor']
mount_name = {'askapfs1': 'askapbuffer', 'snx11038': 'scratch',
'astrofs': 'astro', 'pgfs': 'group',
'askapfs2': 'askapingest', 'testfs': 'testfs'
}
def parsemounts():
"""See which lustre filesystems are currently mounted"""
filesystems = []
with open('/proc/mounts', 'r') as mounts:
for line in mounts:
device, mount, fstype, crap = line.split(maxsplit=3)
if fstype == 'lustre':
fsname = device.split(':')[-1].lstrip('/')
#print(mount, device, fsname)
filesystems.append(fsname)
return filesystems
for fs in parsemounts():
data = ''
askapout = ''
mwaout = ''
rbh=subprocess.check_output(['/usr/sbin/rbh-report',
'-f', '/etc/robinhood.d/'+ fs +'.conf',
'--group-info' , '--csv', '--no-header', '-S']
).decode('utf8').splitlines()
ts = time.time()
cols = ['group','user','type','count','volume','spc_used','avg_size']
reader = csv.DictReader(rbh,cols,skipinitialspace=True)
for row in reader:
if int(row['count']) > 0:
data += "robinhood,fs={},mount={},group={},user={},type={} count={},volume={},spc_used={},avg_size={} {}\n".format(
fs, mount_name[fs], row['group'], row['user'],
row['type'], row['count'], row['volume'], row['spc_used'],
row['avg_size'],int(ts)
)
if row['group'] in askapgroups:
askapout += "robinhood,fs={},mount={},group={},user={},type={} count={},volume={},spc_used={},avg_size={}\n".format(
fs, mount_name[fs], row['group'], row['user'],
row['type'], row['count'], row['volume'],
row['spc_used'], row['avg_size']
)
if row['group'] in mwagroups:
mwaout += "robinhood,fs={},mount={},group={},user={},type={} count={},volume={},spc_used={},avg_size={}\n".format(
fs, mount_name[fs], row['group'], row['user'],
row['type'], row['count'], row['volume'],
row['spc_used'], row['avg_size']
)
rbh=subprocess.check_output(['/usr/sbin/rbh-report',
'-f', '/etc/robinhood.d/'+ fs +'.conf',
'--group-info' , '--csv', '--no-header']
).decode('utf8').splitlines()
ts = time.time()
cols = ['group','type','count','volume','spc_used','avg_size']
reader = csv.DictReader(rbh,cols,skipinitialspace=True)
for row in reader:
if int(row['count']) > 0:
data += "rbh-summary,fs={},mount={},group={},type={} count={},volume={},spc_used={},avg_size={} {}\n".format(
fs, mount_name[fs], row['group'], row['type'],
row['count'], row['volume'], row['spc_used'],
row['avg_size'], int(ts)
)
if row['group'] in askapgroups:
askapout += "rbh-summary,fs={},mount={},group={},type={} count={},volume={},spc_used={},avg_size={}\n".format(
fs, mount_name[fs], row['group'], row['type'],
row['count'], row['volume'],
row['spc_used'], row['avg_size']
)
if row['group'] in mwagroups:
mwaout += "rbh-summary,fs={},mount={},group={},type={} count={},volume={},spc_used={},avg_size={}\n".format(
fs, mount_name[fs], row['group'], row['type'],
row['count'], row['volume'],
row['spc_used'], row['avg_size']
)
#print(data)
requests.post('https://influx2.pawsey.org.au:8086/write?db=lustre&precision=s', data, auth=('USERNAME','PASSWORD'))
if askapout:
#print (askapout)
try:
r = requests.post('REDACTED_ASKAP_SERVER/write?db=pawsey_lustre&precision=s',
data=askapout, timeout=1.5,
auth=('REDACTED_ASKAP_USER', 'REDACTED_ASKAP_KEY')
)
#print(r.status_code)
except requests.Timeout:
#print('DEBUG: Request timed out to ASKAP')
pass
except requests.ConnectionError as err:
#print('DEBUG: Connection error to ASKAP:',err)
pass
if mwaout:
try:
#print (mwaout)
r = requests.post('REDACTED_MWA_SERVERwrite?db=lustre&precision=s', data=mwaout,timeout=1.5)
#print('DEBUG: return code = {}'.format(r.status_code))
#print('DEBUG: headers = {}'.format(r.headers))
#print(r.reason)
except requests.Timeout:
#print('DEBUG: Request timed out to MWA')
pass
except requests.ConnectionError as err:
#print('DEBUG: Connection error to MWA: ',err)
pass