ltsdb/record_dus

35 lines
714 B
Plaintext
Raw Permalink Normal View History

2022-08-21 12:00:07 +02:00
#!/usr/bin/python3
import argparse
import os
import socket
import subprocess
import time
from ltsdb_json import LTS
ap = argparse.ArgumentParser()
ap.add_argument("directory")
args = ap.parse_args()
# It's a bit weird that this works.
hostname = socket.gethostbyaddr(socket.gethostname())[0]
p = subprocess.run(["/usr/bin/dus", args.directory], capture_output=True, text=True)
t0 = time.time()
for ln in p.stdout.split("\n")[:-1]:
(size, directory) = ln.split("\t")
ts = LTS(
{
"hostname": hostname,
"directory": directory,
"measure": "diskusage",
"unit": "bytes",
}
)
ts.add(t0, int(size)*1024)
ts.save()
t1 = time.time()