Skip to content

Instantly share code, notes, and snippets.

@maltechx
Last active January 10, 2020 23:35
Show Gist options
  • Save maltechx/5aca06b498be4e7286ea4f8afeb35a37 to your computer and use it in GitHub Desktop.
Save maltechx/5aca06b498be4e7286ea4f8afeb35a37 to your computer and use it in GitHub Desktop.
Netdata chart for Bandwith used since reboot
# no need for shebang - this file is loaded from charts.d.plugin
# netdata
# This has to go unter /usr/libexec/netdata/charts.d/bandwidth.chart.sh or /etc/netdata/charts.d/bandwidth.chart.sh or /opt/netdata/netdata-plugins/charts.d/bandwidth.chart.sh
# real-time performance and health monitoring, done right!
# (C) 2016 Costa Tsaousis <[email protected]>
bandwidth_update_every=1
bandwidth_priority=100
# Should this chart be enabled?
bandwidth_enabled=1
bandwidth_check() {
# - 0 to enable the chart
# - 1 to disable the chart
if [ ${bandwidth_update_every} -lt 1 ]
then
# there is no meaning for shorter than 1 seconds
# the kernel changes this value every 1 seconds
bandwidth_update_every=1
fi
[ ${bandwidth_enabled} -eq 0 ] && return 1
return 0
}
bandwidth_create() {
# Defines the "Style" of the Chart:
# CHART type.id name title units [family [context [charttype [priority [update_every [options [plugin [module]]]]]]]]
# DIMENSION id [name [algorithm [multiplier [divisor [hidden]]]]]
# see: https://github.com/firehol/netdata/wiki/External-Plugins
cat <<EOF
CHART system.bandwidth 'bandwidth' "System used bandwidth" "MBytes" "traffic" system.bandwidth line $((bandwidth_priority + 1)) $bandwidth_update_every
DIMENSION sent 'sent' absolute 1
DIMENSION recived 'recived' absolute 1
EOF
return 0
}
bandwidth_update() {
# Here should be all "magic" goes for calculate your measurements
sent=$[$(cat /proc/net/dev | grep $(ip route | grep default | awk '{print $5}') | awk '{print $10}')/1000000]
recived=$[$(cat /proc/net/dev | grep $(ip route | grep default | awk '{print $5}') | awk '{print $2}')/1000000]
cat <<VALUESEOF
BEGIN system.bandwidth
SET sent = ${sent}
SET recived = ${recived}
END
VALUESEOF
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment