2021-06-25 18:04:30 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from subprocess import check_output
|
|
|
|
|
|
|
|
pools = check_output(
|
2021-06-29 13:18:31 +00:00
|
|
|
['/usr/sbin/zpool', 'list', '-Hpo', 'name,allocated,size'],
|
2021-06-25 18:04:30 +00:00
|
|
|
env={
|
|
|
|
'LC_ALL': 'C',
|
|
|
|
},
|
|
|
|
).decode('UTF-8')
|
|
|
|
|
|
|
|
datasets = check_output(
|
|
|
|
['/usr/sbin/zfs', 'list', '-Hpo', 'name,usedbydataset,usedsnap,compressratio'],
|
|
|
|
env={
|
|
|
|
'LC_ALL': 'C',
|
|
|
|
},
|
|
|
|
).decode('UTF-8')
|
|
|
|
|
|
|
|
zpools = {}
|
|
|
|
for line in pools.splitlines():
|
2021-06-29 13:18:31 +00:00
|
|
|
name, used, total = line.split()
|
2021-06-25 18:04:30 +00:00
|
|
|
|
|
|
|
zpools[name] = {
|
2021-06-29 13:18:31 +00:00
|
|
|
'used': used,
|
2021-06-25 18:04:30 +00:00
|
|
|
'total': total,
|
|
|
|
}
|
|
|
|
|
2021-06-29 13:18:31 +00:00
|
|
|
print('zfs_pool,pool={} size={}i,used={}i'.format(name, total, used))
|
2021-06-25 18:04:30 +00:00
|
|
|
|
|
|
|
for line in datasets.splitlines():
|
|
|
|
name, used, usedsnap, compressratio = line.split()
|
|
|
|
|
|
|
|
pool = name.split('/')[0]
|
|
|
|
|
|
|
|
if '/' not in name:
|
|
|
|
# covered by pool metrics above
|
|
|
|
continue
|
|
|
|
|
|
|
|
if pool not in zpools:
|
|
|
|
raise Exception('BUG: {} in datasets, but {} not in pools'.format(name, pool))
|
|
|
|
|
|
|
|
if compressratio[-1] == 'x':
|
|
|
|
compressratio = compressratio[:-1]
|
|
|
|
|
|
|
|
print('zfs_dataset,pool={},dataset={} used={}i,usedsnap={}i,compressratio={}'.format(
|
|
|
|
pool,
|
|
|
|
name,
|
|
|
|
used,
|
|
|
|
usedsnap,
|
|
|
|
compressratio,
|
|
|
|
))
|