forked from moonlight200/quic-opensand-emulation
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstats.sh
executable file
·45 lines (36 loc) · 777 Bytes
/
stats.sh
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
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# _osnd_stat_cpu()
function _osnd_stat_cpu() {
cat /proc/loadavg | cut -d' ' -f 1
}
# _osnd_stat_ram()
function _osnd_stat_ram() {
free -m | head -n 2 | tail -n 1 | awk -F' ' '{print $3}'
}
# _osnd_log_stats()
function _osnd_log_stats() {
local cpu=$(_osnd_stat_cpu)
local ram=$(_osnd_stat_ram)
log S "CPU load (1m avg): ${cpu}, RAM usage: ${ram}MB"
}
# osnd_stats_every(seconds)
function osnd_stats_every() {
local seconds=$1
while true; do
_osnd_log_stats
sleep $seconds
done
}
# If script is executed directly
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
declare -F log >/dev/null || function log() {
local level="$1"
local msg="$2"
echo "[$level] $msg"
}
if [[ "$@" ]]; then
osnd_stats_every "$@"
else
osnd_stats_every 1
fi
fi