├── README.md └── jstats.sh /README.md: -------------------------------------------------------------------------------- 1 | # jstats 2 | Jstats is a tiny resource monitor for jails, small tool that I wrote for FreeBSD systems - lists RAM, CPU and disk space usage of the jails running in the host system. 3 | 4 | **Tested On:** FreeBSD 13.1 with standard jails defined within **/etc/jail.conf** file. 5 | 6 | I like raw, homemade jails, digging around in config files. I don't use any jail management tool/package, being a minimal&analogue guy with a try-to-do-it-yourself spirit, I never tested jstats with jails created by jail management packages, such as; BastilleBSD, iocage, cbsd, et cetera. 7 | 8 | But while it's all in the kernel, it shouldn't matter which jail manager you use; **jstats** should work. 9 | 10 | **Usage and a sample run:** 11 | 12 | ```console 13 | [root@ozgur:~]# chmod +x jstats.sh 14 | [root@ozgur:~]# ./jstats.sh 15 | 16 | #Alternatively you might wish to move it somewhere inside $PATH for easier access; 17 | 18 | [root@ozgur:~]# chmod +x jstats.sh 19 | [root@ozgur:~]# mv jstats.sh /usr/local/bin/jstats 20 | [root@ozgur:~]# jstats 21 | 22 | ============================== 23 | jstats 0.1 by Ozgur Kazancci 24 | https://ozgurkazancci.com 25 | ============================== 26 | 27 | ------------ 28 | Jails Found: 29 | ------------ 30 | nginxsrv 10.10.10.2 31 | phpserver 10.10.10.3 32 | sqlserver 10.10.10.4 33 | 34 | ------------------ 35 | Jails - RAM usage: 36 | [kB] - [MB] - [GB] 37 | ------------------ 38 | nginxsrv: 2.1% 39 | 42908 kB - 42.908 MB - 0.042908 GB 40 | 41 | phpserver: 2.2% 42 | 45540 kB - 45.54 MB - 0.04554 GB 43 | 44 | sqlserver: 5.6% 45 | 112416 kB - 112.416 MB - 0.112416 GB 46 | 47 | Total RAM usage: 9.9% 48 | 49 | ------------------ 50 | Jails - CPU usage: 51 | ------------------ 52 | nginxsrv: 2.1% 53 | phpserver: 3.3% 54 | sqlserver: 7.5% 55 | 56 | Total CPU usage: 12.9% 57 | 58 | ------------------------- 59 | Jails - Disk space usage: 60 | This might take a while.. 61 | ------------------------- 62 | 1.3G /jails/nginxsrv 63 | 1.7G /jails/phpserver 64 | 1.4G /jails/sqlserver 65 | 66 | [root@ozgur:~]# 67 | ``` 68 | -------------------------------------------------------------------------------- /jstats.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | printf "\n==============================" 4 | printf "\n jstats 0.1 by Ozgur Kazancci" 5 | printf "\n https://ozgurkazancci.com" 6 | printf "\n==============================\n" 7 | 8 | if [ "$(jls name | xargs)" = "" ]; then printf "\nNo jail found?\n\n"; exit 1; 9 | 10 | else 11 | 12 | jails=`jls name | xargs | sed 's/ / -J /g'` 13 | printf "\n------------" 14 | printf "\nJails Found:" 15 | printf "\n------------\n" 16 | 17 | jls name ip4.addr 18 | 19 | printf "\n------------------" 20 | printf "\nJails - RAM usage:" 21 | printf "\n[kB] - [MB] - [GB]" 22 | printf "\n------------------\n" 23 | jls name | while SUM= read -r line; do printf "$line: " && ps -o %mem= -J "$line" | awk '{sum+=$1} END {printf("%.1f%%\n",sum)}' && \ 24 | ps -o rss= -J "$line" | awk '{ total+=$1 } END { printf total " kB - " total/1000 " MB - " total/1000**2 " GB\n\n" }'; done 25 | 26 | printf "Total RAM usage: " 27 | ps -o %mem= -J $jails | awk '{sum+=$1} END {printf("%.1f%%\n",sum)}' 28 | 29 | printf "\n------------------" 30 | printf "\nJails - CPU usage:" 31 | printf "\n------------------\n" 32 | jls name | while SUM= read -r line; do printf "$line: " && ps -o %cpu= -J "$line" | awk '{sum+=$1} END {printf("%.1f%%\n",sum)}'; done 33 | 34 | printf "\nTotal CPU usage: " 35 | ps -o %cpu= -J $jails | awk '{sum+=$1} END {printf("%.1f%%\n",sum)}' 36 | 37 | printf "\n-------------------------" 38 | printf "\nJails - Disk space usage:" 39 | printf "\nThis might take a while.." 40 | sleep 0.5 41 | printf "\n-------------------------\n" 42 | jls path | while SUM= read -r line; do du -sh "$line"; done 43 | printf "\n" 44 | exit 0; 45 | fi 46 | --------------------------------------------------------------------------------