tobiaswaldvogel / openwrt-feed-nettools

OpenWRT packages to collect and display statistics from nftables counters
GNU General Public License v3.0
2 stars 0 forks source link

Packages

Example for adding counters in OpenWRT firewall fw4 for reject WAN traffic:

nft add counter add counter inet fw4 cnt_reject_from_wan_total
nft add counter add counter inet fw4 cnt_reject_from_wan_http
nft insert rule inet fw4 reject_from_wan counter name cnt_reject_from_wan_total
nft insert rule inet fw4 reject_from_wan tcp dport 80 counter name cnt_reject_from_wan_http

nftables rule (anonymous) counters

Local rule counters can be referenced by chain and comment of the rule.
With nftables there can be several counters in a rule but this plugin only considers the first one for now.

Plugin confgiuration

An empty configuration section collects all counters, otherwise only listed counters will be collected. Counters can be grouped into instance for creating individual charts. Without a surrounding Instance tag the instance name is empty. If all counters are collected the chain name is used as plugin instance for rule counters and "Named counters" for named counters. Example:

LoadPlugin nftables
<Plugin nftables>
        <Instance TCP>
                "Counter cnt_reject_from_wan_http" "HTTP"
                "Counter cnt_reject_from_wan_https" "HTTPS"
                "Counter cnt_reject_from_wan_ssh" "SSH"
                "Counter cnt_reject_from_wan_tcp" "Total"
        </Instance>
        <Instance Protocol>
                Counter "cnt_reject_from_wan_udp" "UDP"
                Counter "cnt_reject_from_wan_tcp" "TCP"
                Counter "cnt_reject_from_wan_total" "Total"
        </Instance>
        <Instance WAN>
                Rule "drop_from_wan" "!fw4: drop wan IPv4/IPv6 traffic" "Drop input"
        </Instance>
</Plugin>

This can be placed in /etc/collectd/conf.d/. The luci statistics extension will add it automatically into the generated configuration