rrdtool/interface.sh

74 lines
2.8 KiB
Bash
Raw Normal View History

2019-03-12 16:14:48 +01:00
#!/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.
#
2020-05-31 16:15:35 +02:00
# Get list of interfaces with: snmpctl snmp walk <host> community public oid ifDescr
#
2019-03-12 16:14:48 +01:00
test -n "$1" || exit 1
test -n "$2" || exit 1
HOST="$1"
INTERFACE="$2"
COMMUNITY="public"
2019-05-04 18:20:26 +02:00
RRDFILES="/home/mischa/rrd"
2019-03-12 16:18:30 +01:00
WATERMARK="OpenBSD Amsterdam - https://obsda.ms"
2020-05-31 16:15:35 +02:00
IMAGES="/var/www/rrdtool/obsda.ms"
2019-03-12 16:14:48 +01:00
RRDTOOL="/usr/local/bin/rrdtool"
UPTIME=$(cat /tmp/${HOST}-uptime.txt)
2019-05-04 18:20:26 +02:00
VERSION=$(cat /tmp/${HOST}-version.txt)
2019-03-12 16:14:48 +01:00
NOW=$(date "+%Y-%m-%d %H:%M:%S %Z" | sed 's/:/\\:/g')
if ! test -f "${RRDFILES}/${HOST}-${INTERFACE}.rrd"
then
echo "Creating ${RRDFILES}/${HOST}-${INTERFACE}.rrd"
${RRDTOOL} create ${RRDFILES}/${HOST}-${INTERFACE}.rrd \
--step 300 \
DS:ds0:COUNTER:600:0:1250000000 \
DS:ds1:COUNTER:600:0:1250000000 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797
fi
IN=$(snmpctl snmp get ${HOST} community ${COMMUNITY} oid ifInOctets.${INTERFACE} | cut -d= -f2)
OUT=$(snmpctl snmp get ${HOST} community ${COMMUNITY} oid ifOutOctets.${INTERFACE} | cut -d= -f2)
DESCR=$(snmpctl snmp get ${HOST} community ${COMMUNITY} oid ifDescr.${INTERFACE} | cut -d= -f2 | tr -d '"')
${RRDTOOL} update ${RRDFILES}/${HOST}-${INTERFACE}.rrd N:${IN}:${OUT}
${RRDTOOL} graph ${IMAGES}/${HOST}-${INTERFACE}.png \
--start -43200 \
2019-05-04 18:20:26 +02:00
--title "${HOST} - ${VERSION} - ${DESCR}" \
2019-03-12 16:14:48 +01:00
--vertical-label "Bits per Second" \
2019-03-12 16:18:30 +01:00
--watermark "${WATERMARK}" \
2019-05-04 18:20:26 +02:00
--color BACK#ffffff \
--border 0 \
2019-03-12 16:14:48 +01:00
DEF:IN=${RRDFILES}/${HOST}-${INTERFACE}.rrd:ds0:AVERAGE \
DEF:OUT=${RRDFILES}/${HOST}-${INTERFACE}.rrd:ds1:AVERAGE \
CDEF:IN_CDEF="IN,8,*" \
CDEF:OUT_CDEF="OUT,8,*" \
AREA:IN_CDEF#00FF00:"In " \
GPRINT:IN_CDEF:MAX:"Max\:%5.2lf %s" \
GPRINT:IN_CDEF:AVERAGE:"Average\:%5.2lf %s" \
GPRINT:IN_CDEF:LAST:" Current\:%5.2lf %s\n" \
LINE2:OUT_CDEF#0000FF:"Out" \
GPRINT:OUT_CDEF:MAX:"Max\:%5.2lf %s" \
GPRINT:OUT_CDEF:AVERAGE:"Average\:%5.2lf %s" \
GPRINT:OUT_CDEF:LAST:" Current\:%5.2lf %s\n" \
COMMENT:"\\n" \
COMMENT:" Up for ${UPTIME} at ${NOW}"