I assume that node_exporter process is running and collecting data from /var/tmp/node_exporter and cbsd is used to manage jails.

  1. enable RACCT add

    to /boot/loader.conf and reboot

  2. Create collection script

    # vi /usr/local/etc/cbsd_prometheus_exporter.sh

    if ! [ -f /var/tmp/node_exporter/cbsd_stats.prom ];then
       /usr/bin/touch /var/tmp/node_exporter/cbsd_stats.prom
       /usr/sbin/chown node_exporter:node_exporter /var/tmp/node_exporter/cbsd_stats.prom
       /bin/chmod u=rw,g=,o= /var/tmp/node_exporter/cbsd_stats.prom
    echo jail_job_completion_time $(date +%s) > /var/tmp/node_exporter/cbsd_stats.prom
    echo bhyve_job_completion_time $(date +%s) >> /var/tmp/node_exporter/cbsd_stats.prom
    /usr/local/bin/cbsd jrctl mode=show prometheus=1 | /usr/bin/grep -vE "^# " >> /var/tmp/node_exporter/cbsd_stats.prom
  3. set access rights for the script
    #chmod u=rwx,g=,o= /usr/local/etc/cbsd_prometheus_exporter.sh
    #ls -l /usr/local/etc/cbsd_prometheus_exporter.sh
    -rwx------  1 root  wheel  583 Jun 18 19:18 /usr/local/etc/cbsd_prometheus_exporter.sh
  4. add collection script to root crontab. Unfortunately it have to be run as root because cbsd program can be only run as root # crontab -e -u root
     # CBSD reporting for prometheuth
     @every_minute	/bin/sh /usr/local/etc/cbsd_prometheus_exporter.sh
  5. Check that prometheus is getting metrics like jail_pcpu and bhyve_pcpu. Explanation of what each value means can be found in the bottom of RCTL(8) man page