Last active
April 11, 2022 12:39
-
-
Save taoky/ba50758d4cbf086abaace4a496927d55 to your computer and use it in GitHub Desktop.
xfs_quota telegraf script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
import subprocess as sp | |
def main(): | |
command = ["/sbin/xfs_quota", "-c", "free -N"] | |
ret = sp.run(command, stdout=sp.PIPE) | |
if ret.returncode != 0: | |
raise RuntimeError(f"xfs_quota failed with return value {ret.returncode}") | |
# parse xfs_quota output | |
# the output of one path may not on one single line | |
# so I have to use this dirty way to parse it | |
i = 0 | |
lines = ret.stdout.decode('utf8').strip().split('\n') | |
data = {} | |
while i < len(lines): | |
line = lines[i] | |
splits = line.split() | |
i += 1 | |
if len(splits) < 6: | |
assert i < len(lines) | |
line += lines[i] | |
splits = line.split() | |
i += 1 | |
assert len(splits) == 6 | |
fs, onekblk, used, available, _, path = splits | |
data[path] = { | |
"fs": fs, | |
"1kblk": onekblk, | |
"used": used, | |
"available": available, | |
} | |
# produce influxdb format | |
for path, info in data.items(): | |
print(f"xfsquota,path={path} fs=\"{info['fs']}\",onekblk={info['1kblk']},used={info['used']},available={info['available']}") | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[inputs.exec]] | |
commands = ["sudo /opt/xfsquota-telegraf.py"] | |
timeout = "30s" | |
data_format = "influx" | |
interval = "1m" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment