bundles/grafana: replace the useless builtin of telegraf with something more useful
This commit is contained in:
parent
f6d6ef7aa7
commit
6b641890c3
5 changed files with 299 additions and 23 deletions
47
bundles/smartd/files/telegraf_plugin
Normal file
47
bundles/smartd/files/telegraf_plugin
Normal file
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from subprocess import check_output
|
||||
from json import loads
|
||||
from sys import stderr
|
||||
|
||||
devices = check_output(['smartctl', '--scan']).decode().splitlines()
|
||||
|
||||
for device in devices:
|
||||
device = device.split(' ')[0]
|
||||
|
||||
try:
|
||||
json = loads(check_output(['smartctl', '-n', 'standby', '-A', '--json=c', device]))
|
||||
|
||||
telegraf_output = set()
|
||||
|
||||
if 'power_on_time' in json:
|
||||
telegraf_output.add('power_on_hours={}'.format(json['power_on_time']['hours']))
|
||||
|
||||
if 'temperature' in json:
|
||||
telegraf_output.add('temperature={}'.format(json['temperature']['current']))
|
||||
|
||||
print('smartd_stats,device={device} {values}'.format(
|
||||
device=device,
|
||||
values=','.join(sorted(telegraf_output)),
|
||||
))
|
||||
|
||||
telegraf_output = set()
|
||||
|
||||
if 'nvme_smart_health_information_log' in json:
|
||||
for k, v in json['nvme_smart_health_information_log'].items():
|
||||
telegraf_output.add(f'{k}={v}')
|
||||
|
||||
if 'ata_smart_attributes' in json:
|
||||
for entry in json['ata_smart_attributes']['table']:
|
||||
telegraf_output.add('{}={}'.format(
|
||||
entry['name'],
|
||||
entry['raw']['value'],
|
||||
))
|
||||
|
||||
print('smartd_health,device={device},type={type} {values}'.format(
|
||||
device=device,
|
||||
type=json['device']['type'],
|
||||
values=','.join(sorted(telegraf_output)),
|
||||
))
|
||||
except Exception as e:
|
||||
print(f'{device} {repr(e)}', file=stderr)
|
|
@ -8,6 +8,10 @@ files = {
|
|||
'/usr/local/share/icinga/plugins/check_smart': {
|
||||
'mode': '0755',
|
||||
},
|
||||
'/usr/local/sbin/telegraf-smartd': {
|
||||
'source': 'telegraf_plugin',
|
||||
'mode': '0755',
|
||||
},
|
||||
}
|
||||
|
||||
svc_systemd = {
|
||||
|
|
|
@ -24,6 +24,22 @@ defaults = {
|
|||
},
|
||||
}
|
||||
|
||||
if node.has_bundle('telegraf'):
|
||||
defaults['telegraf'] = {
|
||||
'input_plugins': {
|
||||
'exec': {
|
||||
'smartd': {
|
||||
'commands': ['sudo /usr/local/sbin/telegraf-smartd'],
|
||||
'data_format': 'influx',
|
||||
'timeout': '5s',
|
||||
},
|
||||
},
|
||||
},
|
||||
'sudo_commands': {
|
||||
'/usr/local/sbin/telegraf-smartd',
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@metadata_reactor.provides(
|
||||
'smartd/disks',
|
||||
|
@ -67,29 +83,6 @@ def icinga(metadata):
|
|||
}
|
||||
|
||||
|
||||
@metadata_reactor.provides(
|
||||
'telegraf/input_plugins/builtin/smart',
|
||||
)
|
||||
def telegraf(metadata):
|
||||
if not node.has_bundle('telegraf'):
|
||||
raise DoNotRunAgain
|
||||
|
||||
if metadata.get('smartd/disks', set()):
|
||||
return {
|
||||
'telegraf': {
|
||||
'input_plugins': {
|
||||
'builtin': {
|
||||
'smart': [{
|
||||
'devices': list(sorted(metadata.get('smartd/disks'))),
|
||||
}],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return {}
|
||||
|
||||
|
||||
@metadata_reactor.provides(
|
||||
'cron/jobs/smartd',
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue