I’m sorry, I’m not able to reproduce your issue. I am using Telegraf 1.5.2 on Ubuntu 16.04.3. Here are the steps I followed:
First, I got the interface name using the command you are using:
$ route -n | awk '$1 ~ /0.0.0.0/ {print $NF}'
enp0s3
Then I added an environment variable to my configuration. Here are the relevant lines from my config:
$ cat /etc/telegraf/telegraf.conf | grep -B 5 \$INTERFACE
[[inputs.net]]
# ## By default, telegraf gathers stats from any up interface (excluding loopback)
# ## Setting interfaces will tell it to gather these explicit interfaces,
# ## regardless of status.
# ##
interfaces = ["$INTERFACE"]
I added the variable to /etc/default/telegraf
. Here are the contents of the file and its permissions:
$ cat /etc/default/telegraf
INTERFACE=enp0s3
$ ls -l /etc/default/telegraf
-rw-r--r-- 1 telegraf telegraf 17 Apr 5 10:15 /etc/default/telegraf
I am writing metrics to /tmp/metrics.out
using the File output plugin. When I run Telegraf I see metrics for that specific interface:
$ cat /tmp/metrics.out | grep enp0s3
net,interface=enp0s3,host=scratchbox bytes_recv=175127i,packets_sent=1746i,err_in=0i,err_out=0i,drop_in=0i,drop_out=0i,bytes_sent=703715i,packets_recv=2159i 1522942350000000000
If you want to test using the --test
argument, you’ll need to create and export an environment variable as follows:
$ INTERFACE=enp0s3
$ export INTERFACE
$ telegraf --input-filter net --test
2018/04/05 11:37:39 I! Using config file: /etc/telegraf/telegraf.conf
* Plugin: inputs.net, Collection 1
> net,host=scratchbox,interface=enp0s3 drop_in=0i,drop_out=0i,bytes_sent=775291i,packets_sent=2097i,err_in=0i,err_out=0i,bytes_recv=205727i,packets_recv=2556i 1522942660000000000
> net,interface=all,host=scratchbox icmp_outparmprobs=0i,icmp_inechos=0i,ip_fragoks=0i,ip_forwdatagrams=0i,ip_reasmoks=0i,ip_fragcreates=0i,icmp_inparmprobs=0i,icmp_outerrors= [...]
Is there any more information you can provide?