43 lines
836 B
Python
43 lines
836 B
Python
#!/usr/bin/env python
|
|
|
|
import threading
|
|
import subprocess
|
|
import re
|
|
import functools
|
|
import time
|
|
|
|
from .sender import send
|
|
|
|
# Disk Space
|
|
# CPU
|
|
# MEM
|
|
# Temperatures
|
|
# Network in/out
|
|
# Backups (Plus 5 day forecast)
|
|
|
|
def handle_stdout(stdout):
|
|
return stdout.decode("utf-8").strip()
|
|
|
|
def nice_run(*args, **kwargs):
|
|
run = subprocess.run(*args, capture_output=True, **kwargs)
|
|
return handle_stdout(run.stdout)
|
|
|
|
def get_hostname():
|
|
return nice_run(["hostname"])
|
|
|
|
def clean_storage(storage):
|
|
group = re.search(r"([0-9]*.?[0-9]+[\w]+)", storage)
|
|
return group.group(1)
|
|
|
|
def collect_temp():
|
|
pass
|
|
|
|
def collect_compute():
|
|
pass
|
|
|
|
def collect_storage(path, exclude = None):
|
|
cmd = ["du", "-sk", path]
|
|
if exclude:
|
|
cmd += [f"--exclude={exclude}"]
|
|
storage = nice_run(cmd)
|
|
return clean_storage(storage) |