Skip to content

Instantly share code, notes, and snippets.

@kogir
Last active August 29, 2015 14:03
Show Gist options
  • Save kogir/251c4a25e4e0dd31403f to your computer and use it in GitHub Desktop.
Save kogir/251c4a25e4e0dd31403f to your computer and use it in GitHub Desktop.
ZFS StatHat
BEGIN {
FS = "\t";
print "{\n \"ezkey\": \"<key>\",\n \"data\": [";
}
{ COMMA = ""; }
NR > 1 { COMMA = ","; }
$2 == "available" && match($1, "/") == 0 {
print " " COMMA "{ \"stat\": \"ZFS " $1 " Available\", \"value\": " $3/(1024 * 1024 * 1024) " }";
}
$2 == "used" {
print " " COMMA "{ \"stat\": \"ZFS " $1 " Used\", \"value\": " $3/(1024 * 1024 * 1024) " }";
}
$2 == "usedbysnapshots" && $3 != "0" {
print " " COMMA "{ \"stat\": \"ZFS " $1 " Used By Snapshots\", \"value\": " $3/(1024 * 1024 * 1024) " }";
}
$2 == "usedbydataset" {
print " " COMMA "{ \"stat\": \"ZFS " $1 " Used By Dataset\", \"value\": " $3/(1024 * 1024 * 1024) " }";
}
$2 == "compressratio" && $3 != "1.00x" {
gsub("x", "", $3);
print " " COMMA "{ \"stat\": \"ZFS " $1 " Compression Ratio\", \"value\": " $3 " }";
}
END {
print " ]\n}"
}
#! /bin/bash
zfs get -t filesystem -Hpo name,property,value available,used,usedbysnapshots,usedbydataset,compressratio \
| awk -f zfs-stathat.awk \
| curl -H "Content-Type: application/json" -d @- "https://api.stathat.com/ez"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment