-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstats.sh
More file actions
executable file
·33 lines (23 loc) · 769 Bytes
/
stats.sh
File metadata and controls
executable file
·33 lines (23 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
# Mongo ID
itemId=`/bin/bash /opt/machine-system/itemid.sh`
# Memory
mem=`free -k | grep Mem | awk '{print $3-$7}'`
echo "Mem usage (KiB): $mem"
# CPU
read cpu a b c previdle rest < /proc/stat
prevtotal=$((a+b+c+previdle))
sleep 0.5
read cpu a b c idle rest < /proc/stat
total=$((a+b+c+idle))
avtotal=$(((total+prevtotal)/2))
idtotal=$(((idle+previdle)/2))
cpu=$((10000*((total-prevtotal)-(idle-previdle))/(total-prevtotal)))
echo "CPU util (hundredths of percent): $cpu"
# Disk space
disk=`df --total | grep total | awk '{print $3}'`
echo "Disk util (KiB): $disk"
# Reporting
urlString="http://visium.club.cc.cmu.edu:8080/machinesystem/server/${itemId}"
curl --request PATCH $urlString --data "mem=${mem}&cpu=${cpu}&disk=${disk}"
echo $urlString