bundles/zfs: add per-dataset metrics
This commit is contained in:
parent
9cc324f84c
commit
1c10be5cdc
5 changed files with 792 additions and 1 deletions
51
bundles/zfs/files/telegraf-per-dataset
Normal file
51
bundles/zfs/files/telegraf-per-dataset
Normal file
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from subprocess import check_output
|
||||
|
||||
pools = check_output(
|
||||
['/usr/sbin/zpool', 'list', '-Hpo', 'name,free,size'],
|
||||
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():
|
||||
name, free, total = line.split()
|
||||
|
||||
zpools[name] = {
|
||||
'free': free,
|
||||
'total': total,
|
||||
}
|
||||
|
||||
print('zfs_pool,pool={} size={}i,free={}i'.format(name, total, free))
|
||||
|
||||
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,
|
||||
))
|
|
@ -44,6 +44,9 @@ files = {
|
|||
'svc_systemd:zfs-zed:restart'
|
||||
},
|
||||
},
|
||||
'/usr/local/sbin/telegraf-per-dataset': {
|
||||
'mode': '0755',
|
||||
},
|
||||
'/usr/local/sbin/zfs-auto-snapshot': {
|
||||
'mode': '0755',
|
||||
},
|
||||
|
|
|
@ -84,9 +84,18 @@ if node.has_bundle('telegraf'):
|
|||
'builtin': {
|
||||
'zfs': [{
|
||||
'poolMetrics': True,
|
||||
'datasetMetrics': True,
|
||||
}],
|
||||
},
|
||||
'exec': {
|
||||
'zfs-dataset': {
|
||||
'commands': ['sudo /usr/local/sbin/telegraf-per-dataset'],
|
||||
'data_format': 'influx',
|
||||
'timeout': '5s',
|
||||
},
|
||||
},
|
||||
},
|
||||
'sudo_commands': {
|
||||
'/usr/local/sbin/telegraf-per-dataset',
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue