forked from nyanloutre/nixos-config
Monitoring Zpool
This commit is contained in:
parent
415c86221b
commit
c395d478b6
@ -71,8 +71,8 @@ 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";
|
||||||
@ -83,7 +83,36 @@ in
|
|||||||
];
|
];
|
||||||
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" ]; };
|
||||||
|
Loading…
Reference in New Issue
Block a user