<p><ahref="https://openbsd.amsterdam/">OpenBSD Amsterdam</a> was in search of a lightweight toolset to keep track of resource usage, at a minimum the CPU load generated by the <ahref="https://man.openbsd.org/vmm.4">vmm(4)</a>/<ahref="https://man.openbsd.org/vmd.8">vmd(8)</a> hosts and the traffic from and to the hosts. A couple of weeks ago we ended up with a workable [MRTG setup]. While it worked, it didn't look very pretty.</p>
<p>In a moment of clarity, we thought about using <ahref="https://oss.oetiker.ch/rrdtool/">RRDtool</a>. Heck, why shouldn't we give it a try? From the previous tooling, we already had some required building blocks in place to make <ahref="https://oss.oetiker.ch/mrtg/">MRTG</a> understand the CPU Cores and uptime from <ahref="https://openbsd.org/">OpenBSD</a>.</p>
<p>We decided to split the collection of the different OIDs (SNMP Object Identifiers) into three different scripts, which <ahref="https://man.openbsd.org/cron.1">cron(1)</a> calls, from a wrapper script.</p>
<ul>
<li>uptime.sh</li>
<li>cpu_load.sh</li>
<li>interface.sh</li>
</ul>
<h3id="uptime.sh">uptime.sh</h3>
<pre><code>#!/bin/sh
test -n "$1" || exit 1
HOST="$1"
COMMUNITY="public"
UPTIMEINFO="/tmp/${HOST}-uptime.txt"
TICKS=$(snmpctl snmp get ${HOST} community ${COMMUNITY} oid hrSystemUptime.0 | cut -d= -f2)
DAYS=$(echo "${TICKS}/8640000" | bc -l)
HOURS=$(echo "0.${DAYS##*.} * 24" | bc -l)
MINUTES=$(echo "0.${HOURS##*.} * 60" | bc -l)
SECS=$(echo "0.${MINUTES##*.} * 60" | bc -l)
test -n "$DAYS"&& printf '%s days, '"${DAYS%.*}"> ${UPTIMEINFO}
COMMENT:" SUM CPU Load / Active Cores = % CPU Used\n" \
COMMENT:" Up for ${UPTIME} at ${NOW}"
</code></pre>
<p>On the first run, <ahref="https://oss.oetiker.ch/rrdtool/">RRDtool</a> will create the .rrd file. On every subsequent run, it will update the file with the collected values and update the graph.</p>
<p>The origins for this script can be found detailed in our <ahref="https://chargen.one/obsdams/using-mrtg-again">MRTG Setup</a>.</p>