petar.company/rrdtools/scripts/conn-server.sh

92 lines
3 KiB
Bash
Raw Normal View History

2025-03-01 00:58:18 +01:00
#!/bin/sh
BASEDIR=`pwd`
. ${BASEDIR%scripts}/rrdtool.conf
FILE="conn-server"
DBASE="${DBASEDIR}/${FILE}.rrd"
IMG="${IMGDIR}/${FILE}.png"
SIMG="${IMGDIR}/small-${FILE}.png"
if [ ! -f "${DBASE}" ]; then
${RRD} create ${DBASE} \
--start N \
--step 300 \
DS:conn_tot:GAUGE:600:U:U \
DS:conn_udp:GAUGE:600:U:U \
DS:conn_tcp:GAUGE:600:U:U \
DS:conn_pop:GAUGE:600:U:U \
DS:conn_www:GAUGE:600:U:U \
DS:conn_mai:GAUGE:600:U:U \
DS:conn_pcs:GAUGE:600:U:U \
RRA:AVERAGE:0.5:1:288
fi
TOTSESS=`netstat -an | grep -ce '^.*p4'`
UDPSESS=`netstat -an | grep -ce '^udp4'`
TCPSESS=`netstat -an | grep -ce '^tcp4'`
POPSESS=`netstat -an | grep -ce '83.149.156.244.110 '`
WWWSESS=`netstat -an | grep -ce '83.149.156.244.80'`
MAISESS=`netstat -an | grep -ce '83.149.156.244.25'`
PCSSESS=`netstat -an | grep -ce '83.149.156.244.2110'`
${RRD} update ${DBASE} N:${TOTSESS}:${UDPSESS}:${TCPSESS}:${POPSESS}:${WWWSESS}:${MAISESS}:${PCSSESS}
${RRD} graph ${IMG} \
--imgformat=PNG \
--title="Connections" \
--font DEFAULT:7 \
--rigid \
--base=1000 \
--height=100 \
--width=400 \
--tabwidth=20 \
--lower-limit=0 \
--vertical-label="Connections" \
DEF:tot="${DBASE}":conn_tot:AVERAGE \
DEF:udp="${DBASE}":conn_udp:AVERAGE \
DEF:tcp="${DBASE}":conn_tcp:AVERAGE \
DEF:pop="${DBASE}":conn_pop:AVERAGE \
DEF:www="${DBASE}":conn_www:AVERAGE \
DEF:mai="${DBASE}":conn_mai:AVERAGE \
DEF:pcs="${DBASE}":conn_pcs:AVERAGE \
AREA:tot#00CF00:"TOT\t\t" GPRINT:tot:LAST:"Last\:%4.0lf %s\t" GPRINT:tot:AVERAGE:"Avg\:%4.0lf %s\t" GPRINT:tot:MAX:"Max\:%4.0lf %s\n" \
LINE1:udp#FF0000:"UDP\t\t" GPRINT:udp:LAST:"Last\:%4.0lf %s\t" GPRINT:udp:AVERAGE:"Avg\:%4.0lf %s\t" GPRINT:udp:MAX:"Max\:%4.0lf %s\n" \
LINE1:tcp#002A97:"TCP\t\t" GPRINT:tcp:LAST:"Last\:%4.0lf %s\t" GPRINT:tcp:AVERAGE:"Avg\:%4.0lf %s\t" GPRINT:tcp:MAX:"Max\:%4.0lf %s\n" \
LINE1:pop#FF00FF:"pop3\t\t" GPRINT:pop:LAST:"Last\:%4.0lf %s\t" GPRINT:pop:AVERAGE:"Avg\:%4.0lf %s\t" GPRINT:pop:MAX:"Max\:%4.0lf %s\n" \
LINE1:www#009999:"www\t\t" GPRINT:www:LAST:"Last\:%4.0lf %s\t" GPRINT:www:AVERAGE:"Avg\:%4.0lf %s\t" GPRINT:www:MAX:"Max\:%4.0lf %s\n" \
LINE1:mai#DDDDDD:"smtp\t\t" GPRINT:mai:LAST:"Last\:%4.0lf %s\t" GPRINT:mai:AVERAGE:"Avg\:%4.0lf %s\t" GPRINT:mai:MAX:"Max\:%4.0lf %s\n" \
LINE1:pcs#FFFF66:"procsy\t" GPRINT:pcs:LAST:"Last\:%4.0lf %s\t" GPRINT:pcs:AVERAGE:"Avg\:%4.0lf %s\t" GPRINT:pcs:MAX:"Max\:%4.0lf %s"
${RRD} graph ${SIMG} \
--imgformat=PNG \
--font DEFAULT:5 \
--height=50 \
--width=200 \
--tabwidth=20 \
--lower-limit=0 \
--no-legend \
DEF:tot="${DBASE}":conn_tot:AVERAGE \
DEF:udp="${DBASE}":conn_udp:AVERAGE \
DEF:tcp="${DBASE}":conn_tcp:AVERAGE \
DEF:pop="${DBASE}":conn_pop:AVERAGE \
DEF:www="${DBASE}":conn_www:AVERAGE \
DEF:mai="${DBASE}":conn_mai:AVERAGE \
DEF:pcs="${DBASE}":conn_pcs:AVERAGE \
AREA:tot#00CF00 \
LINE1:udp#FF0000 \
LINE1:tcp#002A97 \
LINE1:pop#FF00FF \
LINE1:www#009999 \
LINE1:mai#DDDDDD \
LINE1:pcs#FFFF66
# Optionals
# HRULE:150000#FF0000:"MAX possible speed"
# CDEF:byte_in=in,8,* \
# CDEF:byte_out=out,8,* \