Last active
August 8, 2021 22:46
-
-
Save Elwell/620b9521dbf51727b82b92c2d861cf81 to your computer and use it in GitHub Desktop.
robinhood rbh-report to influxdb parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bravo:~ # cat rbh2influx.py | |
#!/usr/bin/python3 | |
# rbh-report to influx publisher | |
# Andrew Elwell <[email protected]>, July 2020 | |
import time | |
import subprocess | |
import csv | |
import requests | |
mount_name = {'fs1': 'foofs', 'fs2': 'barfs', | |
'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 = '' | |
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) | |
) | |
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) | |
) | |
#print(data) | |
requests.post('https://influx.example.org:8086/write?db=lustre&precision=s', data, auth=('username','password')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment