luci-mod-admin-full: use `nf_conntrack_count` for counting connections (#1114)
authorJo-Philipp Wich <jo@mein.io>
Thu, 20 Apr 2017 14:55:29 +0000 (16:55 +0200)
committerJo-Philipp Wich <jo@mein.io>
Thu, 20 Apr 2017 14:57:58 +0000 (16:57 +0200)
As suggested by PR #1114, use `/proc/sys/net/netfilter/nf_conntrack_count`
instead of counting the lines in `/proc/net/nf_conntrack` but use a slightly
more efficient approach which avoids spawning an extra `cat` command.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm

index 206f9ef82af90f6508f7cfc705efd4734e3d92cb..d29a89427687738fca1b2493134ac8c01ecc8f9f 100644 (file)
                local wan = ntm:get_wannet()
                local wan6 = ntm:get_wan6net()
 
-               local conn_count = tonumber((
-                       luci.sys.exec("wc -l /proc/net/nf_conntrack") or
-                       luci.sys.exec("wc -l /proc/net/ip_conntrack") or
-                       ""):match("%d+")) or 0
+               local conn_count = tonumber(
+                       fs.readfile("/proc/sys/net/netfilter/nf_conntrack_count")) or 0
 
                local conn_max = tonumber((
                        luci.sys.exec("sysctl net.nf_conntrack_max") or