rrdtool/cores.sh
2019-05-04 18:20:26 +02:00

84 lines
3.0 KiB
Bash
Executable File

#!/bin/sh
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
test -n "$1" || exit 1
HOST="$1"
COMMUNITY="public"
RRDFILES="/home/mischa/rrd"
IMAGES="/var/www/mrtg/obsda.ms"
WATERMARK="OpenBSD Amsterdam - https://obsda.ms"
RRDTOOL="/usr/local/bin/rrdtool"
CPUINFO="/tmp/${HOST}-cores.txt"
UPTIME=$(cat /tmp/${HOST}-uptime.txt)
NOW=$(date "+%Y-%m-%d %H:%M:%S %Z" | sed 's/:/\\:/g')
if ! test -f "${RRDFILES}/${HOST}-cores.rrd"
then
echo "Creating ${RRDFILES}/${HOST}-cores.rrd"
${RRDTOOL} create ${RRDFILES}/${HOST}-cores.rrd \
--step 300 \
DS:ds0:GAUGE:600:U:U \
DS:ds1:GAUGE:600:U:U \
DS:ds2:GAUGE:600:U:U \
DS:ds3:GAUGE:600:U:U \
DS:ds4:GAUGE:600:U:U \
DS:ds5:GAUGE:600:U:U \
DS:ds6:GAUGE:600:U:U \
DS:ds7:GAUGE:600:U:U \
DS:ds8:GAUGE:600:U:U \
DS:ds9:GAUGE:600:U:U \
DS:ds10:GAUGE:600:U:U \
DS:ds11:GAUGE:600:U:U \
RRA:MAX:0.5:1:20000
fi
snmpctl snmp walk ${HOST} community ${COMMUNITY} oid hrProcessorLoad | cut -d= -f2 > ${CPUINFO}
CORES=$(cat ${CPUINFO} | wc -l)
ACT_CORES=$((${CORES}/2))
CPU_LOAD=$(cat ${CPUINFO} | paste -s -d: - | cut -d: -f1-${ACT_CORES})
${RRDTOOL} update ${RRDFILES}/${HOST}-cores.rrd N:${CPU_LOAD}
${RRDTOOL} graph ${IMAGES}/${HOST}-cores.png \
--start -432000 \
--title "${HOST} - CPU" \
--vertical-label "% CPU Used" \
--watermark "${WATERMARK}" \
DEF:CORE0=${RRDFILES}/${HOST}-cores.rrd:ds0:AVERAGE \
DEF:CORE1=${RRDFILES}/${HOST}-cores.rrd:ds1:AVERAGE \
DEF:CORE2=${RRDFILES}/${HOST}-cores.rrd:ds2:AVERAGE \
DEF:CORE3=${RRDFILES}/${HOST}-cores.rrd:ds3:AVERAGE \
DEF:CORE4=${RRDFILES}/${HOST}-cores.rrd:ds4:AVERAGE \
DEF:CORE5=${RRDFILES}/${HOST}-cores.rrd:ds5:AVERAGE \
DEF:CORE6=${RRDFILES}/${HOST}-cores.rrd:ds6:AVERAGE \
DEF:CORE7=${RRDFILES}/${HOST}-cores.rrd:ds7:AVERAGE \
DEF:CORE8=${RRDFILES}/${HOST}-cores.rrd:ds8:AVERAGE \
DEF:CORE9=${RRDFILES}/${HOST}-cores.rrd:ds9:AVERAGE \
DEF:CORE10=${RRDFILES}/${HOST}-cores.rrd:ds10:AVERAGE \
DEF:CORE11=${RRDFILES}/${HOST}-cores.rrd:ds11:AVERAGE \
LINE1:CORE0#FFFA00:"CORE0" \
LINE1:CORE1#FFFA00:"CORE1" \
LINE1:CORE2#FFF000:"CORE2" \
LINE1:CORE3#FFE600:"CORE3" \
LINE1:CORE4#FFDC00:"CORE4" \
LINE1:CORE5#FFD200:"CORE5" \
LINE1:CORE6#FFC800:"CORE6" \
LINE1:CORE7#FFBE00:"CORE7" \
LINE1:CORE8#FFB400:"CORE8" \
LINE1:CORE9#FFAA00:"CORE9" \
LINE1:CORE10#FFA000:"CORE10" \
LINE1:CORE11#FF9600:"CORE11" \
COMMENT:"\\n" \
COMMENT:" Up for ${UPTIME} at ${NOW}"