]> Git — Sourcephile - sourcephile-nix.git/blob - nixpkgs/pkgs/tools/system/smartmontools/smartctl-tbw/default.nix
losurdo: nginx: enable on wg-intra
[sourcephile-nix.git] / nixpkgs / pkgs / tools / system / smartmontools / smartctl-tbw / default.nix
1 { lib
2 , coreutils
3 , gawk
4 , gnused
5 , smartmontools
6 , sudo
7 , writeShellScriptBin
8 , utillinux
9 }:
10 let PATH = lib.makeBinPath
11 [ coreutils
12 gawk
13 gnused
14 utillinux
15 ] + ":$PATH"; # For sudo
16 in
17 writeShellScriptBin "smartctl-tbw" ''
18 export PATH=${PATH}
19 device=''${1:-/dev/sda}
20 sudo ${smartmontools}/bin/smartctl -A $device |
21 { awk '
22 $0 ~ /Power_On_Hours/ { poh=$10; printf "%s / %d hours / %d days / %.2f years\n", $2, $10, $10 / 24, $10 / 24 / 365.25 }
23 $0 ~ /Total_LBAs_Written/ {
24 lbas = $10;
25 bytes = $10 * 512;
26 mb = bytes / 1024^2;
27 gb = bytes / 1024^3;
28 tb = bytes / 1024^4;
29 printf "%s / %s / %d mb / %.1f gb / %.3f tb\n", $2, $10, mb, gb, tb
30 printf "mean writes per hour: / %.2f", mb/poh
31 }
32 $0 ~ /Airflow_Temperature_Cel/ { print $2 " / " $10}
33 $0 ~ /Wear_Leveling_Count/ { printf "%s / %d (%% health)\n", $2, int($4) }
34 '; echo; } |
35 sed -e 's:/:@:' |
36 sed -e "s\$^\$$device @ \$" |
37 column -ts@
38 ''