Skip to main content

Overview

Periodically gathers stats about iptables rules and sends them to different sinks (while currently only MQTT is supported). It is possible to count rules in chains, count number of packets/bytes processed by a rule and to count unique IPs in a ipset.

Usage

Start iptables_stat and it will run constantly, generate readings periodically and publish them to configured sinks.

Configuration

The program is configured using a configuration file in YAML format. Default location is /etc/iptable_stats.yml but a different location can be configured using the command line parameter --config.

The config file consists of the section general and a variable number of configuration sections for input modules and output sinks.

Example:

general:
  interval: 120

mqtt:
  host: myHost
  topic_root: home/myHost/iptables_stats

iptables_pkg_count:
  firehol_level1:
    chain: FIREHOL_BLACKLIST
    rule_regex: .*match-set.firehol_level3.src.*

  firehol_level2:
    chain: FIREHOL_BLACKLIST
    rule_regex: .*match-set.firehol_level2.src.*

  firehol_level3:
    chain: FIREHOL_BLACKLIST
    rule_regex: .*match-set.firehol_level3.src.*

ipset_count:
  firehol_level1:
    setname: firehol_level1

  firehol_level2:
    setname: firehol_level2

  firehol_level3:
    setname: firehol_level3

iptables_rule_count:
  f2b-traefik-auth:
    chain: f2b-traefik-auth
    offset: -1

  f2b-traefik-botsearch:
    chain: f2b-traefik-botsearch
    offset: -1

This configuration contains three iptables_pkg_count objects that will report iptables counters for the rules matching the given regular expressions. Also three ipset_count objects that count the number of unique IPs in the ipsets firehol_level1, firehol_level2 and firehol_level3. Last but not least two iptables_rule_count objects that count the rules in the chains f2b-traefik-auth and f2b-traefik-botsearch. fail2ban injects rules into these chains in case of a IP ban. Each rule represents a single IP. Both objects use an offset of -1 cause both chains contain a fixed DROP rule that should not be counted.

Output Sinks

Currntly only one sink is implemented

MQTT

Example:

mqtt:
  host: myHost
  port: 1883
  topic_root: home/myhost/iptables_stats
  • host
  • port (optional) - defaults to 1883
  • topic_root - string that defines the root topic that is used for publishing readings

Reading Modules

Every module has a section in the configuration. In each of these sections object configurations can be defined using a user-defined object name. Every object configuration can override the gobal interval parameter so it is possible to configure interval for objects individually.

iptable_pkt_count

Reads counter statistics for a given rule and chain from iptables and generates the readings packet_count and byte_count. Those represent the number of blocked packets and bytes.

Configuration:

  • chain - Name of the chain
  • rule_regex - Regex that matches the rule in question. It is matched against a string as the rule appears in the output of iptables-save. The regex is not allowed to match more than one rule.

iptables_rule_count

Counts the number of rules in a given chain and generates the reading rule_count.

Configuration:

  • chain - Name of the chain
  • offset (optional) - An integer that is added to the value before publishing. This is useful to account for rules that should be ignored. E.g. there might be a drop rule which should not account towards the value. Set offset to -1 to adjust to that.

Metadata

Release files for iptables-stats 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iptables-stats 1.0.1
File Size Uploaded
iptables_stats-1.0.1.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iptables-stats 1.0.1
File Interpreter ABI Platform
iptables_stats-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.3 kB

Release files / iptables_stats-1.0.1.tar.gz

Download URL iptables_stats-1.0.1.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ba0fe6d07850f365b1f8529025f83294608f2307d83cb103d5014627d984f178
BLAKE2b-256 checksum
How to use checksums
49b5630d3c7defb40a3731fdc3950f5e4c1be0410989e928cd31d4c2c579a147
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / iptables_stats-1.0.1-py3-none-any.whl

Download URL iptables_stats-1.0.1-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f51edf14b5f592ea1cd725a3956395cd440f13e5c1b03a66762f73b7826ff717
BLAKE2b-256 checksum
How to use checksums
539a90a3f2edea534dd4cd8cf3b75a3a8e3f224e2c66f3ba4e0d2afdd9cd72c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.9.11

1 release file

0.9.10

1 release file

0.9.9

1 release file

0.9.6

1 release file

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

1 release file

0.9.1

3 release files

0.9.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page