Created
May 29, 2019 15:03
-
-
Save ddimick/2baf45daba634bc7396e5d0a456a49e9 to your computer and use it in GitHub Desktop.
Revisions
-
ddimick created this gist
May 29, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ #!/usr/bin/env python # Runs '/sbin/zpool list -Hp' and outputs an InfluxDB-compatible JSON array. Use with telegraf inputs.exec. # Sample telegraf.conf config snippet. # [[inputs.exec]] # commands = [ # "/usr/local/bin/zpool_list.py" # ] # data_format = "influx" import socket from subprocess import check_output columns = ['name', 'size', 'alloc', 'free', 'expandsz', 'frag', 'cap', 'dedup', 'health', 'altroot'] health = {'ONLINE':0, 'DEGRADED':11, 'OFFLINE':21, 'UNAVAIL':22, 'FAULTED':23, 'REMOVED':24} stdout = check_output(['/sbin/zpool', 'list', '-Hp']).split('\n') parsed_stdout = list(map(lambda x: dict(zip(columns,x.split('\t'))), stdout))[:-1] for pool in parsed_stdout: influxlp = 'zfs_pool,host=' + socket.gethostname() + ',pool=' + pool['name'] + ' ' for counter, item in enumerate(pool): if item == 'name': continue if item in ['size', 'alloc', 'free', 'frag', 'cap']: pool[item] = int(pool[item]) if item in ['dedup']: pool[item] = float(pool[item]) if item == 'health': pool[item] = health[pool[item]] if pool[item] == '-' or item == 'expandsz': pool[item] = '"' + pool[item] + '"' influxlp += item + '=' + str(pool[item]) if counter < (len(pool) - 1): influxlp += ',' influxlp += ' ' + check_output(['date', '+%s%N']) print(influxlp.strip())