By default, node exporter supports collecting netstat info, but not all of it. When you run netstat -s
there are lots of useful information which are not present in the node-exporter's netstat info.
The statistics in netstat -s
come from two sources, /proc/net/netstat
and /proc/net/snmp
. node-exporter also uses these two sources, but does not collect all of its information. It uses a regex to filter and collect some of these stats.
Like me, you may need to collect one of these unexported metrics. In my case, I needed forwarded
or to be more accurate, ForwDatagrams
which indicates the number of forwarded packets. It's useful when you're running a software router and want to keep track of it in prometheus and grafana.
Fortunately, there is a way to change the regex and select which statistics you want to collect without changing the node-exporter source code.
In my case, I just had to add Ip_ForwDatagrams
to the default regex and pass it as the following argument:
./node_exporter --collector.netstat.fields="^(.*_(InErrors|InErrs)|Ip_Forwarding|Ip_ForwDatagrams|Ip(6|Ext)_(InOctets|OutOctets)|Icmp6?_(InMsgs|OutMsgs)|TcpExt_(Listen.*|Syncookies.*|TCPSynRetrans|TCPTimeouts|TCPOFOQueue)|Tcp_(ActiveOpens|InSegs|OutSegs|OutRsts|PassiveOpens|RetransSegs|CurrEstab)|Udp6?_(InDatagrams|OutDatagrams|NoPorts|RcvbufErrors|SndbufErrors))$"
It will show up in prometheus as node_netstat_Ip_ForwDatagrams
. You can find your desired statistic in /proc/net/netstat
or /proc/net/snmp
and add it to the regex.