#!/bin/bash - 
#===============================================================================
#
#          FILE: jitsi-statistics.sh
# 
#         USAGE: ./jitsi-statistics.sh 
# 
#   DESCRIPTION: 
# 
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: YOUR NAME (), 
#  ORGANIZATION: 
#       CREATED: 02/15/2021 13:14
#      REVISION:  ---
#===============================================================================

set -o nounset                              # Treat unset variables as an error

# cpu  
awk '{u=$2+$4; t=$2+$4+$5; if (NR==1){uuu1=u; ttt1=t;} else print ($2+$4-u1) * 100 / (t-t1) ""; }' <(grep 'cpu ' /proc/stat) <(sleep 1;grep 'cpu ' /proc/stat) > /usr/share/jitsi-meet/cpu.txt    
#memory  
free -m | awk 'NR==2{printf "%s", $3 }' > /usr/share/jitsi-meet/memory.txt   
# statistic  
[[ -f /usr/share/jitsi-meet/stats.json ]] && rm /usr/share/jitsi-meet/stats.json  
curl -s http://127.0.0.1:8080/colibri/stats >> /usr/share/jitsi-meet/stats.json  

