FreeBSD: Jstats – a resource monitoring tool that I made for FreeBSD Jails

Written by: Özgür Konstantin Kazanççı -

Category: My FreeBSD Write-ups

Greetings everyone.

Long time no text! I stayed away from here for a long while, both because of the heavy workload at my place of work and because I myself was in the process of autodidacticism/learning, rather than writing here. During this period, I have collected and read many books on UNIX server administration, FreeBSD server security and system virtualization/vm managers.

In particular, I’ve had a wide variety of experience across FreeBSD’s Jails, virtualization hypervisors in both OpenBSD (vmm) and FreeBSD (bhyve), nginx in deep, as reverse proxy&TLS termination.

When Nginx’s Reverse Proxy&TLS Termination method is combined with FreeBSD Jails, great things can happen!

For example, on a FreeBSD system with only a single external/public IP (with virtual network interfaces&local IP addresses for Jails) and only using Nginx as reverse proxy, I discovered great ways to host multiple instances of https websites (separated into Jails with virtual/local IPs). I will share all these, in the form of articles on my blog soon.

I think using Jails in FreeBSD is the easiest way to create virtual systems with a very practical, secure and fast method.

Anyways, here we go, how jstats was born;

On my FreeBSD server, I created 3 different jails. My #1 Jail is running nginx for hosting my domain inside it, the other one is running php-fpm service for all my sites, and the last one is running SQL (MariaDB) server, providing database access to my sites.

Later, when the number of jails increased, it became difficult to manage all these systems and to control the resources they consumed. (CPU, RAM, disk space)

Thus jstats was born – I wrote a small, ‘top’-alike shell tool for my Jails.

Jstats is a resource monitoring script for Jails. It simply lists RAM, CPU and disk space usage of the jails running in the host system:

Sample output:


[root@ozgur:~]# chmod +x jstats.sh
[root@ozgur:~]# ./jstats.sh

==============================
 jstats 0.1 by Ozgur Kazancci
  https://ozgurkazancci.com
==============================

------------
Jails Found:
------------
nginxsrv  10.10.10.2
phpserver 10.10.10.3
sqlserver 10.10.10.4

------------------
Jails - RAM usage:
[kB] - [MB] - [GB]
------------------
nginxsrv: 2.1%
42908 kB - 42.908 MB - 0.042908 GB

phpserver: 2.2%
45540 kB - 45.54 MB - 0.04554 GB

sqlserver: 5.6%
112416 kB - 112.416 MB - 0.112416 GB

Total RAM usage: 9.9%

------------------
Jails - CPU usage:
------------------
nginxsrv:  2.1%
phpserver: 3.3%
sqlserver: 7.5%

Total CPU usage: 12.9%

-------------------------
Jails - Disk space usage:
-------------------------
1.3G    /jails/nginxsrv
1.7G    /jails/phpserver
1.4G    /jails/sqlserver

[root@ozgur:~]# 

Download link: https://github.com/ozgurkazancci/jstats

Tested On: FreeBSD 13.1 with standard jails defined within /etc/jail.conf file.

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.

But while it’s all in the kernel, it shouldn’t matter which jail manager you use; jstats should work.

Honestly, this tool is small, yet it meets all my needs. I hope it will be useful to you too.

Till next time, thank you for reading.


Leave a Reply