How to create a graph of switch ports utilization?

I would like to monitor bandwidth usage of the switch ports. It is possible? If it is, then is it possible without bridging (aka forcing the traffic to go through the CPU before going back to other switch ports -- it sounds like a performance bottleneck to me)? I want something like this:

The only thing I can think of right now is scheduling an ash script to run at a 60-sec interval, which runs the command swconfig dev switch0 show to get the switch port statistics:

Port 0:
	mib: MIB counters
RxGoodByte  : 669494488 (638.4 MiB)
TxByte      : 6533390629 (6.0 GiB)

	pvid: 0
	link: port:0 link:up speed:1000baseT full-duplex txflow rxflow 
Port 1:
	mib: MIB counters
RxGoodByte  : 1283903310846 (1195.7 GiB)
TxByte      : 539614562573 (502.5 GiB)

... then manipulate the text to get the value, substract the current value with the previous run, output to a text file, import it to LibreOffice Calc / Excel, and create a graph. It is a pain to maintain, and most importantly the statistic outputs of all switches are not the same. For examle, the Cisco WRT320N outputs this instead (the MiB counter is nowhere to be found):

Port 0:
	mib: TxOctets            : 531222876444
TxDropPkts          : 0
TxBroadcastPkts     : 2513130
TxMulticastPkts     : 503873
TxUnicastPkts       : 1072695899
TxCollisions        : 0
TxSingleCollision   : 0
TxMultipleCollision : 0
TxDeferredTransmit  : 0
TxLateCollision     : 0
TxExcessiveCollision: 0
TxPausePkts         : 85340088
RxOctets            : 1464164566647
RxUndersizePkts     : 0
RxPausePkts         : 0
Pkts64Octets        : 102603
Pkts65to127Octets   : 296972219
Pkts128to255Octets  : 40562538
Pkts256to511Octets  : 44482295
Pkts512to1023Octets : 94017641
Pkts1024to1522Octets: 901230866
RxOversizePkts      : 0
RxJabbers           : 0
RxAlignmentErrors   : 0
RxFCSErrors         : 0
RxGoodOctets        : 1464164587796
RxDropPkts          : 0
RxUnicastPkts       : 1372925166
RxMulticastPkts     : 3015561
RxBroadcastPkts     : 1427444
RxSAChanges         : 89347939
RxFragments         : 0
RxJumboPkts         : 0
RxSymbolErrors      : 0
RxDiscarded         : 869758

	pvid: 0
	link: port:0 link:up speed:1000baseT full-duplex auto

Have you checked collectd?

1 Like

LuCI statistics, which uses collectd as the monitoring engine.

Monitoring switch on port level might not be built-in, as the ready tools mainly monitor interfaces like eth0.6.

But similar "read sensor by script" approach was recently used for SQM stats plugin, so that should offer you examples.

1 Like