diff --git a/plugins/cake/cake_ b/plugins/cake/cake_ new file mode 100755 index 000000000..f1b13f9e1 --- /dev/null +++ b/plugins/cake/cake_ @@ -0,0 +1,210 @@ +#!/bin/bash +# -*- sh -*- + +: << =cut + +=pod + +=encoding UTF-8 + +=head1 NAME + +cake_ - Plugin to monitor cake's backlog, dropped, overlimits and requeues + +=head1 CONFIGURATION + +None needed. + +=head1 INTERPRETATION + +Cake, also known as sch_cake is a modern bandwidth limiter, which eliminates +buffer bloat over slow links. It's also capable to give flows, hosts and each +flow of each host a fair part of the avaible bandwidth. + +This plugin allows for a monitor of the pressure on the qdisc, by monitoring key +values. + +=head1 SEE ALSO + +Take a look at "man cake" to get more information about cake. + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf suggest + +=head1 AUTHORS + +RubenKelevra + +work based on the tc plugin, authors: +Steve Schnepp , +Samuel Smith , +Nye Liu + +=head1 LICENSE + +GPLv2 or later + +=cut + +DEVICE="${0##*/cake_}" + +tc_get_ifb_dev() { + dev="$(/sbin/tc filter show dev "$DEVICE" parent ffff: protocol all | grep "mirred" | grep "Egress Redirect to device")" + [ "$?" -eq "1" ] && return 1 + + echo "$dev" | sed -n 's/.* device \([^ ]*\).*/\1/p' | tr ')' ' ' | awk '{ print $1 }' +} + +tc_cake_sent() { + /sbin/tc -s qdisc show dev "$1" | grep -E "^ Sent" | tr ',' ' ' | tr ')' ' ' +} +tc_cake_backlog() { + /sbin/tc -s qdisc show dev "$1" | grep -E "^ backlog" | tr 'p' ' ' +} + +DEVICE_IN="$(tc_get_ifb_dev)" +has_if_in=$? + +case "$1" in + autoconf) + if [ -r /proc/net/dev ]; then + echo yes + exit 0 + else + echo "no (/proc/net/dev not found)" + exit 1 + fi + ;; + suggest) + if [ -r /proc/net/dev ]; then + ifs="$(awk ' + /^ *(eth|tap|bond|wlan|ath|ra|sw|eno|ens|enp|wlp|wl)[0-9]*/ { + split($0, a, /: */); + gsub(/^ +/,"",a[1]); + if (($2 > 0) || ($10 > 0)) print a[1]; }' /proc/net/dev)" + cake_ifs=() + for if in $ifs; do + qdisc="$(/sbin/tc -s qdisc show dev "$if" | head -n1 | awk '{ print $2 }')" + if [ "$qdisc" == "cake" ]; then + cake_ifs+=("$if") + fi + done + echo "${cake_ifs[@]}" + fi + exit 0 + ;; + config) + + if [ "$has_if_in" -eq "0" ]; then + echo "graph_title $DEVICE ($DEVICE_IN) cake queuing" + else + echo "graph_title $DEVICE cake queuing" + fi + echo 'graph_args --base 1000' + if [ "$has_if_in" -eq "0" ]; then + echo 'graph_vlabel pps in (-) / out (+)' + else + echo 'graph_vlabel packets per second' + fi + echo 'graph_category network' + if [ "$has_if_in" -eq "0" ]; then + echo "graph_info This graph shows the general packet handling status of egress+ingress traffic of the $DEVICE ($DEVICE_IN) network interface." + else + echo "graph_info This graph shows the general packet handling status of egress traffic of the $DEVICE network interface." + fi + + if [ "$has_if_in" -eq "0" ]; then + echo "backlog_in.label backlog" + echo "backlog_in.draw LINE2" + echo "backlog_in.colour 85c4e0" + echo "backlog_in.min 0" + echo "backlog_in.info amount of packets currently buffered. This is an absolut value at the time the plugin is running, not an avg over the last 5 minutes (as all other values in this graph)" + echo "backlog_in.graph no" + fi + echo "backlog.label backlog" + echo "backlog.draw LINE2" + echo "backlog.colour 85c4e0" + echo "backlog.min 0" + echo "backlog.info amount of packets currently buffered" + [ "$has_if_in" -eq "0" ] && echo "backlog.negative backlog_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "dropped_in.label dropped" + echo "dropped_in.draw AREA" + echo "dropped_in.colour c77223" + echo "dropped_in.type DERIVE" + echo "dropped_in.min 0" + echo "dropped_in.info dropped packets in queue" + echo "dropped_in.graph no" + fi + echo "dropped.label dropped" + echo "dropped.draw AREA" + echo "dropped.colour c77223" + echo "dropped.type DERIVE" + echo "dropped.min 0" + echo "dropped.info dropped packets in queue" + [ "$has_if_in" -eq "0" ] && echo "dropped.negative dropped_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "overlimits_in.label overlimits" + echo "overlimits_in.draw STACK" + echo "overlimits_in.colour b6655c" + echo "overlimits_in.type DERIVE" + echo "overlimits_in.min 0" + echo "overlimits_in.info packets exeeded a limit" + echo "overlimits_in.graph no" + fi + echo "overlimits.label overlimits" + echo "overlimits.draw STACK" + echo "overlimits.colour b6655c" + echo "overlimits.type DERIVE" + echo "overlimits.min 0" + echo "overlimits.info packets exeeded a limit" + [ "$has_if_in" -eq "0" ] && echo "overlimits.negative overlimits_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "requeues_in.label requeues" + echo "requeues_in.draw STACK" + echo "requeues_in.colour 4e9e14" + echo "requeues_in.type DERIVE" + echo "requeues_in.min 0" + echo "requeues_in.info packets requeued in queue" + echo "requeues_in.graph no" + fi + echo "requeues.label requeues" + echo "requeues.draw STACK" + echo "requeues.colour 4e9e14" + echo "requeues.type DERIVE" + echo "requeues.min 0" + echo "requeues.info packets requeued in queue" + [ "$has_if_in" -eq "0" ] && echo "requeues.negative requeues_in" + + exit 0 + ;; +esac + +tc_cake_sent "$DEVICE" | awk '{ + print "dropped.value " $7 + print "overlimits.value " $9 + print "requeues.value " $11 +}' + +tc_cake_backlog "$DEVICE" | awk '{ + print "backlog.value " $3 +}' + +if [ "$has_if_in" -eq "0" ]; then + tc_cake_sent "$DEVICE_IN" | awk '{ + print "dropped_in.value " $7 + print "overlimits_in.value " $9 + print "requeues_in.value " $11 + }' + + tc_cake_backlog "$DEVICE_IN" | awk '{ + print "backlog_in.value " $3 + }' +fi + + diff --git a/plugins/cake/cake_tin_delay_ b/plugins/cake/cake_tin_delay_ new file mode 100755 index 000000000..0eed9e248 --- /dev/null +++ b/plugins/cake/cake_tin_delay_ @@ -0,0 +1,391 @@ +#!/bin/bash +# -*- sh -*- + +: << =cut + +=pod + +=encoding UTF-8 + +=head1 NAME + +cake_tin_delay_ - Plugin to monitor cake's average tin delay + +=head1 CONFIGURATION + +None needed. + +=head1 INTERPRETATION + +Cake, also known as sch_cake is a modern bandwidth limiter, which eliminates +buffer bloat over slow links. It's also capable to give flows, hosts and each +flow of each host a fair part of the avaible bandwidth. + +This plugin allows for a monitoring packet delays per tins on the qdisc. + +=head1 SEE ALSO + +Take a look at "man cake" to get more information about cake. + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf suggest + +=head1 AUTHORS + +RubenKelevra + +work based on the tc plugin, authors: +Steve Schnepp , +Samuel Smith , +Nye Liu + +=head1 LICENSE + +GPLv2 or later + +=cut + +DEVICE="${0##*/cake_tin_delay_}" + +# green/blue -> red +eight_color=("006b5f" "1a9850" "66bd63" "a6d96a" "fdae61" "f46d43" "d73027" "9427d7") +four_color=("3288bd" "abdda4" "fdae61" "d53e4f") +three_color=("3288bd" "abdda4" "d53e4f") + +tc_get_ifb_dev() { + dev="$(/sbin/tc filter show dev "$DEVICE" parent ffff: protocol all | grep "mirred" | grep "Egress Redirect to device")" + [ "$?" -eq "1" ] && return 1 + + echo "$dev" | sed -n 's/.* device \([^ ]*\).*/\1/p' | tr ')' ' ' | awk '{ print $1 }' +} + +tc_cake_get_diffserv() { + /sbin/tc -s qdisc show dev "$1" | head -n1 | grep -i "diffserv3" > /dev/null + if [ "$?" -eq "0" ]; then + echo 3 + fi + /sbin/tc -s qdisc show dev "$1" | head -n1 | grep -i "diffserv4" > /dev/null + if [ "$?" -eq "0" ]; then + echo 4 + fi + /sbin/tc -s qdisc show dev "$1" | head -n1 | grep -i "diffserv8" > /dev/null + if [ "$?" -eq "0" ]; then + echo 8 + fi + return 0 +} + +convert_time() { + #converts us, ms, s into s without a unit + echo "$1" | awk '{ + time = $1; + sub(/[a-z]+$/, "", time); + unit = $1; + sub(/^[^a-z]+/, "", unit); + + if (unit == "ns") { + time /= 1000000000; + } else if (unit == "us") { + time /= 1000000; + } else if (unit == "ms") { + time /= 1000; + } else if (unit == "s") { + time = time; + } else if (unit == "m") { + time *= 60; + } else if (unit == "h") { + time *= 3600; + } else if (unit == "d") { + time *= 86400; + } + printf("%.9f\n", time) + }' +} + +tc_cake_get_delays() { + delays="$(/sbin/tc -s qdisc show dev "$1" | grep "^ av_delay" | sed -e 's/av_delay//')" + for e in ${delays[@]}; do + delay="$(convert_time "$e")" + echo -en " $delay " + done + echo "" +} + +DEVICE_IN="$(tc_get_ifb_dev)" +has_if_in=$? + +diffserv_no="$(tc_cake_get_diffserv "$DEVICE")" +if [ "$has_if_in" -eq "0" ]; then + diffserv_in_no="$(tc_cake_get_diffserv "$DEVICE_IN")" + + if [ ! "$diffserv_no" == "$diffserv_in_no" ]; then + echo "cake_tin_delay_: diffserv setting different between egress and ingress device - this cannot be plotted, exiting" >&2 + exit 1 + fi +fi + +case "$1" in + autoconf) + if [ -r /proc/net/dev ]; then + echo yes + exit 0 + else + echo "no (/proc/net/dev not found)" + exit 1 + fi + ;; + suggest) + if [ -r /proc/net/dev ]; then + ifs="$(awk ' + /^ *(eth|tap|bond|wlan|ath|ra|sw|eno|ens|enp|wlp|wl)[0-9]*/ { + split($0, a, /: */); + gsub(/^ +/,"",a[1]); + if (($2 > 0) || ($10 > 0)) print a[1]; }' /proc/net/dev)" + cake_ifs=() + for if in $ifs; do + qdisc="$(/sbin/tc -s qdisc show dev "$if" | head -n1 | awk '{ print $2 }')" + if [ "$qdisc" == "cake" ]; then + cake_ifs+=("$if") + fi + done + echo "${cake_ifs[@]}" + fi + exit 0 + ;; + config) + + if [ "$has_if_in" -eq "0" ]; then + echo "graph_title $DEVICE ($DEVICE_IN) cake QoS tin's avg delay" + else + echo "graph_title $DEVICE cake QoS tin's avg delay" + fi + echo 'graph_args --base 1000' + if [ "$has_if_in" -eq "0" ]; then + echo 'graph_vlabel seconds in (-) / out (+)' + else + echo 'graph_vlabel seconds' + fi + echo 'graph_category network' + if [ "$has_if_in" -eq "0" ]; then + echo "graph_info This graph shows the average latency of egress+ingress traffic per tin of the $DEVICE ($DEVICE_IN) network interface." + else + echo "graph_info This graph shows the average latency of egress traffic per tin of the $DEVICE network interface." + fi + + if [ "$diffserv_no" == "3" ]; then + + if [ "$has_if_in" -eq "0" ]; then + echo "bulk_in.label Bulk" + echo "bulk_in.type GAUGE" + echo "bulk_in.colour ${three_color[0]}" + echo "bulk_in.min 0" + echo "bulk_in.info avg delay for bulk packets thru cake" + echo "bulk_in.graph no" + fi + echo "bulk.label Bulk" + echo "bulk.type GAUGE" + echo "bulk.colour ${three_color[0]}" + echo "bulk.min 0" + echo "bulk.info avg delay for bulk packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "bulk.negative bulk_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "besteffort_in.label Best Effort" + echo "besteffort_in.type GAUGE" + echo "besteffort_in.colour ${three_color[1]}" + echo "besteffort_in.min 0" + echo "besteffort_in.info avg delay for best effort packets thru cake" + echo "besteffort_in.graph no" + fi + echo "besteffort.label Best Effort" + echo "besteffort.type GAUGE" + echo "besteffort.colour ${three_color[1]}" + echo "besteffort.min 0" + echo "besteffort.info avg delay for best effort packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "besteffort.negative besteffort_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "voice_in.label Voice" + echo "voice_in.type GAUGE" + echo "voice_in.colour ${three_color[2]}" + echo "voice_in.min 0" + echo "voice_in.info avg delay for Voice packets thru cake" + echo "voice_in.graph no" + fi + echo "voice.label Voice" + echo "voice.type GAUGE" + echo "voice.colour ${three_color[2]}" + echo "voice.min 0" + echo "voice.info avg delay for Voice packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "voice.negative voice_in" + + exit 0 + fi + + if [ "$diffserv_no" == "4" ]; then + + if [ "$has_if_in" -eq "0" ]; then + echo "bulk_in.label Bulk" + echo "bulk_in.type GAUGE" + echo "bulk_in.colour ${four_color[0]}" + echo "bulk_in.min 0" + echo "bulk_in.info avg delay for bulk packets thru cake" + echo "bulk_in.graph no" + fi + echo "bulk.label Bulk" + echo "bulk.type GAUGE" + echo "bulk.colour ${four_color[0]}" + echo "bulk.min 0" + echo "bulk.info avg delay for bulk packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "bulk.negative bulk_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "besteffort_in.label Best Effort" + echo "besteffort_in.type GAUGE" + echo "besteffort_in.colour ${four_color[1]}" + echo "besteffort_in.min 0" + echo "besteffort_in.info avg delay for best effort packets thru cake" + echo "besteffort_in.graph no" + fi + echo "besteffort.label Best Effort" + echo "besteffort.type GAUGE" + echo "besteffort.colour ${four_color[1]}" + echo "besteffort.min 0" + echo "besteffort.info avg delay for best effort packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "besteffort.negative besteffort_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "video_in.label Video" + echo "video_in.type GAUGE" + echo "video_in.colour ${four_color[2]}" + echo "video_in.min 0" + echo "video_in.info avg delay for Video packets thru cake" + echo "video_in.graph no" + fi + echo "video.label Video" + echo "video.type GAUGE" + echo "video.colour ${four_color[2]}" + echo "video.min 0" + echo "video.info avg delay for Video packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "video.negative video_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "voice_in.label Voice" + echo "voice_in.type GAUGE" + echo "voice_in.colour ${four_color[3]}" + echo "voice_in.min 0" + echo "voice_in.info avg delay for Voice packets thru cake" + echo "voice_in.graph no" + fi + echo "voice.label Voice" + echo "voice.type GAUGE" + echo "voice.colour ${four_color[3]}" + echo "voice.min 0" + echo "voice.info avg delay for Voice packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "voice.negative voice_in" + + exit 0 + fi + + if [ "$diffserv_no" == "8" ]; then + + if [ "$has_if_in" -eq "0" ]; then + echo "tin1_in.label Tin 1" + echo "tin1_in.type GAUGE" + echo "tin1.colour ${eight_color[0]}" + echo "tin1_in.min 0" + echo "tin1_in.info avg delay for Tin 1 packets thru cake" + echo "tin1_in.graph no" + fi + echo "tin1.label Tin 1" + echo "tin1.type GAUGE" + echo "tin1.colour ${eight_color[0]}" + echo "tin1.min 0" + echo "tin1.info avg delay for Tin 1 packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "tin1.negative tin1_in" + + for i in `seq 2 8`; do + if [ "$has_if_in" -eq "0" ]; then + echo "tin${i}_in.label Tin $i" + echo "tin${i}_in.type GAUGE" + echo "tin${i}_in.colour ${eight_color[$((i - 1))]}" + echo "tin${i}_in.min 0" + echo "tin${i}_in.info avg delay for Tin $i packets thru cake" + echo "tin${i}_in.graph no" + fi + echo "tin${i}.label Tin $i" + echo "tin${i}.type GAUGE" + echo "tin${i}.colour ${eight_color[$((i - 1))]}" + echo "tin${i}.min 0" + echo "tin${i}.info avg delay for Tin $i packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "tin${i}.negative tin${i}_in" + done + + exit 0 + fi + ;; +esac + +if [ "$diffserv_no" == "3" ]; then + tc_cake_get_delays "$DEVICE" | awk '{ + print "bulk.value " $1 + print "besteffort.value " $2 + print "voice.value " $3 + }' + if [ "$has_if_in" -eq "0" ]; then + tc_cake_get_delays "$DEVICE_IN" | awk '{ + print "bulk_in.value " $1 + print "besteffort_in.value " $2 + print "voice_in.value " $3 + }' + fi + exit 0 +fi +if [ "$diffserv_no" == "4" ]; then + tc_cake_get_delays "$DEVICE" | awk '{ + print "bulk.value " $1 + print "besteffort.value " $2 + print "video.value " $3 + print "voice.value " $4 + }' + if [ "$has_if_in" -eq "0" ]; then + tc_cake_get_delays "$DEVICE_IN" | awk '{ + print "bulk_in.value " $1 + print "besteffort_in.value " $2 + print "video_in.value " $3 + print "voice_in.value " $4 + }' + fi + exit 0 +fi +if [ "$diffserv_no" == "8" ]; then + tc_cake_get_delays "$DEVICE" | awk '{ + print "tin1.value " $1 + print "tin2.value " $2 + print "tin3.value " $3 + print "tin4.value " $4 + print "tin5.value " $5 + print "tin6.value " $6 + print "tin7.value " $7 + print "tin8.value " $8 + }' + if [ "$has_if_in" -eq "0" ]; then + tc_cake_get_delays "$DEVICE_IN" | awk '{ + print "tin1_in.value " $1 + print "tin2_in.value " $2 + print "tin3_in.value " $3 + print "tin4_in.value " $4 + print "tin5_in.value " $5 + print "tin6_in.value " $6 + print "tin7_in.value " $7 + print "tin8_in.value " $8 + }' + fi + exit 0 +fi + + +echo "cake_tin_delay_: no diffserv or unknown parameter set (best effort?)" >&2 +exit 1 diff --git a/plugins/cake/cake_tin_ecn_ b/plugins/cake/cake_tin_ecn_ new file mode 100755 index 000000000..3310dcbaf --- /dev/null +++ b/plugins/cake/cake_tin_ecn_ @@ -0,0 +1,381 @@ +#!/bin/bash +# -*- sh -*- + +: << =cut + +=pod + +=encoding UTF-8 + +=head1 NAME + +cake_tin_ecn_ - Plugin to monitor cake's ecn marks per tin + +=head1 CONFIGURATION + +None needed. + +=head1 INTERPRETATION + +Cake, also known as sch_cake is a modern bandwidth limiter, which eliminates +buffer bloat over slow links. It's also capable to give flows, hosts and each +flow of each host a fair part of the avaible bandwidth. + +This plugin allows for a monitoring ecn packet marks per tin on the qdisc. + +=head1 SEE ALSO + +Take a look at "man cake" to get more information about cake. + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf suggest + +=head1 AUTHORS + +RubenKelevra + +work based on the tc plugin, authors: +Steve Schnepp , +Samuel Smith , +Nye Liu + +=head1 LICENSE + +GPLv2 or later + +=cut + +DEVICE="${0##*/cake_tin_ecn_}" + +#static color paletts + +# green/blue -> red +eight_color=("006b5f" "1a9850" "66bd63" "a6d96a" "fdae61" "f46d43" "d73027" "9427d7") +four_color=("3288bd" "abdda4" "fdae61" "d53e4f") +three_color=("3288bd" "abdda4" "d53e4f") + +tc_get_ifb_dev() { + dev="$(/sbin/tc filter show dev "$DEVICE" parent ffff: protocol all | grep "mirred" | grep "Egress Redirect to device")" + [ "$?" -eq "1" ] && return 1 + + echo "$dev" | sed -n 's/.* device \([^ ]*\).*/\1/p' | tr ')' ' ' | awk '{ print $1 }' +} + +tc_cake_get_diffserv() { + /sbin/tc -s qdisc show dev "$1" | head -n1 | grep -i "diffserv3" > /dev/null + if [ "$?" -eq "0" ]; then + echo 3 + fi + /sbin/tc -s qdisc show dev "$1" | head -n1 | grep -i "diffserv4" > /dev/null + if [ "$?" -eq "0" ]; then + echo 4 + fi + /sbin/tc -s qdisc show dev "$1" | head -n1 | grep -i "diffserv8" > /dev/null + if [ "$?" -eq "0" ]; then + echo 8 + fi + return 0 +} + +tc_cake_get_marks() { + /sbin/tc -s qdisc show dev "$1" | grep "^ marks" +} + +DEVICE_IN="$(tc_get_ifb_dev)" +has_if_in=$? + +diffserv_no="$(tc_cake_get_diffserv "$DEVICE")" +if [ "$has_if_in" -eq "0" ]; then + diffserv_in_no="$(tc_cake_get_diffserv "$DEVICE_IN")" + + if [ ! "$diffserv_no" == "$diffserv_in_no" ]; then + echo "cake_tin_delay_: diffserv setting different between egress and ingress device - this cannot be plotted, exiting" >&2 + exit 1 + fi +fi + +case "$1" in + autoconf) + if [ -r /proc/net/dev ]; then + echo yes + exit 0 + else + echo "no (/proc/net/dev not found)" + exit 1 + fi + ;; + suggest) + if [ -r /proc/net/dev ]; then + ifs="$(awk ' + /^ *(eth|tap|bond|wlan|ath|ra|sw|eno|ens|enp|wlp|wl)[0-9]*/ { + split($0, a, /: */); + gsub(/^ +/,"",a[1]); + if (($2 > 0) || ($10 > 0)) print a[1]; }' /proc/net/dev)" + cake_ifs=() + for if in $ifs; do + qdisc="$(/sbin/tc -s qdisc show dev "$if" | head -n1 | awk '{ print $2 }')" + if [ "$qdisc" == "cake" ]; then + cake_ifs+=("$if") + fi + done + echo "${cake_ifs[@]}" + fi + exit 0 + ;; + config) + + if [ "$has_if_in" -eq "0" ]; then + echo "graph_title $DEVICE ($DEVICE_IN) cake tin ecn marks" + else + echo "graph_title $DEVICE cake tin ecn marks" + fi + + echo 'graph_args --base 1000' + if [ "$has_if_in" -eq "0" ]; then + echo 'graph_vlabel packet marks/s in (-) / out (+)' + else + echo 'graph_vlabel packet marks/s' + fi + + echo 'graph_category network' + if [ "$has_if_in" -eq "0" ]; then + echo "graph_info This graph shows the ecn marks on packages per tin of egress+ingress traffic of the $DEVICE ($DEVICE_IN) network interface." + else + echo "graph_info This graph shows the ecn marks on packages per tin of egress traffic of the $DEVICE network interface." + fi + + if [ "$diffserv_no" == "3" ]; then + + if [ "$has_if_in" -eq "0" ]; then + echo "bulk_in.label Bulk" + echo "bulk_in.draw AREA" + echo "bulk_in.colour ${three_color[0]}" + echo "bulk_in.type DERIVE" + echo "bulk_in.min 0" + echo "bulk_in.info bulk packets with ecn marks thru cake" + echo "bulk_in.graph no" + fi + echo "bulk.label Bulk" + echo "bulk.draw AREA" + echo "bulk.colour ${three_color[0]}" + echo "bulk.type DERIVE" + echo "bulk.min 0" + echo "bulk.info bulk packets with ecn marks thru cake" + [ "$has_if_in" -eq "0" ] && echo "bulk.negative bulk_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "besteffort_in.label Best Effort" + echo "besteffort_in.draw STACK" + echo "besteffort_in.colour ${three_color[1]}" + echo "besteffort_in.type DERIVE" + echo "besteffort_in.min 0" + echo "besteffort_in.info best effort packets with ecn marks thru cake" + echo "besteffort_in.graph no" + fi + echo "besteffort.label Best Effort" + echo "besteffort.draw STACK" + echo "besteffort.colour ${three_color[1]}" + echo "besteffort.type DERIVE" + echo "besteffort.min 0" + echo "besteffort.info best effort packets with ecn marks thru cake" + [ "$has_if_in" -eq "0" ] && echo "besteffort.negative besteffort_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "voice_in.label Voice" + echo "voice_in.draw STACK" + echo "voice_in.colour ${three_color[2]}" + echo "voice_in.type DERIVE" + echo "voice_in.min 0" + echo "voice_in.info Voice packets with ecn marks thru cake" + echo "voice_in.graph no" + fi + echo "voice.label Voice" + echo "voice.draw STACK" + echo "voice.colour ${three_color[2]}" + echo "voice.type DERIVE" + echo "voice.min 0" + echo "voice.info Voice packets with ecn marks thru cake" + [ "$has_if_in" -eq "0" ] && echo "voice.negative voice_in" + + exit 0 + fi + + if [ "$diffserv_no" == "4" ]; then + + if [ "$has_if_in" -eq "0" ]; then + echo "bulk_in.label Bulk" + echo "bulk_in.draw AREA" + echo "bulk_in.colour ${four_color[0]}" + echo "bulk_in.type DERIVE" + echo "bulk_in.min 0" + echo "bulk_in.info bulk packets with ecn marks thru cake" + echo "bulk_in.graph no" + fi + echo "bulk.label Bulk" + echo "bulk.draw AREA" + echo "bulk.colour ${four_color[0]}" + echo "bulk.type DERIVE" + echo "bulk.min 0" + echo "bulk.info bulk packets with ecn marks thru cake" + [ "$has_if_in" -eq "0" ] && echo "bulk.negative bulk_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "besteffort_in.label Best Effort" + echo "besteffort_in.draw STACK" + echo "besteffort_in.colour ${four_color[1]}" + echo "besteffort_in.type DERIVE" + echo "besteffort_in.min 0" + echo "besteffort_in.info best effort packets with ecn marks thru cake" + echo "besteffort_in.graph no" + fi + echo "besteffort.label Best Effort" + echo "besteffort.draw STACK" + echo "besteffort.colour ${four_color[1]}" + echo "besteffort.type DERIVE" + echo "besteffort.min 0" + echo "besteffort.info best effort packets with ecn marks thru cake" + [ "$has_if_in" -eq "0" ] && echo "besteffort.negative besteffort_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "video_in.label Video" + echo "video_in.draw STACK" + echo "video_in.colour ${four_color[2]}" + echo "video_in.type DERIVE" + echo "video_in.min 0" + echo "video_in.info Video packets with ecn marks thru cake" + echo "video_in.graph no" + fi + echo "video.label Video" + echo "video.draw STACK" + echo "video.colour ${four_color[2]}" + echo "video.type DERIVE" + echo "video.min 0" + echo "video.info Video packets with ecn marks thru cake" + [ "$has_if_in" -eq "0" ] && echo "video.negative video_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "voice_in.label Voice" + echo "voice_in.draw STACK" + echo "voice_in.colour ${four_color[3]}" + echo "voice_in.type DERIVE" + echo "voice_in.min 0" + echo "voice_in.info Voice packets with ecn marks thru cake" + echo "voice_in.graph no" + fi + echo "voice.label Voice" + echo "voice.draw STACK" + echo "voice.colour ${four_color[3]}" + echo "voice.type DERIVE" + echo "voice.min 0" + echo "voice.info Voice packets with ecn marks thru cake" + [ "$has_if_in" -eq "0" ] && echo "voice.negative voice_in" + + exit 0 + fi + + if [ "$diffserv_no" == "8" ]; then + + if [ "$has_if_in" -eq "0" ]; then + echo "tin1_in.label Tin 1" + echo "tin1_in.draw AREA" + echo "tin1.colour ${eight_color[0]}" + echo "tin1_in.type DERIVE" + echo "tin1_in.min 0" + echo "tin1_in.info Tin 1 packets with ecn marks thru cake" + echo "tin1_in.graph no" + fi + echo "tin1.label Tin 1" + echo "tin1.draw AREA" + echo "tin1.colour ${eight_color[0]}" + echo "tin1.type DERIVE" + echo "tin1.min 0" + echo "tin1.info Tin 1 packets with ecn marks thru cake" + [ "$has_if_in" -eq "0" ] && echo "tin1.negative tin1_in" + + for i in `seq 2 8`; do + if [ "$has_if_in" -eq "0" ]; then + echo "tin${i}_in.label Tin $i" + echo "tin${i}_in.draw STACK" + echo "tin${i}_in.colour ${eight_color[$((i - 1))]}" + echo "tin${i}_in.type DERIVE" + echo "tin${i}_in.min 0" + echo "tin${i}_in.info Tin $i packets with ecn marks thru cake" + echo "tin${i}_in.graph no" + fi + echo "tin${i}.label Tin $i" + echo "tin${i}.draw STACK" + echo "tin${i}.colour ${eight_color[$((i - 1))]}" + echo "tin${i}.type DERIVE" + echo "tin${i}.min 0" + echo "tin${i}.info Tin $i packets with ecn marks thru cake" + [ "$has_if_in" -eq "0" ] && echo "tin${i}.negative tin${i}_in" + done + + exit 0 + fi + ;; +esac + +if [ "$diffserv_no" == "3" ]; then + tc_cake_get_marks "$DEVICE" | awk '{ + print "bulk.value " $2 + print "besteffort.value " $3 + print "voice.value " $4 + }' + if [ "$has_if_in" -eq "0" ]; then + tc_cake_get_marks "$DEVICE_IN" | awk '{ + print "bulk_in.value " $2 + print "besteffort_in.value " $3 + print "voice_in.value " $4 + }' + fi + exit 0 +fi +if [ "$diffserv_no" == "4" ]; then + tc_cake_get_marks "$DEVICE" | awk '{ + print "bulk.value " $2 + print "besteffort.value " $3 + print "video.value " $4 + print "voice.value " $5 + }' + if [ "$has_if_in" -eq "0" ]; then + tc_cake_get_marks "$DEVICE_IN" | awk '{ + print "bulk_in.value " $2 + print "besteffort_in.value " $3 + print "video_in.value " $4 + print "voice_in.value " $5 + }' + fi + exit 0 +fi +if [ "$diffserv_no" == "8" ]; then + tc_cake_get_marks "$DEVICE" | awk '{ + print "tin1.value " $2 + print "tin2.value " $3 + print "tin3.value " $4 + print "tin4.value " $5 + print "tin5.value " $6 + print "tin6.value " $7 + print "tin7.value " $8 + print "tin8.value " $9 + }' + if [ "$has_if_in" -eq "0" ]; then + tc_cake_get_marks "$DEVICE_IN" | awk '{ + print "tin1_in.value " $2 + print "tin2_in.value " $3 + print "tin3_in.value " $4 + print "tin4_in.value " $5 + print "tin5_in.value " $6 + print "tin6_in.value " $7 + print "tin7_in.value " $8 + print "tin8_in.value " $9 + }' + fi + exit 0 +fi + + +echo "cake_tin_ecn_: no diffserv or unknown parameter set (best effort?)" >&2 +exit 1 diff --git a/plugins/cake/cake_tin_pps_ b/plugins/cake/cake_tin_pps_ new file mode 100755 index 000000000..7d4dcfa52 --- /dev/null +++ b/plugins/cake/cake_tin_pps_ @@ -0,0 +1,376 @@ +#!/bin/bash +# -*- sh -*- + +: << =cut + +=pod + +=encoding UTF-8 + +=head1 NAME + +cake_tin_pps_ - Plugin to monitor cake's tin' pps + +=head1 CONFIGURATION + +None needed. + +=head1 INTERPRETATION + +Cake, also known as sch_cake is a modern bandwidth limiter, which eliminates +buffer bloat over slow links. It's also capable to give flows, hosts and each +flow of each host a fair part of the avaible bandwidth. + +This plugin allows for a monitoring packets per tins on the qdisc. + +=head1 SEE ALSO + +Take a look at "man cake" to get more information about cake. + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf suggest + +=head1 AUTHORS + +RubenKelevra + +work based on the tc plugin, authors: +Steve Schnepp , +Samuel Smith , +Nye Liu + +=head1 LICENSE + +GPLv2 or later + +=cut + +DEVICE="${0##*/cake_tin_pps_}" + +# green/blue -> red +eight_color=("006b5f" "1a9850" "66bd63" "a6d96a" "fdae61" "f46d43" "d73027" "9427d7") +four_color=("3288bd" "abdda4" "fdae61" "d53e4f") +three_color=("3288bd" "abdda4" "d53e4f") + +tc_get_ifb_dev() { + dev="$(/sbin/tc filter show dev "$DEVICE" parent ffff: protocol all | grep "mirred" | grep "Egress Redirect to device")" + [ "$?" -eq "1" ] && return 1 + + echo "$dev" | sed -n 's/.* device \([^ ]*\).*/\1/p' | tr ')' ' ' | awk '{ print $1 }' +} + +tc_cake_get_diffserv() { + /sbin/tc -s qdisc show dev "$1" | head -n1 | grep -i "diffserv3" > /dev/null + if [ "$?" -eq "0" ]; then + echo 3 + fi + /sbin/tc -s qdisc show dev "$1" | head -n1 | grep -i "diffserv4" > /dev/null + if [ "$?" -eq "0" ]; then + echo 4 + fi + /sbin/tc -s qdisc show dev "$1" | head -n1 | grep -i "diffserv8" > /dev/null + if [ "$?" -eq "0" ]; then + echo 8 + fi + return 0 +} + +tc_cake_get_pkts() { + /sbin/tc -s qdisc show dev "$1" | grep "^ pkts" +} + +DEVICE_IN="$(tc_get_ifb_dev)" +has_if_in=$? + +diffserv_no="$(tc_cake_get_diffserv "$DEVICE")" +if [ "$has_if_in" -eq "0" ]; then + diffserv_in_no="$(tc_cake_get_diffserv "$DEVICE_IN")" + + if [ ! "$diffserv_no" == "$diffserv_in_no" ]; then + echo "cake_tin_pps_: diffserv setting different between egress and ingress device - this cannot be plotted, exiting" >&2 + exit 1 + fi +fi + +case "$1" in + autoconf) + if [ -r /proc/net/dev ]; then + echo yes + exit 0 + else + echo "no (/proc/net/dev not found)" + exit 1 + fi + ;; + suggest) + if [ -r /proc/net/dev ]; then + ifs="$(awk ' + /^ *(eth|tap|bond|wlan|ath|ra|sw|eno|ens|enp|wlp|wl)[0-9]*/ { + split($0, a, /: */); + gsub(/^ +/,"",a[1]); + if (($2 > 0) || ($10 > 0)) print a[1]; }' /proc/net/dev)" + cake_ifs=() + for if in $ifs; do + qdisc="$(/sbin/tc -s qdisc show dev "$if" | head -n1 | awk '{ print $2 }')" + if [ "$qdisc" == "cake" ]; then + cake_ifs+=("$if") + fi + done + echo "${cake_ifs[@]}" + fi + exit 0 + ;; + config) + + if [ "$has_if_in" -eq "0" ]; then + echo "graph_title $DEVICE ($DEVICE_IN) cake QoS tin packet throughput" + else + echo "graph_title $DEVICE cake QoS tin packet throughput" + fi + echo 'graph_args --base 1000' + if [ "$has_if_in" -eq "0" ]; then + echo 'graph_vlabel pps in (-) / out (+)' + else + echo 'graph_vlabel packets per second' + fi + echo 'graph_category network' + if [ "$has_if_in" -eq "0" ]; then + echo "graph_info This graph shows the packages per tin of egress+ingress traffic of the $DEVICE ($DEVICE_IN) network interface." + else + echo "graph_info This graph shows the packages per tin of egress traffic of the $DEVICE network interface." + fi + + if [ "$diffserv_no" == "3" ]; then + + if [ "$has_if_in" -eq "0" ]; then + echo "bulk_in.label Bulk" + echo "bulk_in.draw AREA" + echo "bulk_in.colour ${three_color[0]}" + echo "bulk_in.type DERIVE" + echo "bulk_in.min 0" + echo "bulk_in.info sent bulk packets thru cake" + echo "bulk_in.graph no" + fi + echo "bulk.label Bulk" + echo "bulk.draw AREA" + echo "bulk.colour ${three_color[0]}" + echo "bulk.type DERIVE" + echo "bulk.min 0" + echo "bulk.info sent bulk packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "bulk.negative bulk_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "besteffort_in.label Best Effort" + echo "besteffort_in.draw STACK" + echo "besteffort_in.colour ${three_color[1]}" + echo "besteffort_in.type DERIVE" + echo "besteffort_in.min 0" + echo "besteffort_in.info sent best effort packets thru cake" + echo "besteffort_in.graph no" + fi + echo "besteffort.label Best Effort" + echo "besteffort.draw STACK" + echo "besteffort.colour ${three_color[1]}" + echo "besteffort.type DERIVE" + echo "besteffort.min 0" + echo "besteffort.info sent best effort packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "besteffort.negative besteffort_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "voice_in.label Voice" + echo "voice_in.draw STACK" + echo "voice_in.colour ${three_color[2]}" + echo "voice_in.type DERIVE" + echo "voice_in.min 0" + echo "voice_in.info sent Voice packets thru cake" + echo "voice_in.graph no" + fi + echo "voice.label Voice" + echo "voice.draw STACK" + echo "voice.colour ${three_color[2]}" + echo "voice.type DERIVE" + echo "voice.min 0" + echo "voice.info sent Voice packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "voice.negative voice_in" + + exit 0 + fi + + if [ "$diffserv_no" == "4" ]; then + + if [ "$has_if_in" -eq "0" ]; then + echo "bulk_in.label Bulk" + echo "bulk_in.draw AREA" + echo "bulk_in.colour ${four_color[0]}" + echo "bulk_in.type DERIVE" + echo "bulk_in.min 0" + echo "bulk_in.info sent bulk packets thru cake" + echo "bulk_in.graph no" + fi + echo "bulk.label Bulk" + echo "bulk.draw AREA" + echo "bulk.colour ${four_color[0]}" + echo "bulk.type DERIVE" + echo "bulk.min 0" + echo "bulk.info sent bulk packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "bulk.negative bulk_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "besteffort_in.label Best Effort" + echo "besteffort_in.draw STACK" + echo "besteffort_in.colour ${four_color[1]}" + echo "besteffort_in.type DERIVE" + echo "besteffort_in.min 0" + echo "besteffort_in.info sent best effort packets thru cake" + echo "besteffort_in.graph no" + fi + echo "besteffort.label Best Effort" + echo "besteffort.draw STACK" + echo "besteffort.colour ${four_color[1]}" + echo "besteffort.type DERIVE" + echo "besteffort.min 0" + echo "besteffort.info sent best effort packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "besteffort.negative besteffort_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "video_in.label Video" + echo "video_in.draw STACK" + echo "video_in.colour ${four_color[2]}" + echo "video_in.type DERIVE" + echo "video_in.min 0" + echo "video_in.info sent Video packets thru cake" + echo "video_in.graph no" + fi + echo "video.label Video" + echo "video.draw STACK" + echo "video.colour ${four_color[2]}" + echo "video.type DERIVE" + echo "video.min 0" + echo "video.info sent Video packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "video.negative video_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "voice_in.label Voice" + echo "voice_in.draw STACK" + echo "voice_in.colour ${four_color[3]}" + echo "voice_in.type DERIVE" + echo "voice_in.min 0" + echo "voice_in.info sent Voice packets thru cake" + echo "voice_in.graph no" + fi + echo "voice.label Voice" + echo "voice.draw STACK" + echo "voice.colour ${four_color[3]}" + echo "voice.type DERIVE" + echo "voice.min 0" + echo "voice.info sent Voice packets thru cake" + [ "$has_if_in" -eq "0" ] && echo "voice.negative voice_in" + + exit 0 + fi + + if [ "$diffserv_no" == "8" ]; then + if [ "$has_if_in" -eq "0" ]; then + echo "tin1_in.label Tin 1" + echo "tin1_in.draw AREA" + echo "tin1.colour ${eight_color[0]}" + echo "tin1_in.type DERIVE" + echo "tin1_in.min 0" + echo "tin1_in.info sent Tin $i packets with ecn marks thru cake" + echo "tin1_in.graph no" + fi + echo "tin1.label Tin 1" + echo "tin1.draw AREA" + echo "tin1.colour ${eight_color[0]}" + echo "tin1.type DERIVE" + echo "tin1.min 0" + echo "tin1.info sent Tin $i packets with ecn marks thru cake" + [ "$has_if_in" -eq "0" ] && echo "tin1.negative tin1_in" + + for i in `seq 2 8`; do + if [ "$has_if_in" -eq "0" ]; then + echo "tin${i}_in.label Tin $i" + echo "tin${i}_in.draw STACK" + echo "tin${i}_in.colour ${eight_color[$((i - 1))]}" + echo "tin${i}_in.type DERIVE" + echo "tin${i}_in.min 0" + echo "tin${i}_in.info Tin $i packets with ecn marks thru cake" + echo "tin${i}_in.graph no" + fi + echo "tin${i}.label Tin $i" + echo "tin${i}.draw STACK" + echo "tin${i}.colour ${eight_color[$((i - 1))]}" + echo "tin${i}.type DERIVE" + echo "tin${i}.min 0" + echo "tin${i}.info Tin $i packets with ecn marks thru cake" + [ "$has_if_in" -eq "0" ] && echo "tin${i}.negative tin${i}_in" + done + + exit 0 + fi + ;; +esac + +if [ "$diffserv_no" == "3" ]; then + tc_cake_get_pkts "$DEVICE" | awk '{ + print "bulk.value " $2 + print "besteffort.value " $3 + print "voice.value " $4 + }' + if [ "$has_if_in" -eq "0" ]; then + tc_cake_get_pkts "$DEVICE_IN" | awk '{ + print "bulk_in.value " $2 + print "besteffort_in.value " $3 + print "voice_in.value " $4 + }' + fi + exit 0 +fi +if [ "$diffserv_no" == "4" ]; then + tc_cake_get_pkts "$DEVICE" | awk '{ + print "bulk.value " $2 + print "besteffort.value " $3 + print "video.value " $4 + print "voice.value " $5 + }' + if [ "$has_if_in" -eq "0" ]; then + tc_cake_get_pkts "$DEVICE_IN" | awk '{ + print "bulk_in.value " $2 + print "besteffort_in.value " $3 + print "video_in.value " $4 + print "voice_in.value " $5 + }' + fi + exit 0 +fi +if [ "$diffserv_no" == "8" ]; then + tc_cake_get_pkts "$DEVICE" | awk '{ + print "tin1.value " $2 + print "tin2.value " $3 + print "tin3.value " $4 + print "tin4.value " $5 + print "tin5.value " $6 + print "tin6.value " $7 + print "tin7.value " $8 + print "tin8.value " $9 + }' + if [ "$has_if_in" -eq "0" ]; then + tc_cake_get_pkts "$DEVICE_IN" | awk '{ + print "tin1_in.value " $2 + print "tin2_in.value " $3 + print "tin3_in.value " $4 + print "tin4_in.value " $5 + print "tin5_in.value " $6 + print "tin6_in.value " $7 + print "tin7_in.value " $8 + print "tin8_in.value " $9 + }' + fi + exit 0 +fi + + +echo "cake_tin_pps_: no diffserv or unknown parameter set (best effort?)" >&2 +exit 1 diff --git a/plugins/cake/cake_tin_throughput_ b/plugins/cake/cake_tin_throughput_ new file mode 100755 index 000000000..20aa14377 --- /dev/null +++ b/plugins/cake/cake_tin_throughput_ @@ -0,0 +1,470 @@ +#!/bin/bash +# -*- sh -*- + +: << =cut + +=pod + +=encoding UTF-8 + +=head1 NAME + +cake_tin_throughput_ - Plugin to monitor cake's bandwidth utilization + +=head1 CONFIGURATION + +None needed. + +=head1 INTERPRETATION + +Cake, also known as sch_cake is a modern bandwidth limiter, which eliminates +buffer bloat over slow links. It's also capable to give flows, hosts and each +flow of each host a fair part of the avaible bandwidth. + +This plugin allows for a monitoring of cake's bandwidth utilization. + +=head1 SEE ALSO + +Take a look at "man cake" to get more information about cake. + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf suggest + +=head1 AUTHORS + +RubenKelevra + +work based on the tc plugin, authors: +Steve Schnepp , +Samuel Smith , +Nye Liu + +=head1 LICENSE + +GPLv2 or later + +=cut + +DEVICE="${0##*/cake_tin_throughput_}" + +# green/blue -> red +eight_color=("006b5f" "1a9850" "66bd63" "a6d96a" "fdae61" "f46d43" "d73027" "9427d7") +four_color=("3288bd" "abdda4" "fdae61" "d53e4f") +three_color=("3288bd" "abdda4" "d53e4f") + +tc_get_ifb_dev() { + dev="$(/sbin/tc filter show dev "$DEVICE" parent ffff: protocol all | grep "mirred" | grep "Egress Redirect to device")" + [ "$?" -eq "1" ] && return 1 + + echo "$dev" | sed -n 's/.* device \([^ ]*\).*/\1/p' | tr ')' ' ' | awk '{ print $1 }' +} + +tc_cake_get_diffserv() { + /sbin/tc -s qdisc show dev "$1" | head -n1 | grep -i "diffserv3" > /dev/null + if [ "$?" -eq "0" ]; then + echo 3 + fi + /sbin/tc -s qdisc show dev "$1" | head -n1 | grep -i "diffserv4" > /dev/null + if [ "$?" -eq "0" ]; then + echo 4 + fi + /sbin/tc -s qdisc show dev "$1" | head -n1 | grep -i "diffserv8" > /dev/null + if [ "$?" -eq "0" ]; then + echo 8 + fi + return 0 +} + +tc_cake_get_bandwidth() { + bandwidth="$(/sbin/tc -s qdisc show dev "$1" | grep "^ capacity estimate" | sed -e 's/capacity estimate://' | awk '{ print $1 }')" + convert_bit "$bandwidth" +} + +tc_cake_get_bits() { + bytes="$(/sbin/tc -s qdisc show dev "$1" | grep "^ bytes" | sed -e 's/bytes//')" + for e in ${bytes[@]}; do + bits="$(convert_byte_to_bit $e)" + echo -en " $bits " + done + echo "" +} + +convert_byte_to_bit() { + #convert byte into bit + echo "$1" | awk '{ + bit = $1; + sub(/[A-Za-z]+$/, "", bit); + + bit *= 8; + + print bit + }' +} + +convert_bit() { + #converts Tbit, Gbit, Mbit, Kbit into bit without a unit + echo "$1" | awk '{ + bit = $1; + sub(/[A-Za-z]+$/, "", bit); + unit = $1; + sub(/^[^A-Za-z]+/, "", unit); + + if (unit == "Tbit") { + bit *= 1000000000000; + } else if (unit == "Gbit") { + bit *= 1000000000; + } else if (unit == "Mbit") { + bit *= 1000000; + } else if (unit == "Kbit") { + bit *= 1000; + } else if (unit == "bit") { + bit = bit; + } + print bit + }' +} + +DEVICE_IN="$(tc_get_ifb_dev)" +has_if_in=$? + +diffserv_no="$(tc_cake_get_diffserv "$DEVICE")" +if [ "$has_if_in" -eq "0" ]; then + diffserv_in_no="$(tc_cake_get_diffserv "$DEVICE_IN")" + + if [ ! "$diffserv_no" == "$diffserv_in_no" ]; then + echo "cake_tin_throughput_: diffserv setting different between egress and ingress device - this cannot be plotted, exiting" >&2 + exit 1 + fi +fi + +case "$1" in + autoconf) + if [ -r /proc/net/dev ]; then + echo yes + exit 0 + else + echo "no (/proc/net/dev not found)" + exit 1 + fi + ;; + suggest) + if [ -r /proc/net/dev ]; then + ifs="$(awk ' + /^ *(eth|tap|bond|wlan|ath|ra|sw|eno|ens|enp|wlp|wl)[0-9]*/ { + split($0, a, /: */); + gsub(/^ +/,"",a[1]); + if (($2 > 0) || ($10 > 0)) print a[1]; }' /proc/net/dev)" + cake_ifs=() + for if in $ifs; do + qdisc="$(/sbin/tc -s qdisc show dev "$if" | head -n1 | awk '{ print $2 }')" + if [ "$qdisc" == "cake" ]; then + cake_ifs+=("$if") + fi + done + echo "${cake_ifs[@]}" + fi + exit 0 + ;; + config) + + if [ "$has_if_in" -eq "0" ]; then + echo "graph_title $DEVICE ($DEVICE_IN) cake throughput" + else + echo "graph_title $DEVICE cake throughput" + fi + echo 'graph_args --base 1000' + if [ "$has_if_in" -eq "0" ]; then + echo 'graph_vlabel bit/s in (-) / out (+)' + else + echo 'graph_vlabel bit/s' + fi + echo 'graph_category network' + if [ "$has_if_in" -eq "0" ]; then + echo "graph_info This graph shows the bits per second per tin of egress+ingress traffic of the $DEVICE ($DEVICE_IN) network interface as well as the general bandwidth limit." + else + echo "graph_info This graph shows the bits per second per tin of egress traffic of the $DEVICE network interface as well as the general bandwidth limit." + fi + + if [ "$diffserv_no" == "3" ]; then + + if [ "$has_if_in" -eq "0" ]; then + echo "bandwidth_in.label Bandwidth-Limit" + echo "bandwidth_in.type GAUGE" + echo "bandwidth_in.colour 27bdd7" + echo "bandwidth_in.min 0" + echo "bandwidth_in.info maximal bandwidth set for cake" + echo "bandwidth_in.graph no" + fi + echo "bandwidth.label Bandwidth-Limit" + echo "bandwidth.type GAUGE" + echo "bandwidth.colour 27bdd7" + echo "bandwidth.min 0" + echo "bandwidth.info maximal bandwidth set for cake" + [ "$has_if_in" -eq "0" ] && echo "bandwidth.negative bandwidth_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "bulk_in.label Bulk" + echo "bulk_in.type DERIVE" + echo "bulk_in.colour ${three_color[0]}" + echo "bulk_in.min 0" + echo "bulk_in.info sent Bulk bits thru cake" + echo "bulk_in.graph no" + fi + echo "bulk.label Bulk" + echo "bulk.type DERIVE" + echo "bulk.colour ${three_color[0]}" + echo "bulk.min 0" + echo "bulk.info sent Bulk bits thru cake" + [ "$has_if_in" -eq "0" ] && echo "bulk.negative bulk_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "besteffort_in.label Best Effort" + echo "besteffort_in.type DERIVE" + echo "besteffort_in.colour ${three_color[1]}" + echo "besteffort_in.min 0" + echo "besteffort_in.info sent Best Effort bits thru cake" + echo "besteffort_in.graph no" + fi + echo "besteffort.label Best Effort" + echo "besteffort.type DERIVE" + echo "besteffort.colour ${three_color[1]}" + echo "besteffort.min 0" + echo "besteffort.info sent Best Effort bits thru cake" + [ "$has_if_in" -eq "0" ] && echo "besteffort.negative besteffort_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "voice_in.label Voice" + echo "voice_in.type DERIVE" + echo "voice_in.colour ${three_color[2]}" + echo "voice_in.min 0" + echo "voice_in.info sent Voice bits thru cake" + echo "voice_in.graph no" + fi + echo "voice.label Voice" + echo "voice.type DERIVE" + echo "voice.colour ${three_color[2]}" + echo "voice.min 0" + echo "voice.info sent Voice bits thru cake" + [ "$has_if_in" -eq "0" ] && echo "voice.negative voice_in" + + exit 0 + fi + + if [ "$diffserv_no" == "4" ]; then + + if [ "$has_if_in" -eq "0" ]; then + echo "bandwidth_in.label Bandwidth-Limit" + echo "bandwidth_in.type GAUGE" + echo "bandwidth_in.colour 27bdd7" + echo "bandwidth_in.min 0" + echo "bandwidth_in.info maximal bandwidth set for cake" + echo "bandwidth_in.graph no" + fi + echo "bandwidth.label Bandwidth-Limit" + echo "bandwidth.colour 27bdd7" + echo "bandwidth.type GAUGE" + echo "bandwidth.min 0" + echo "bandwidth.info maximal bandwidth set for cake" + [ "$has_if_in" -eq "0" ] && echo "bandwidth.negative bandwidth_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "bulk_in.label Bulk" + echo "bulk_in.type DERIVE" + echo "bulk_in.colour ${four_color[0]}" + echo "bulk_in.min 0" + echo "bulk_in.info sent Bulk bits thru cake" + echo "bulk_in.graph no" + fi + echo "bulk.label Bulk" + echo "bulk.type DERIVE" + echo "bulk.colour ${four_color[0]}" + echo "bulk.min 0" + echo "bulk.info sent Bulk bits thru cake" + [ "$has_if_in" -eq "0" ] && echo "bulk.negative bulk_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "besteffort_in.label Best Effort" + echo "besteffort_in.type DERIVE" + echo "besteffort_in.colour ${four_color[1]}" + echo "besteffort_in.min 0" + echo "besteffort_in.info sent Best Effort bits thru cake" + echo "besteffort_in.graph no" + fi + echo "besteffort.label Best Effort" + echo "besteffort.type DERIVE" + echo "besteffort.colour ${four_color[1]}" + echo "besteffort.min 0" + echo "besteffort.info sent Best Effort bits thru cake" + [ "$has_if_in" -eq "0" ] && echo "besteffort.negative besteffort_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "video_in.label Video" + echo "video_in.draw STACK" + echo "video_in.colour ${four_color[2]}" + echo "video_in.type DERIVE" + echo "video_in.min 0" + echo "video_in.info sent Video bits thru cake" + echo "video_in.graph no" + fi + echo "video.label Video" + echo "video.draw STACK" + echo "video.colour ${four_color[2]}" + echo "video.type DERIVE" + echo "video.min 0" + echo "video.info sent Video bits thru cake" + [ "$has_if_in" -eq "0" ] && echo "video.negative video_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "voice_in.label Voice" + echo "voice_in.type DERIVE" + echo "voice_in.colour ${four_color[3]}" + echo "voice_in.min 0" + echo "voice_in.info sent Voice bits thru cake" + echo "voice_in.graph no" + fi + echo "voice.label Voice" + echo "voice.type DERIVE" + echo "voice.colour ${four_color[3]}" + echo "voice.min 0" + echo "voice.info sent Voice bits thru cake" + [ "$has_if_in" -eq "0" ] && echo "voice.negative voice_in" + + exit 0 + fi + + if [ "$diffserv_no" == "8" ]; then + + if [ "$has_if_in" -eq "0" ]; then + echo "bandwidth_in.label Bandwidth-Limit" + echo "bandwidth_in.type GAUGE" + echo "bandwidth_in.colour 27bdd7" + echo "bandwidth_in.min 0" + echo "bandwidth_in.info maximal bandwidth set for cake" + echo "bandwidth_in.graph no" + fi + echo "bandwidth.label Bandwidth-Limit" + echo "bandwidth.type GAUGE" + echo "bandwidth.colour 27bdd7" + echo "bandwidth.min 0" + echo "bandwidth.info maximal bandwidth set for cake" + [ "$has_if_in" -eq "0" ] && echo "bandwidth.negative bandwidth_in" + + if [ "$has_if_in" -eq "0" ]; then + echo "tin1_in.label Tin 1" + echo "tin1_in.draw AREA" + echo "tin1.colour ${eight_color[0]}" + echo "tin1_in.type DERIVE" + echo "tin1_in.min 0" + echo "tin1_in.info sent Tin 1 bits thru cake" + echo "tin1_in.graph no" + fi + echo "tin1.label Tin 1" + echo "tin1.draw AREA" + echo "tin1.colour ${eight_color[0]}" + echo "tin1.type DERIVE" + echo "tin1.min 0" + echo "tin1.info sent Tin 1 bits thru cake" + [ "$has_if_in" -eq "0" ] && echo "tin1.negative tin1_in" + + for i in `seq 2 8`; do + if [ "$has_if_in" -eq "0" ]; then + echo "tin${i}_in.label Tin $i" + echo "tin${i}_in.draw STACK" + echo "tin${i}_in.colour ${eight_color[$((i - 1))]}" + echo "tin${i}_in.type DERIVE" + echo "tin${i}_in.min 0" + echo "tin${i}_in.info sent Tin $i bits thru cake" + echo "tin${i}_in.graph no" + fi + echo "tin${i}.label Tin $i" + echo "tin${i}.draw STACK" + echo "tin${i}.colour ${eight_color[$((i - 1))]}" + echo "tin${i}.type DERIVE" + echo "tin${i}.min 0" + echo "tin${i}.info sent Tin $i bits thru cake" + [ "$has_if_in" -eq "0" ] && echo "tin${i}.negative tin${i}_in" + done + + exit 0 + fi + ;; +esac + +if [ "$diffserv_no" == "3" ]; then + echo "bandwidth.value $(tc_cake_get_bandwidth "$DEVICE")" + + tc_cake_get_bits "$DEVICE" | awk '{ + print "bulk.value " $1 + print "besteffort.value " $2 + print "voice.value " $3 + }' + + if [ "$has_if_in" -eq "0" ]; then + echo "bandwidth_in.value $(tc_cake_get_bandwidth "$DEVICE_IN")" + + tc_cake_get_bits "$DEVICE_IN" | awk '{ + print "bulk_in.value " $1 + print "besteffort_in.value " $2 + print "voice_in.value " $3 + }' + fi + exit 0 +fi +if [ "$diffserv_no" == "4" ]; then + echo "bandwidth.value $(tc_cake_get_bandwidth "$DEVICE")" + + tc_cake_get_bits "$DEVICE" | awk '{ + print "bulk.value " $1 + print "besteffort.value " $2 + print "video.value " $3 + print "voice.value " $4 + }' + + if [ "$has_if_in" -eq "0" ]; then + echo "bandwidth_in.value $(tc_cake_get_bandwidth "$DEVICE_IN")" + + tc_cake_get_bits "$DEVICE_IN" | awk '{ + print "bulk_in.value " $1 + print "besteffort_in.value " $2 + print "video_in.value " $3 + print "voice_in.value " $4 + }' + fi + exit 0 +fi +if [ "$diffserv_no" == "8" ]; then + echo "bandwidth.value $(tc_cake_get_bandwidth "$DEVICE")" + + tc_cake_get_bits "$DEVICE" | awk '{ + print "tin1.value " $1 + print "tin2.value " $2 + print "tin3.value " $3 + print "tin4.value " $4 + print "tin5.value " $5 + print "tin6.value " $6 + print "tin7.value " $7 + print "tin8.value " $8 + }' + + if [ "$has_if_in" -eq "0" ]; then + echo "bandwidth_in.value $(tc_cake_get_bandwidth "$DEVICE_IN")" + + tc_cake_get_bits "$DEVICE_IN" | awk '{ + print "tin1_in.value " $1 + print "tin2_in.value " $2 + print "tin3_in.value " $3 + print "tin4_in.value " $4 + print "tin5_in.value " $5 + print "tin6_in.value " $6 + print "tin7_in.value " $7 + print "tin8_in.value " $8 + }' + fi + exit 0 +fi + + +echo "cake_tin_throughput_: no diffserv or unknown parameter set (best effort?)" >&2 +exit 1