All of lore.kernel.org
 help / color / mirror / Atom feed
* Route count
@ 2021-02-08 17:10 Grant Taylor
  2021-02-10  8:11 ` Anton Danilov
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Grant Taylor @ 2021-02-08 17:10 UTC (permalink / raw)
  To: lartc

[-- Attachment #1: Type: text/plain, Size: 525 bytes --]

Hi,

Does anyone know a more efficient way to get a count of the number of 
routes than to do something like the following?

    # ip route show table $TABLE | wc -l

I'm doing something where I'd like to instrument the number of 
(unreachable / null) routes once a minute and I'd like to avoid 
unnecessary load on the system.

It seems to me like there should be a counter somewhere that I can just 
read instead of needing to enumerate every single route in the table.



-- 
Grant. . . .
unix || die


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4013 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Route count
  2021-02-08 17:10 Route count Grant Taylor
@ 2021-02-10  8:11 ` Anton Danilov
  2021-02-10 16:46 ` Grant Taylor
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Anton Danilov @ 2021-02-10  8:11 UTC (permalink / raw)
  To: lartc

Hello.
Instead of fetching all content of a route table, you can parse the
/proc/net/fib_triestat file. It contents the number of prefixes for
every routing table.

On Mon, 8 Feb 2021 at 20:13, Grant Taylor <gtaylor@tnetconsulting.net> wrote:
>
> Hi,
>
> Does anyone know a more efficient way to get a count of the number of
> routes than to do something like the following?
>
>     # ip route show table $TABLE | wc -l
>
> I'm doing something where I'd like to instrument the number of
> (unreachable / null) routes once a minute and I'd like to avoid
> unnecessary load on the system.
>
> It seems to me like there should be a counter somewhere that I can just
> read instead of needing to enumerate every single route in the table.
>
>
>
> --
> Grant. . . .
> unix || die
>


-- 
Anton Danilov.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Route count
  2021-02-08 17:10 Route count Grant Taylor
  2021-02-10  8:11 ` Anton Danilov
@ 2021-02-10 16:46 ` Grant Taylor
  2021-02-10 16:53 ` Grant Taylor
  2021-02-10 19:11 ` Jay Vosburgh
  3 siblings, 0 replies; 5+ messages in thread
From: Grant Taylor @ 2021-02-10 16:46 UTC (permalink / raw)
  To: lartc

[-- Attachment #1: Type: text/plain, Size: 470 bytes --]

On 2/10/21 1:11 AM, Anton Danilov wrote:
> Hello.

Hi Anton,

> Instead of fetching all content of a route table, you can parse the 
> /proc/net/fib_triestat file. It contents the number of prefixes for 
> every routing table.

Perfect!

That's exactly what I was wanting.

Now I just need to put together a simple script to parse 
/proc/net/fib_triestat.  I suspect awk, or maybe even sed, will do quite 
nicely.



-- 
Grant. . . .
unix || die


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4013 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Route count
  2021-02-08 17:10 Route count Grant Taylor
  2021-02-10  8:11 ` Anton Danilov
  2021-02-10 16:46 ` Grant Taylor
@ 2021-02-10 16:53 ` Grant Taylor
  2021-02-10 19:11 ` Jay Vosburgh
  3 siblings, 0 replies; 5+ messages in thread
From: Grant Taylor @ 2021-02-10 16:53 UTC (permalink / raw)
  To: lartc

[-- Attachment #1: Type: text/plain, Size: 491 bytes --]

On 2/10/21 9:46 AM, Grant Taylor wrote:
> Now I just need to put together a simple script to parse 
> /proc/net/fib_triestat.  I suspect awk, or maybe even sed, will do quite 
> nicely.

sed -n '/Id 13:/,/^$/p' /proc/net/fib_triestat | sed -n '/Prefixes:/p' | 
sed 's/	Prefixes       //'

That's a tab before Prefixes and seven (7) spaces afterwards.

I'd like to have something more graceful.  But it's a start.

Thank you again Anton.



-- 
Grant. . . .
unix || die


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4013 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Route count
  2021-02-08 17:10 Route count Grant Taylor
                   ` (2 preceding siblings ...)
  2021-02-10 16:53 ` Grant Taylor
@ 2021-02-10 19:11 ` Jay Vosburgh
  3 siblings, 0 replies; 5+ messages in thread
From: Jay Vosburgh @ 2021-02-10 19:11 UTC (permalink / raw)
  To: lartc

Grant Taylor <gtaylor@tnetconsulting.net> wrote:

>On 2/10/21 9:46 AM, Grant Taylor wrote:
>> Now I just need to put together a simple script to parse
>> /proc/net/fib_triestat.  I suspect awk, or maybe even sed, will do quite
>> nicely.
>
>sed -n '/Id 13:/,/^$/p' /proc/net/fib_triestat | sed -n '/Prefixes:/p' |
>sed 's/	Prefixes       //'
>
>That's a tab before Prefixes and seven (7) spaces afterwards.
>
>I'd like to have something more graceful.  But it's a start.

	The other tricky bit is that by default the IPv4 main and local
routing tables are merged, so the prefix, et al, counts in fib_triestate
for main and local will each include all of main plus local.

	The main and local tables are unmerged when an "ip rule" is
added or removed.  You can watch this happen by comparing
/prob/net/fib_trie before and after adding an ip rule.  Once split, the
tables are never merged back togther, even if the original rule set is
restored.

	This also covers only IPv4 routes; IPv6 has no equivalent to
fib_trie and fib_triestats.

	-J

---
	-Jay Vosburgh, jay.vosburgh@canonical.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-10 19:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-08 17:10 Route count Grant Taylor
2021-02-10  8:11 ` Anton Danilov
2021-02-10 16:46 ` Grant Taylor
2021-02-10 16:53 ` Grant Taylor
2021-02-10 19:11 ` Jay Vosburgh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.