snartctl
This commit is contained in:
parent
1f0e660a4d
commit
5390f3ac3c
10 changed files with 115 additions and 32 deletions
|
@ -1,18 +0,0 @@
|
|||
previous_action = []
|
||||
|
||||
for device, options in node.metadata.get('hdparm').items():
|
||||
for option, value in options.items():
|
||||
if option == 'power_management':
|
||||
name = f'hdparm_{option}_{device}'
|
||||
actions[name] = {
|
||||
'command': f'hdparm -B {value} "{device}"',
|
||||
'unless': f'hdparm -B "{device}" | grep APM_level | cut -d= -f2 | xargs | grep -q "^{value}$"',
|
||||
'needs': [
|
||||
'pkg_apt:hdparm',
|
||||
*previous_action,
|
||||
],
|
||||
}
|
||||
else:
|
||||
raise ValueError(f'unsupported hdparm option: {option}')
|
||||
|
||||
previous_action = [f'action:{name}']
|
|
@ -1,8 +0,0 @@
|
|||
defaults = {
|
||||
'apt': {
|
||||
'packages': {
|
||||
'hdparm': {},
|
||||
},
|
||||
},
|
||||
'hdparm': {},
|
||||
}
|
15
bundles/smartctl/README.md
Normal file
15
bundles/smartctl/README.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# state
|
||||
smartctl -n idle /dev/sda
|
||||
|
||||
# temp
|
||||
smartctl -n idle -A /dev/sdb --json=c | jq .temperature.current
|
||||
|
||||
# apm
|
||||
smartctl --get apm /dev/sdb --json=c | jq .ata_apm.level
|
||||
smartctl --set apm,20 /dev/sdb --json=c
|
||||
|
||||
# power state
|
||||
smartctl -n idle /dev/sdb
|
||||
|
||||
# devices
|
||||
smartctl --scan | cut -d' ' -f1
|
18
bundles/smartctl/files/hdd_temp
Normal file
18
bundles/smartctl/files/hdd_temp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
|
||||
for device in $(smartctl --scan | cut -d' ' -f1)
|
||||
do
|
||||
temp=$(smartctl -n idle -A --json=c $device | jq .temperature.current)
|
||||
|
||||
if [[ $temp == ?(-)+([0-9]) ]]
|
||||
then
|
||||
echo "smartctl,host=${node.name},device=$device temperature=$temp $(date --utc +%s%N)"
|
||||
elif [[ $temp == null ]]
|
||||
then
|
||||
# hdd might be sleeping
|
||||
continue
|
||||
else
|
||||
# hdd might be unsupported
|
||||
continue
|
||||
fi
|
||||
done
|
25
bundles/smartctl/items.py
Normal file
25
bundles/smartctl/items.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
files = {
|
||||
'/usr/local/share/icinga/plugins/hdd_temp': {
|
||||
'content_type': 'mako',
|
||||
'mode': '0755',
|
||||
},
|
||||
}
|
||||
|
||||
previous_action = []
|
||||
|
||||
for device, conf in node.metadata.get('smartctl').items():
|
||||
for option, value in conf.items():
|
||||
if option == 'apm':
|
||||
action_name = f'smartctl_apm_{device}'
|
||||
actions[action_name] = {
|
||||
'command': f'smartctl --set apm,{value} "{device}"',
|
||||
'unless': f'smartctl --get apm "{device}" --json=c | jq .ata_apm.level | grep -q "^{value}$"',
|
||||
'needs': [
|
||||
'pkg_apt:smartmontools',
|
||||
*previous_action,
|
||||
],
|
||||
}
|
||||
else:
|
||||
raise ValueError(f'{node.name}: unkown smartctl option: {option}')
|
||||
|
||||
previous_action = [f'action:{action_name}']
|
27
bundles/smartctl/metadata.py
Normal file
27
bundles/smartctl/metadata.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
defaults = {
|
||||
'apt': {
|
||||
'packages': {
|
||||
'smartmontools': {},
|
||||
},
|
||||
},
|
||||
'grafana_rows': {
|
||||
'smartctl',
|
||||
},
|
||||
'smartctl': {},
|
||||
'telegraf': {
|
||||
'config': {
|
||||
'inputs': {
|
||||
'exec': [{
|
||||
'commands': [
|
||||
f'sudo /usr/local/share/icinga/plugins/hdd_temp',
|
||||
],
|
||||
'data_format': 'influx',
|
||||
'interval': '60s',
|
||||
}],
|
||||
},
|
||||
},
|
||||
},
|
||||
'sudoers': {
|
||||
'telegraf': ['/usr/local/share/icinga/plugins/hdd_temp'],
|
||||
},
|
||||
}
|
17
data/grafana/rows/smartctl.py
Normal file
17
data/grafana/rows/smartctl.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
'temperature': {
|
||||
'queries': {
|
||||
'usage': {
|
||||
'filters': {
|
||||
'_measurement': 'smartctl',
|
||||
'_field': [
|
||||
'temperature',
|
||||
],
|
||||
},
|
||||
'function': 'mean',
|
||||
},
|
||||
},
|
||||
'min': 0,
|
||||
'unit': 'degrees',
|
||||
},
|
||||
}
|
|
@ -6,9 +6,9 @@
|
|||
'monitored',
|
||||
],
|
||||
'bundles': [
|
||||
'smartctl',
|
||||
'zfs',
|
||||
'zfs-mirror',
|
||||
'hdparm',
|
||||
],
|
||||
'metadata': {
|
||||
'id': '9cf52515-63a1-4659-a8ec-6c3c881727e5',
|
||||
|
@ -22,15 +22,15 @@
|
|||
'backup-server': {
|
||||
'hostname': 'backups.sublimity.de',
|
||||
},
|
||||
'hdparm': {
|
||||
'smartctl': {
|
||||
'/dev/disk/by-id/ata-HGST_HDN726040ALE614_K3GV6TPL': {
|
||||
'power_management': 1,
|
||||
'apm': 32,
|
||||
},
|
||||
'/dev/disk/by-id/ata-HGST_HDN726040ALE614_K4KAJXEB': {
|
||||
'power_management': 1,
|
||||
'apm': 32,
|
||||
},
|
||||
'/dev/disk/by-id/ata-TOSHIBA_HDWQ140_19VZK0EMFAYG': {
|
||||
'power_management': 1,
|
||||
'apm': 32,
|
||||
},
|
||||
},
|
||||
'zfs-mirror': {
|
||||
|
|
|
@ -9,14 +9,15 @@
|
|||
],
|
||||
'bundles': [
|
||||
'gitea',
|
||||
'gollum',
|
||||
'grafana',
|
||||
'influxdb2',
|
||||
'mirror',
|
||||
'postgresql',
|
||||
'redis',
|
||||
'smartctl',
|
||||
'wireguard',
|
||||
'zfs',
|
||||
'gollum',
|
||||
],
|
||||
'metadata': {
|
||||
'id': 'af96709e-b13f-4965-a588-ef2cd476437a',
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
],
|
||||
'bundles': [
|
||||
'dm-crypt',
|
||||
'smartctl',
|
||||
'wireguard',
|
||||
'zfs',
|
||||
],
|
||||
|
@ -53,6 +54,11 @@
|
|||
'device': '/dev/disk/by-id/ata-TOSHIBA_MG06ACA10TE_61C0A1B1FKQE',
|
||||
},
|
||||
},
|
||||
'smartctl': {
|
||||
'/dev/disk/by-id/ata-TOSHIBA_MG06ACA10TE_61C0A1B1FKQE': {
|
||||
'apm': 32,
|
||||
},
|
||||
},
|
||||
'zfs': {
|
||||
'pools': {
|
||||
'tank': {
|
||||
|
|
Loading…
Reference in a new issue