Instantly share code, notes, and snippets.

Embed
What would you like to do?
Send running jail stats to carbon database
#!/bin/sh
# This scripts injects running jails from a FreeBSD host
# into carbon database. It may be consumed then by tools
# like graphite or grafana.
#
# 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
#
# Modify carbon_host, carbon_port and prefix variables
# to suit your needs. By default the metric has the
# format: hostname.jail.<jail name>.<metric name>
#
# Author(s): Víctor Román Archidona <vroman@loadfront.com>
carbon_host="127.0.0.1"
carbon_port="2003"
hostname=`hostname | tr '.' '_'`
prefix="$hostname.jail"
date=`date +%s`
jails=`jls -d -h name | tail -n +2`
for jail in $jails; do
for item in `rctl -u jail:$jail`; do
echo $prefix.$jail.$item $date | tr '=' ' ' | nc -N $carbon_host $carbon_port
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment