Sample Header Ad - 728x90

Getting an interfaces `valid_lft` programmatically

1 vote
0 answers
196 views
iproute2 can give back an interface's valid_lft which corresponds to the dhcp lease time left. See a truncated example output hereafter:
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
  ...
2: enp0s1:  mtu 1500 qdisc fq_codel state UP group default qlen 1000
   ...
       valid_lft 82933sec preferred_lft 82933sec
   ...
I'd like to get this from preferably Golang without actually calling ip address. Though I realise ip route has a json output, I still much prefer to interact with, for example: - a library which allows me access to this counter - a path in /sys or /proc which provides access to this counter - something else? The goal is to expose the valid_lft counter as a metric which can be scraped by something like Prometheus. I'm amazed this is not available yet.
Asked by hbogert (759 rep)
Aug 17, 2023, 06:52 PM