Monitoring Zpool

This commit is contained in:
nyanloutre 2018-08-07 18:04:12 +02:00
parent 415c86221b
commit c395d478b6
1 changed files with 41 additions and 12 deletions

View File

@ -71,19 +71,48 @@ in
smart = { smart = {
path = "${pkgs.writeShellScriptBin "smartctl" "/run/wrappers/bin/sudo ${pkgs.smartmontools}/bin/smartctl $@"}/bin/smartctl"; path = "${pkgs.writeShellScriptBin "smartctl" "/run/wrappers/bin/sudo ${pkgs.smartmontools}/bin/smartctl $@"}/bin/smartctl";
}; };
exec= { exec= [
commands = [ { commands = [
"${pkgs.python}/bin/python ${ "${pkgs.python}/bin/python ${
pkgs.fetchgit { pkgs.fetchgit {
url = "https://gitea.nyanlout.re/nyanloutre/tplink-smartplug.git"; url = "https://gitea.nyanlout.re/nyanloutre/tplink-smartplug.git";
rev = "a0996112fc451b76448589698de440ad5fd6ea79"; rev = "a0996112fc451b76448589698de440ad5fd6ea79";
sha256 = "1f1625g7rfsddgk428g76p8fr7vz5gfhq3f452q17bjni3rf2pj3"; sha256 = "1f1625g7rfsddgk428g76p8fr7vz5gfhq3f452q17bjni3rf2pj3";
} }
}/tplink_smartplug.py -t 192.168.0.57 -c energy" }/tplink_smartplug.py -t 192.168.0.57 -c energy"
]; ];
data_format = "json"; data_format = "json";
name_suffix = "_tplink-smartplug"; name_suffix = "_tplink-smartplug";
}; }
{
commands = [
"${pkgs.python3}/bin/python ${pkgs.writeText "zpool.py" ''
import json
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(["${pkgs.zfs}/bin/zpool", "list", "-Hp"],encoding='UTF-8').split('\n')
parsed_stdout = list(map(lambda x: dict(zip(columns,x.split('\t'))), stdout))[:-1]
for pool in parsed_stdout:
for item in pool:
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]]
print(json.dumps(parsed_stdout))
''}"
];
tag_keys = [ "NAME" ];
data_format = "json";
name_suffix = "_python_zpool";
}
];
}; };
outputs = { outputs = {
influxdb = { database = "telegraf"; urls = [ "http://localhost:8086" ]; }; influxdb = { database = "telegraf"; urls = [ "http://localhost:8086" ]; };