Skip to content

Instantly share code, notes, and snippets.

@vroman
Last active September 2, 2021 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vroman/5f7eba2b668b160a6bbdcdd53406e306 to your computer and use it in GitHub Desktop.
Save vroman/5f7eba2b668b160a6bbdcdd53406e306 to your computer and use it in GitHub Desktop.
send_jail_stats_prometheus.sh
#!/bin/sh
# This scripts injects running jails from a FreeBSD host
# into Prometheus monitoring pushgateway.
#
# A common way to use this is set-up a crontab entry.
#
# kernel requeriments:
# options RACCT
# options RCTL
#
# /boot/loader.conf.local requeriments:
# kern.racct.enable=1
#
# Sample usage via cron:
#
# * * * * * root /usr/local/sbin/send_jail_stats_prometheus.sh | /usr/local/bin/curl --connect-timeout 5 --max-time 15 --data-binary @- http://IP.PROMETHEUS:9091/metrics/job/pushgateway/instance/IP.LOCAL.SERVER >/dev/null 2>&1
#
# Author(s): Victor Roman Archidona <vroman@loadfront.com>
jails=`jls -d -h name | tail -n +2`
for jail in $jails; do
for item in `rctl -u jail:$jail`; do
itemname=`echo $item | cut -d= -f1`
itemvalue=`echo $item | cut -d= -f2`
echo freebsd_jail_resource{jail=\"$jail\",name=\"$itemname\"} $itemvalue
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment