FreeBSD: Jstats – a resource monitor for Jails

Written by: Özgür 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:


Download link:

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