20 lines
882 B
Bash
20 lines
882 B
Bash
#!/usr/bin/env bash
|
|
# ep19fs Lab-Helfer (Server und Clients). Keine Geheimnisse im Output.
|
|
now() { date +%s.%N; }
|
|
ts() { date -u +%H:%M:%S; }
|
|
el() { python3 -c "print(f'{float(\"$2\")-float(\"$1\"):.2f}')"; }
|
|
# hostsample SECONDS OUTFILE: Host-CPU% und RAM (MemTotal-MemAvailable) im 1-s-Takt
|
|
hostsample() { python3 - "$1" "$2" <<'PY'
|
|
import sys,time
|
|
dur=float(sys.argv[1]); out=open(sys.argv[2],'w')
|
|
def cpu():
|
|
v=list(map(int,open('/proc/stat').readline().split()[1:])); idle=v[3]+v[4]; return sum(v),idle
|
|
def mem():
|
|
d={l.split(':')[0]:int(l.split()[1]) for l in open('/proc/meminfo')}
|
|
return (d['MemTotal']-d['MemAvailable'])/1024
|
|
t0=time.time(); a=cpu()
|
|
while time.time()-t0<dur:
|
|
time.sleep(1); b=cpu(); tot=b[0]-a[0]; idl=b[1]-a[1]; a=b
|
|
out.write(f"{time.strftime('%H:%M:%S',time.gmtime())}\t{100*(tot-idl)/max(tot,1):.1f}\t{mem():.0f}\n"); out.flush()
|
|
PY
|
|
}
|