mackerel-agent icon indicating copy to clipboard operation
mackerel-agent copied to clipboard

`host.meta.interfaces` is null when use `ifconfig`

Open xruins opened this issue 3 years ago • 1 comments

Overview

The metric host.meta.interfaces are always null on the particular host.

This problem seems to occur on the hosts satisfy the following conditions.

  • not installed ip command
  • installed ifconfig command
  • a newer version of Linux (maybe)

Output of mackerel-agent

The following log shows mackerel-agent outputs the metrics without proper .host.meta.interfaces. It is expected .host.meta.interfaces have valid information of the NICs of host, but it always be null.

ruins@vm-ubnt1804-Frigg:~$ cat /etc/issue
Ubuntu 18.04.3 LTS \n \l
ruins@vm-ubnt1804-Frigg:~$ uname -r
5.0.0-25-generic
ruins@vm-ubnt1804-Frigg:~$ docker run --rm -it mackerel/mackerel-agent mackerel-agent once -apikey=dummy | jq .host.meta.interfaces
null

Consideration

It seems caused by mismatched Regexp on here (https://github.com/mackerelio/mackerel-agent/blob/master/spec/linux/interface.go#L97-L100).

This Regexp expects the section of IP addresses begins with inet addr but it seems to begin with inet in the newer version of Linux.

On Debian Jessie, the section of IP address begins with inet addr. But on Debian Stretch, it begins with inet.

ruins@thor:~$ docker run --rm -it debian:jessie-slim sh -c "apt update;apt install net-tools;ifconfig -a"
(omit apt logs)
eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:02
          inet addr:172.17.0.2  Bcast:172.17.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:817 errors:0 dropped:0 overruns:0 frame:0
          TX packets:364 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:10517296 (10.0 MiB)  TX bytes:25479 (24.8 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ruins@thor:~$ docker run --rm -it debian:stretch-slim sh -c "apt update;apt install net-tools;ifconfig -a"
(omit apt logs)
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)
        RX packets 508  bytes 8413071 (8.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 256  bytes 18348 (17.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

xruins avatar Jun 19 '22 17:06 xruins

Thank you for your report! We will check this issue.

inommm avatar Jun 23 '22 04:06 inommm

We plan to implement this using netlink. It will be independent of the command execution result.

yseto avatar Aug 29 '22 06:08 yseto

A corrected version will be in the next release.

yseto avatar Sep 01 '22 02:09 yseto