https://github.com/SuperQ/chrony_exporter
Code: Select all
fetch https://github.com/SuperQ/chrony_exporter/releases/download/v0.12.1/chrony_exporter-0.12.1.freebsd-amd64.tar.gzCode: Select all
tar -xzf chrony_exporter-0.12.1.freebsd-amd64.tar.gzCode: Select all
cd chrony_exporter-0.12.1.freebsd-amd64Code: Select all
install -m 755 chrony_exporter /usr/local/bin/Code: Select all
#!/bin/sh
# PROVIDE: chrony_exporter
# REQUIRE: NETWORKING
# KEYWORD: shutdown
. /etc/rc.subr
name="chrony_exporter"
rcvar="${name}_enable"
# The actual exporter binary
procname="/usr/local/bin/chrony_exporter"
# daemon(8) will be the command invoked by rc.subr
command="/usr/sbin/daemon"
# pidfiles (parent and child)
pidfile="/var/run/${name}.pid"
child_pidfile="/var/run/${name}.child.pid"
# Default flags (override in /etc/rc.conf via chrony_exporter_flags="...")
: ${chrony_exporter_flags:="--chrony.address=unix:///var/run/chrony/chronyd.sock --web.listen-address=:9123 --collector.sources --collector.serverstats --collector.chmod-socket"}
# Arguments passed to daemon(8):
# -r restart child if it exits
# -p <file> write daemon pid
# -P <file> write child pid
# -o <file> capture stdout/stderr
command_args="-p ${pidfile} -P ${child_pidfile} -o /var/log/${name}.log ${procname} ${chrony_exporter_flags}"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
chrony_exporter_start()
{
echo "Starting ${name}."
${command} ${command_args}
}
chrony_exporter_stop()
{
if [ -r "${pidfile}" ]; then
kill "$(cat "${pidfile}")" 2>/dev/null || true
rm -f "${pidfile}" "${child_pidfile}"
echo "Stopped ${name}."
else
echo "${name} not running (no pidfile)."
fi
}
chrony_exporter_status()
{
if [ -r "${child_pidfile}" ] && kill -0 "$(cat "${child_pidfile}")" 2>/dev/null; then
echo "${name} child is running as pid $(cat "${child_pidfile}")"
return 0
elif [ -r "${pidfile}" ] && kill -0 "$(cat "${pidfile}")" 2>/dev/null; then
echo "${name} daemon is running as pid $(cat "${pidfile}") (child may have exited)"
return 0
else
echo "${name} is not running"
return 1
fi
}
load_rc_config "${name}"
: ${chrony_exporter_enable:="NO"}
run_rc_command "$1"
Code: Select all
chmod +x /usr/local/etc/rc.d/chrony_exporterCode: Select all
sysrc chrony_exporter_enable="YES"Code: Select all
service chrony_exporter startCode: Select all
- job_name: 'chrony_exporter'
static_configs:
- targets: ['localhost:9123'] # or use the host IP/hostname
Code: Select all
groups:
- name: Chrony
rules:
- record: instance:chrony_clock_error_seconds:abs
expr: >
abs(chrony_tracking_last_offset_seconds)
+
chrony_tracking_root_dispersion_seconds
+
(0.5 * chrony_tracking_root_delay_seconds)
Code: Select all
rule_files:
- "/usr/local/etc/prometheus/rules/*.yml"
Code: Select all
service prometheus restartCode: Select all
vi /etc/newsyslog.confCode: Select all
/var/log/chrony_exporter.log root:wheel 644 7 * @T00 -