chitoku-k / edgerouter-exporter

A Prometheus exporter for EdgeRouter
MIT License
23 stars 3 forks source link

Fails to pull stats because /bin/ip doesn't support --json on ER12 #151

Closed joeshaw closed 2 years ago

joeshaw commented 2 years ago

Running on an EdgeRouter 12 with firmware v2.0.9-hotfix.4, which is the latest available for this device, I get the following in the debug logs:

[2022-08-15T14:45:19Z DEBUG] parsed 3 headers
[2022-08-15T14:45:19Z DEBUG] incoming body is empty
[2022-08-15T14:45:19Z DEBUG] executing /opt/vyatta/sbin/ubnt_vtysh with ["-c", "show ip bgp summary"]
[2022-08-15T14:45:19Z DEBUG] executing /opt/vyatta/sbin/ubnt_vtysh with ["-c", "show bgp ipv6 summary"]
[2022-08-15T14:45:19Z DEBUG] executing /opt/vyatta/bin/sudo-users/vyatta-op-dynamic-dns.pl with ["--show-status"]
[2022-08-15T14:45:19Z DEBUG] failed to connect to strongSwan at /run/charon.vici: No such file or directory (os error 2)
[2022-08-15T14:45:19Z DEBUG] executing /opt/vyatta/bin/vyatta-op-cmd-wrapper with ["show", "load-balance", "watchdog"]
[2022-08-15T14:45:19Z DEBUG] executing /bin/ip with ["--json", "addr", "show"]
[2022-08-15T14:45:19Z DEBUG] executing /opt/vyatta/bin/vyatta-op-cmd-wrapper with ["show", "version"]
[2022-08-15T14:45:19Z ERROR] failed to collect metrics
Error: error parsing interfaces

Caused by:
    EOF while parsing a value at line 1 column 0
[2022-08-15T14:45:19Z DEBUG] flushed 135 bytes
[2022-08-15T14:45:19Z DEBUG] read eof

My version of /bin/ip (and /sbin/ip) don't support --json. When I try to run that command, I get on stderr:

$ /bin/ip --json addr show
Option "-json" is unknown, try "ip -help".

And the help:

$ ip -help
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
       ip [ -force ] -batch filename
where  OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |
                   tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |
                   netns | l2tp | fou | macsec | tcp_metrics | token | netconf | ila }
       OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
                    -h[uman-readable] | -iec |
                    -f[amily] { inet | inet6 | ipx | dnet | mpls | bridge | link } |
                    -4 | -6 | -I | -D | -B | -0 |
                    -l[oops] { maximum-addr-flush-attempts } | -br[ief] |
                    -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
                    -rc[vbuf] [size] | -n[etns] name | -a[ll] | -c[olor]}

So perhaps this version of EdgeOS has a different/older version of /bin/ip than the model you have?

joeshaw commented 2 years ago

Version info, such as it is:

$ ip -V
ip utility, iproute2-ss161212
chitoku-k commented 2 years ago

Thank you for report and sorry for the late reply! I checked the both firmware and found that different versions of iproute2 are bundled in v2.0.9-hotfix.4 as you mentioned.

JSON support on iproute2 seems to have been available after August 17, 2017: https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=d0e720111aad2527fa350723779144c56c8a5607

I will try to add a parser that handles the following output instead so wait until then!

$ ip --oneline addr show
joeshaw commented 2 years ago

v2.6.0 works great. Thanks a lot for the quick turnaround, and I learned about a new rust crate! (nom)

chitoku-k commented 2 years ago

Glad to hear that 😄