I'm testing my network infrastructure where I'm using iPerf and UDP protocol.

I'm running Cacti an open-source, web-based network monitoring and graphing. SNMP server is enabled in Linux servers.

First of all, so far, Cacti is able to monitor all template's graphs which are already there (e.g., Memory, CPU, Average Load, Interface Statistics) But I could not find the graph for Packet loss graph for the Interface. It should be like in Cisco Router In/Out Errors/Discarded Packets but maybe with different notation. Does anybody have an idea?

Secondly, I would like also to plot/graph what netstat shows. For instance netstat -su shows:

            1354844 packets received
            0 packets to unknown port received.
            5854 packet receive errors
            1360713 packets sent
            RcvbufErrors: 5854

I want to graph the sent, received packets and the packet receive errors. Is that possible with SNMP NETSTAT. In another words, I'd like to plot UDP packet loss.

Is there any python, Perl or bash script that can be used to collect data of SNMP NETSTAT for UDP packets? Would be much better if it is SNMP queries.

I tried snmpnetstat -v2c -c public -Cs -Cp udp where it shows only


Then, I tried snmpnetstat -v2c -c public -Cs but it does not show any values.


          - output errors
         icmp6 histogram:
              input     output type

2nd Edit

I have written the bash script and it returns exactly the output I want when I run for example ./udp_netstat.sh


rs="$(snmpnetstat -v2c -c public -Cs -Cp udp "$@")"
    # You have to quote "$rs" so newlines don't break
    ReceivedDatagrams="$(echo "$rs" | cut -d$'\n' -f2 | tr -s ' '| cut -d' ' -f2)"
    InvalidPort="$(echo "$rs" | cut -d$'\n' -f3 | tr -s ' '| cut -d' ' -f2)"
    DroppedDatagrams="$(echo "$rs" | cut -d$'\n' -f4 | tr -s ' '| cut -d' ' -f2)"
    DatagramRequests="$(echo "$rs" | cut -d$'\n' -f5 | tr -s ' '| cut -d' ' -f2)"

    echo "Received Datagrams:$ReceivedDatagrams Invalid port:$InvalidPort Dropped datagrams:$DroppedDatagrams Datagram requests:$DatagramRequests"

the value "$@" is for the hostname device for cacti

The output of bash script is:

Received Datagrams:258 Invalid port:63 Dropped datagrams:0 Datagram requests:471520

Starting with data input method, I gave the following path /usr/share/cacti/site/scripts/udp_netstat <hostname> then I added the input fields as well as the output, according to the bash file output.

For the Data Source, I added data source items also according to the bash file output and made Data source type as COUNTER. Then, I proceed to Graph Template where I added the line of each output I have.

It seems to be in the workflow of adding new script, however, nothing so far is shown in the graph.

I assume there is a mistake with the Input String.

1 Answer 1


One option could be to use the snmpnetstat command that comes with the snmp package.

It allows to query statistics per protocols using -Cs and -Cp parameters :

snmpnetstat [COMMON OPTIONS] [-Ca] [-Cn] [-Cs] [-Cp protocol] AGENT

-Cs Show per-protocol statistics.

-Cp protocol Show statistics about protocol


E.g :

$ snmpnetstat -v2c -c public -Cs -Cp udp
          1052 total datagrams received
          1167 datagrams to invalid port
             0 datagrams dropped due to errors
          1152 output datagram requests

From there you can parse the output and/or format it according to Cacti requirements.

Edit :

In case it returns no values like so :

             - datagrams input
             - octets received
             - hdr errors input
             - no routes input

This is besause you have to allow queries on these statistics (OIDs) in your snmp agent config file.

E.g in /etc/snmp/snmpd.conf add either :

  • For UDP only :

     view   systemonly  included   .
  • For All :

     view   systemonly  included   .

Ref : https://oidref.com/

Then restart your snmp agent to apply changes.

  • thanks! One issue please, how do I parse the output to cacti? Any tutorial useful you may have?
    – Tim Luka
    Jul 1, 2019 at 20:28
  • The script should output this format <fieldname_1>:<value_1> <fieldname_2>:<value_2> ... <fieldname_n>:<value_n>. cacti.net/downloads/docs/html/…
    – krisFR
    Jul 1, 2019 at 20:49
  • I edited my question after issue which I've got after running snmpnetstat
    – Tim Luka
    Jul 2, 2019 at 10:32
  • @Tim Luka I've edited my answer for this issue
    – krisFR
    Jul 2, 2019 at 18:58
  • Thanks, I have edited my question, just couple of issues I faced while adding the data source.
    – Tim Luka
    Jul 3, 2019 at 15:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .