10
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

保存版: ContainerLabでBGP環境にIPFIX導入。pmacctでSQLite保存まで1行ずつ徹底解説

Posted at

はじめに

GMOコネクトの永田です。

前回の記事では、BGPルータ環境にsFlowテレメトリ収集を導入しました。今回は、もう1つの主要なフロー収集プロトコルである**IPFIX(IP Flow Information Export)**を、pmacctを使って実装していきます。

前回との大きな違いは、フローデータをSQLiteデータベースに保存する点です。これにより、時系列でのフロー分析やSQL クエリによる柔軟なデータ抽出が可能になります。

本記事では、pmacctの設定についてconfigファイルの1行1行を詳細に解説します。pmacctは強力なツールですが、日本語の詳しい情報が少ないため、本記事が実践的な参考になれば幸いです。

まとめ

  • IPFIX + pmacctでBGPルータ環境にフローテレメトリ収集を実装
  • **pmacctd(nfprobeプラグイン)**でIPFIX Exporterとして動作
  • **nfacctd(sqlite3プラグイン)**でCollectorとしてSQLite3にデータ保存
  • SQLiteデータベースで時系列フロー分析とSQLクエリによる柔軟な集計が可能
  • macOS (ARM64) + Devcontainer環境でも動作確認完了

前回からの主な変更点

  • テレメトリプロトコル: sFlow → IPFIX v10
  • Export/Collect ツール: host-sflow + nfdump → pmacct
  • データ保存形式: ファイルベース(nfcapd) → SQLite3データベース
  • Router イメージ: FRR + host-sflow → FRR + pmacct(nfprobeプラグイン)
  • Collector イメージ: nfdump-sflow → pmacct-collector(nfacctd + sqlite3プラグイン)

前提知識

IPFIXとは

IPFIX(RFC 7011, 7012, 7013)は、Cisco NetFlowをベースに標準化されたネットワークフローの収集プロトコルです。

この辺りの解説が参考になります。

pmacctとは

pmacct(Promiscuous mode IP Accounting package)は、ネットワークトラフィックの収集・集約・保存を行うオープンソースツールです。

pmacctの主な機能

  • pmacctd: パケットキャプチャベースのアカウンティングデーモン(Exporterとして動作)
  • nfacctd: NetFlow/IPFIX/sFlow受信デーモン(Collectorとして動作)
  • 多様な出力プラグイン: print(JSON/CSV)、SQLite3、MySQL、PostgreSQL、Kafka、RabbitMQ など

今回の構成では:

  • Router(r1, r2): pmacctd + nfprobeプラグイン(IPFIX Exporter)
  • Collector: nfacctd + sqlite3プラグイン(IPFIX Collector)

試したtopology

今回試したtopologyは以下です。port番号がIPFIX用に変更となっているだけで、前回と同じです。

                     ┌─────────────┐
                     │  collector  │ 172.100.101.100
                     │(nfacctd)    │ :4739 IPFIX Collector
                     └──────┬──────┘
                            │ mgmt network
         ┌──────────────────┼──────────────────┐
         │                  │                  │
    ┌────┴────┐        ┌────┴────┐       ┌────┴────┐
    │   src   │        │   r1    │       │   r2    │
    │.1.11    │────────│(pmacctd)│───────│(pmacctd)│
    └─────────┘ eth1   │ :179 BGP│  eth2 └────┬────┘
   192.168.1.0/24      └─────────┘             │
                       172.100.101.2            │
                       IPFIX Exporter     172.100.101.3
                                          IPFIX Exporter
                                                │
                                           ┌────┴────┐
                                           │   dst   │
                                           │.2.11    │
                                           └─────────┘
                                          192.168.2.0/24

環境

  • MacBook Pro Apple M4 Max 36GBメモリ
  • VSCode + Devcontainer
  • containerlab 0.71.0

topology設定

clab yml

前回(sFlow版)からの主な変更点:

name: clab-bgp-ipfix-pmacct-topo  # topo名変更
mgmt:
  network: custom_mgmt
  ipv4-subnet: 172.100.101.0/24
topology:
  nodes:
    r1:
      kind: linux
      image: local/frr_pmacct:latest  # pmacct版イメージ
      mgmt-ipv4: 172.100.101.2
      binds:
        - r1/daemons:/etc/frr/daemons
        - r1/frr.conf:/etc/frr/frr.conf
        - r1/vtysh.conf:/etc/frr/vtysh.conf
        - r1/pmacctd.conf:/etc/pmacct/pmacctd.conf  # pmacct設定
    r2:
      kind: linux
      image: local/frr_pmacct:latest
      mgmt-ipv4: 172.100.101.3
      binds:
        - r2/daemons:/etc/frr/daemons
        - r2/frr.conf:/etc/frr/frr.conf
        - r2/vtysh.conf:/etc/frr/vtysh.conf
        - r2/pmacctd.conf:/etc/pmacct/pmacctd.conf
    src:
      kind: linux
      image: praqma/network-multitool:latest
      mgmt-ipv4: 172.100.101.11
      exec:
        - "ip link set eth1 up"
        - "ip addr add 192.168.1.11/24 dev eth1"
        - "ip route add 192.168.0.0/16 via 192.168.1.1 dev eth1"
    dst:
      kind: linux
      mgmt-ipv4: 172.100.101.12
      image: praqma/network-multitool:latest
      exec:
        - "ip link set eth1 up"
        - "ip addr add 192.168.2.11/24 dev eth1"
        - "ip route add 192.168.0.0/16 via 192.168.2.1 dev eth1"
    collector:
      kind: linux
      image: local/pmacct-collector:latest  # pmacct collector
      mgmt-ipv4: 172.100.101.100
  links:
    - endpoints: [r1:eth2, r2:eth2]  # BGP peering
    - endpoints: [src:eth1, r1:eth1]  # host connectivity
    - endpoints: [dst:eth1, r2:eth1]

FRRouting Config

前回と同じなので省略します(daemons, frr.conf, vtysh.conf)。

pmacct設定の詳細解説

ここからが本記事のメインパートです。pmacctの設定ファイルを1行ずつ詳しく解説していきます。

Router側:pmacctd.conf(IPFIX Exporter設定)

r1/pmacctd.conf

! pmacctd configuration for router1
! This configuration enables IPFIX export

daemonize: true
pidfile: /var/run/pmacctd.pid

! Interface to capture packets (monitor edge-facing interface)
pcap_interface: eth1
pcap_promisc: true

! Aggregate primitives
aggregate: src_host, dst_host, src_port, dst_port, proto

! IPFIX export settings
plugins: nfprobe

! nfprobe plugin configuration
nfprobe_receiver: 172.100.101.100:4739
nfprobe_version: 10

! Refresh rates (in seconds) to speed up flow export during testing
nfprobe_timeouts: tcp=10:udp=10:icmp=10:general=10:maxlife=60

! Sampling
sampling_rate: 1

! Enable debug logging for troubleshooting
debug: core,nfprobe

! Log pmacctd events for investigation
logfile: /var/log/pmacct/pmacctd.log
logfile_mask: all

設定項目の詳細解説

基本設定
daemonize: true
  • 意味: pmacctdをバックグラウンドプロセス(デーモン)として起動
  • : true または false
  • 推奨: コンテナ環境ではtrue、systemd管理ならfalseでもOK
pidfile: /var/run/pmacctd.pid
  • 意味: プロセスIDを記録するファイルのパス
  • 用途: プロセス管理(再起動・停止時に使用)
  • デフォルト: /var/run/pmacctd.pid
パケットキャプチャ設定
pcap_interface: eth1
  • 意味: トラフィックをキャプチャする対象インターフェース
  • 重要: ルータのエッジ側インターフェースを指定(ホストとの接続側)
  • r1の場合: eth1(src接続)、r2の場合: eth1(dst接続)
  • BGPピア側(eth2)をキャプチャすると重複カウントになる可能性あり
pcap_promisc: true
  • 意味: プロミスキャスモードを有効化
  • 効果: インターフェースを通過する全パケット(宛先MACが自分以外のものも)をキャプチャ
  • デフォルト: true
  • 推奨: ルータとして転送するトラフィックもキャプチャするためtrueを使用
フロー集約設定
aggregate: src_host, dst_host, src_port, dst_port, proto
  • 意味: フローを集約するキー(5-tuple)
  • 利用可能な値:
    • src_host, dst_host: 送信元/宛先IPアドレス
    • src_port, dst_port: 送信元/宛先ポート番号
    • proto: プロトコル(TCP/UDP/ICMP等)
    • その他: src_mac, dst_mac, vlan, tos, src_as, dst_as など多数
  • ポイント: ここで指定した要素の組み合わせごとに1フローとして集約される
プラグイン設定
plugins: nfprobe
  • 意味: 使用するプラグインの指定
  • nfprobe: NetFlow/IPFIX形式でフローをエクスポートするプラグイン
  • その他の主なプラグイン: print, sqlite3, mysql, kafka など
  • 複数指定可能: plugins: nfprobe, print のようにカンマ区切り
IPFIX Export設定
nfprobe_receiver: 172.100.101.100:4739
  • 意味: IPFIX/NetFlowの送信先(Collector)
  • 形式: IPアドレス:ポート番号
  • ポート番号:
    • 4739: IPFIX標準ポート(今回使用)
    • 2055: NetFlow v9標準ポート
  • 複数Collector指定可能: nfprobe_receiver: 192.168.1.1:4739,192.168.2.1:4739
nfprobe_version: 10
  • 意味: エクスポートするフォーマットのバージョン
  • :
    • 10: IPFIX(RFC 7011)
    • 9: NetFlow v9
    • 5: NetFlow v5(レガシー)
  • 推奨: 10(IPFIX)を使用
タイムアウト設定
nfprobe_timeouts: tcp=10:udp=10:icmp=10:general=10:maxlife=60
  • 意味: フローをエクスポートするタイムアウト時間(秒)
  • パラメータ:
    • tcp: TCPフローの非アクティブタイムアウト
    • udp: UDPフローの非アクティブタイムアウト
    • icmp: ICMPフローの非アクティブタイムアウト
    • general: その他プロトコルのタイムアウト
    • maxlife: フローの最大生存時間(長時間の通信も強制的にエクスポート)
  • 本番推奨値: tcp=300:udp=120:icmp=60:general=60:maxlife=1800
  • 検証用: 今回は10秒と短く設定して動作確認を容易に
サンプリング設定
sampling_rate: 1
  • 意味: パケットサンプリングレート
  • : 1 = 全パケット、100 = 100パケットに1つ
  • デフォルト: none(サンプリングなし)
  • 本番環境: 高トラフィック環境では1001000程度
  • 検証環境: 1(全パケット)で正確な動作確認
デバッグ・ログ設定
debug: core,nfprobe
  • 意味: デバッグログのカテゴリ指定
  • カテゴリ:
    • core: コア機能のログ
    • nfprobe: nfprobeプラグインのログ
    • その他: pcap, bgp, bmp など
  • 本番環境: 無効化またはエラーのみ
logfile: /var/log/pmacct/pmacctd.log
  • 意味: ログファイルの出力先
  • デフォルト: syslog
  • 推奨: 独立したログファイルで管理
logfile_mask: all
  • 意味: ログに出力するイベントの種類
  • :
    • all: すべてのログ
    • info, warning, error: レベル別指定
  • 本番環境: warning,error 程度に絞る

Collector側:nfacctd.conf(IPFIX Collector設定)

docker/pmacct_collector/nfacctd.conf

! nfacctd configuration for IPFIX collection
! Uses pmacct sqlite3 plugin to store flow data in SQLite database

daemonize: false
pidfile: /var/run/nfacctd.pid

! Listen for IPFIX from the routers
nfacctd_ip: 0.0.0.0
nfacctd_port: 4739
nfacctd_disable_checks: true

! Aggregate standard 5-tuple primitives
aggregate: src_host, dst_host, src_port, dst_port, proto

! SQLite3 plugin configuration
plugins: sqlite3
sql_db: /var/log/pmacct/flows.db
sql_table: acct
sql_table_version: 1
sql_refresh_time: 60
sql_history: 60
sql_history_roundoff: m
sql_optimize_clauses: true

設定項目の詳細解説

基本設定
daemonize: false
  • 意味: フォアグラウンドで実行(コンテナのメインプロセスとして)
  • コンテナ環境: false必須(コンテナが終了してしまうため)
  • 通常のサーバー: trueでバックグラウンド実行
pidfile: /var/run/nfacctd.pid
  • Exporter側と同様(プロセス管理用)
IPFIX受信設定
nfacctd_ip: 0.0.0.0
  • 意味: IPFIXを受信するバインドIPアドレス
  • 0.0.0.0: すべてのインターフェースで待ち受け
  • 特定IP: セキュリティ上、特定IPに限定も可能
nfacctd_port: 4739
  • 意味: IPFIXを受信するポート番号
  • 4739: IPFIX標準ポート(IANA登録)
  • カスタム: 別ポート使用も可能だがExporter側と合わせる
nfacctd_disable_checks: true
  • 意味: NetFlow/IPFIXパケットの厳密なチェックを無効化
  • : true または false
  • デフォルト: true
  • true: 若干非標準なExporterも受け入れる(開発・検証向け)
  • false: RFC厳密準拠(本番環境で厳密なチェックが必要な場合)
集約設定
aggregate: src_host, dst_host, src_port, dst_port, proto
  • Exporter側と同じ5-tupleで集約
  • 重要: Exporter側とCollector側のaggregate設定を一致させること
SQLite3プラグイン設定
plugins: sqlite3
  • 意味: データベースへの保存にsqlite3プラグインを使用
  • その他の選択肢: print(JSON/CSV出力)、mysql, pgsql, kafka など
sql_db: /var/log/pmacct/flows.db
  • 意味: SQLiteデータベースファイルのパス
  • 推奨: 永続化ボリュームにマウントすること
sql_table: acct
  • 意味: データを挿入するテーブル名
  • デフォルト: acct(pmacctの標準テーブル名)
  • 今回: デフォルトのacctを使用(自動作成スクリプトと連携)
sql_table_version: 1
  • 意味: pmacctのテーブルスキーマバージョン
  • バージョン:
    • 1: 基本的な5-tuple + packets/bytes + timestamp
    • 29: より多くのフィールド(VLAN, AS, MAC, etc.)
  • 今回: シンプルな1を使用
  • スキーマファイル: /usr/share/pmacct/sql/pmacct-create-table_v1.sqlite3
sql_refresh_time: 60
  • 意味: データベースへの書き込み間隔(秒)
  • デフォルト: 60
  • 60: 1分ごとに集約データをフラッシュ
  • トレードオフ:
    • 短い: リアルタイム性向上、I/O負荷増
    • 長い: I/O負荷軽減、メモリ使用増
sql_history: 60
  • 意味: 時系列バケットのサイズ(秒)
  • 60: 1分単位でタイムスタンプを丸める
  • 用途: 時系列分析時に同じタイムスタンプにフローをまとめる
sql_history_roundoff: m
  • 意味: タイムスタンプの丸め単位
  • : s(秒), m(分), h(時), d(日)
  • m: 分単位で切り捨て(例: 12:34:56 → 12:34:00)
sql_optimize_clauses: true
  • 意味: SQL INSERT文の最適化
  • デフォルト: false
  • true: 複数行を1つのINSERT文にまとめる(パフォーマンス向上)
  • false: 行ごとに個別INSERT

Dockerイメージの詳細

Router用:local/frr_pmacct:latest

docker/frr_pmacct/Dockerfile

# Use official FRRouting image as base
FROM quay.io/frrouting/frr:10.4.1

# Install pmacct for IPFIX export
RUN apk add --no-cache pmacct tcpdump procps iproute2

# Prepare pmacct directories
RUN mkdir -p /etc/pmacct /var/log/pmacct

# Add startup script
COPY start.sh /
RUN chmod +x /start.sh

ENTRYPOINT ["/sbin/tini", "--", "/start.sh"]

ポイント:

  • Alpine Linuxベースのためapkでpmacctをインストール
  • tcpdump, procps, iproute2: デバッグ用ツール
  • pmacctのログディレクトリを事前作成

docker/frr_pmacct/start.sh

#!/bin/sh

# Ensure FRR has correct permissions
chown -R frr:frr /etc/frr

# Start pmacctd in background
/usr/sbin/pmacctd -f /etc/pmacct/pmacctd.conf

# Start FRRouting (this becomes the main process)
exec /usr/lib/frr/docker-start

起動順序:

  1. FRR設定ファイルのパーミッション設定
  2. pmacctdをバックグラウンド起動(-fで設定ファイル指定)
  3. FRRoutingを起動(execでメインプロセスとして)

Collector用:local/pmacct-collector:latest

docker/pmacct_collector/Dockerfile

FROM debian:12-slim

# Install pmacct suite and debugging utilities for IPFIX collection
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        pmacct \
        sqlite3 \
        tcpdump \
        procps \
        iproute2 \
        net-tools \
        psmisc \
    && rm -rf /var/lib/apt/lists/*

# Prepare configuration and log directories
RUN mkdir -p /etc/pmacct /var/log/pmacct

# Add nfacctd configuration
COPY nfacctd.conf /etc/pmacct/nfacctd.conf

# Add startup script to initialize database
COPY start.sh /start.sh
RUN chmod +x /start.sh

# Run startup script which creates table and starts nfacctd
CMD ["/start.sh"]

ポイント:

  • Debian 12ベースでpmacctとsqlite3 CLIツールをインストール
  • start.shスクリプトをコピーして実行可能に設定
  • 起動時にstart.shを実行(SQLiteテーブルの自動作成とnfacctd起動)

SQLiteテーブルの自動作成

pmacctはデフォルトではテーブルを自動作成しません。このため、start.shスクリプトを使ってコンテナ起動時に自動でテーブルを作成しています。

start.shの仕組み

#!/bin/bash

# Initialize SQLite database table using pmacct's standard schema
DB_PATH="/var/log/pmacct/flows.db"

# Create table (pmacct schema includes "DROP TABLE IF EXISTS acct")
sqlite3 "$DB_PATH" < /usr/share/pmacct/sql/pmacct-create-table_v1.sqlite3

# Start nfacctd in the foreground
exec /usr/sbin/nfacctd -f /etc/pmacct/nfacctd.conf

処理フロー:

  1. pmacctの標準スキーマファイル(/usr/share/pmacct/sql/pmacct-create-table_v1.sqlite3)からテーブルを作成
  2. スキーマにはDROP TABLE IF EXISTS acct;が含まれるため、冪等性あり(何度実行しても安全)
  3. pmacctのデフォルトテーブル名"acct"を使用(シンプル)
  4. execでnfacctdを起動(PID 1として実行し、シグナルを正しく受信)

テーブルスキーマ(v1)参考情報

pmacctが提供する標準スキーマ(sql_table_version: 1)は以下の通りです:

DROP TABLE IF EXISTS acct;
CREATE TABLE acct (
    mac_src CHAR(17) NOT NULL DEFAULT '0:0:0:0:0:0',
    mac_dst CHAR(17) NOT NULL DEFAULT '0:0:0:0:0:0',
    ip_src CHAR(45) NOT NULL DEFAULT '0.0.0.0',
    ip_dst CHAR(45) NOT NULL DEFAULT '0.0.0.0',
    src_port INT(4) NOT NULL DEFAULT 0,
    dst_port INT(4) NOT NULL DEFAULT 0,
    ip_proto CHAR(6) NOT NULL DEFAULT 0, 
    packets INT NOT NULL,
    bytes BIGINT NOT NULL,
    stamp_inserted DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
    stamp_updated DATETIME,
    PRIMARY KEY (mac_src, mac_dst, ip_src, ip_dst, src_port, dst_port, ip_proto, stamp_inserted)
);

ポイント:

  • DROP TABLE IF EXISTS acct;により冪等性を保証(何度実行しても安全)
  • 5-tuple(送信元/宛先IP、ポート、プロトコル)+ パケット数/バイト数 + タイムスタンプを記録

このスキーマはpmacctが公式提供するv1フォーマットで、5-tuple(送信元/宛先IP、ポート、プロトコル)とパケット数/バイト数、タイムスタンプを記録します。

動かしてみた

1. Dockerイメージのビルド

cd example/clab-bgp-ipfix-pmacct-topo

# Router用イメージ(FRR + pmacct)
docker build -t local/frr_pmacct:latest docker/frr_pmacct/

# Collector用イメージ(pmacct + SQLite3)
docker build -t local/pmacct-collector:latest docker/pmacct_collector/

2. containerlabでトポロジーを起動

sudo containerlab deploy -t bgp-ipfix-pmacct-topo.clab.yml

出力例:

INFO[0000] Creating lab directory: /path/to/clab-clab-bgp-ipfix-pmacct-topo
INFO[0000] Creating container: "r1"
INFO[0000] Creating container: "r2"
INFO[0000] Creating container: "src"
INFO[0000] Creating container: "dst"
INFO[0000] Creating container: "collector"
...
+-----------------------------------------------+----------------+---------+-----------------+
|                     Name                      |  Kind/Image    |  State  |  IPv4/6 Address |
+-----------------------------------------------+----------------+---------+-----------------+
| clab-clab-bgp-ipfix-pmacct-topo-collector     | linux          | running | 172.100.101.100 |
| clab-clab-bgp-ipfix-pmacct-topo-r1            | linux          | running | 172.100.101.2   |
| clab-clab-bgp-ipfix-pmacct-topo-r2            | linux          | running | 172.100.101.3   |
...
+-----------------------------------------------+----------------+---------+-----------------+

注記: SQLiteテーブルはstart.shスクリプトがコンテナ起動時にpmacctの標準スキーマ(/usr/share/pmacct/sql/pmacct-create-table_v1.sqlite3)を適用して自動作成します。スキーマにはDROP TABLE IF EXISTS acct;が含まれるため、手動での作成は不要です。

テーブルが作成されたことを確認:

docker exec clab-clab-bgp-ipfix-pmacct-topo-collector \
  sqlite3 /var/log/pmacct/flows.db "SELECT name FROM sqlite_master WHERE type='table';"
# 出力: acct

3. トラフィックの生成

# srcからdstへICMPトラフィック生成
docker exec clab-clab-bgp-ipfix-pmacct-topo-src ping -c 100 -i 0.2 192.168.2.11

4. IPFIX動作の確認

Collectorログでパケット受信を確認

docker logs clab-clab-bgp-ipfix-pmacct-topo-collector 2>&1 | grep "stats \["

出力例:

NOTICE ( default/core ): stats [0.0.0.0:4739] agent=172.100.101.2:0 
  time=1761264612 packets=16 bytes=3600 seq_good=16 seq_jmp_fwd=0 seq_jmp_bck=0
NOTICE ( default/core ): stats [0.0.0.0:4739] agent=172.100.101.3:0 
  time=1761264612 packets=16 bytes=3432 seq_good=16 seq_jmp_fwd=0 seq_jmp_bck=0

解説:

  • agent=172.100.101.2: r1からのIPFIXパケット
  • agent=172.100.101.3: r2からのIPFIXパケット
  • packets=16: 受信したIPFIXパケット数
  • bytes=3600: 受信したデータ量
  • seq_good=16: シーケンス番号が正常(パケットロスなし)

Exporterログでエクスポート確認

docker exec clab-clab-bgp-ipfix-pmacct-topo-r1 \
  tail -n 20 /var/log/pmacct/pmacctd.log

出力例:

INFO ( default_nfprobe/nfprobe ): Exporting flows to [172.100.101.100]:4739
INFO ( default_nfprobe/nfprobe ): TCP timeout: 10s
INFO ( default_nfprobe/nfprobe ): UDP timeout: 10s
INFO ( default_nfprobe/nfprobe ): ICMP timeout: 10s

5. SQLiteデータベースでフローデータを確認

レコード数確認

docker exec clab-clab-bgp-ipfix-pmacct-topo-collector \
  sqlite3 /var/log/pmacct/flows.db "SELECT COUNT(*) FROM acct;"
# 出力: 5

フローデータの表示

docker exec clab-clab-bgp-ipfix-pmacct-topo-collector \
  sqlite3 -header -column /var/log/pmacct/flows.db \
  "SELECT ip_src, ip_dst, src_port, dst_port, ip_proto, packets, bytes, stamp_inserted 
   FROM acct 
   ORDER BY stamp_inserted DESC 
   LIMIT 10;"

出力例:

ip_src             ip_dst            src_port  dst_port  ip_proto  packets  bytes   stamp_inserted     
-----------------  ----------------  --------  --------  --------  -------  ------  -------------------
192.168.1.11       192.168.2.11      0         2048      icmp      200      16800   2025-10-24 00:37:00
192.168.2.11       192.168.1.11      0         0         icmp      200      16800   2025-10-24 00:37:00
fe80::a8c1:abff:*  ff02::2           0         0         ipv6-icmp 1        56      2025-10-24 00:36:00
...

データの見方:

  • ip_src → ip_dst: フローの方向(192.168.1.11 → 192.168.2.11)
  • ip_proto: icmp = ICMPトラフィック
  • packets: このフローで送信されたパケット数(200)
  • bytes: このフローの総バイト数(16800 = 200パケット × 84バイト)
  • stamp_inserted: データベースに挿入された時刻(1分単位で丸められている)

SQLクエリの応用例

特定IPアドレスのトラフィック集計
docker exec clab-clab-bgp-ipfix-pmacct-topo-collector \
  sqlite3 /var/log/pmacct/flows.db \
  "SELECT ip_src, SUM(packets) as total_packets, SUM(bytes) as total_bytes 
   FROM acct 
   WHERE ip_src = '192.168.1.11' 
   GROUP BY ip_src;"
プロトコル別トラフィック統計
docker exec clab-clab-bgp-ipfix-pmacct-topo-collector \
  sqlite3 /var/log/pmacct/flows.db \
  "SELECT ip_proto, COUNT(*) as flow_count, SUM(packets) as total_packets, SUM(bytes) as total_bytes 
   FROM acct 
   GROUP BY ip_proto 
   ORDER BY total_bytes DESC;"
時系列トラフィック推移
docker exec clab-clab-bgp-ipfix-pmacct-topo-collector \
  sqlite3 /var/log/pmacct/flows.db \
  "SELECT stamp_inserted, COUNT(*) as flows, SUM(packets) as packets, SUM(bytes) as bytes 
   FROM acct 
   GROUP BY stamp_inserted 
   ORDER BY stamp_inserted;"

7. トポロジーの停止

sudo containerlab destroy -t bgp-ipfix-pmacct-topo.clab.yml

トラブルシューティング

データベースにデータが保存されない

症状: SELECT COUNT(*) FROM acct; が0を返す

確認ポイント:

  1. テーブルが作成されているか確認

    docker exec clab-clab-bgp-ipfix-pmacct-topo-collector \
      sqlite3 /var/log/pmacct/flows.db ".tables"
    
  2. collectorログでエラー確認

    docker logs clab-clab-bgp-ipfix-pmacct-topo-collector 2>&1 | grep ERROR
    

    ERROR: no such table: acct が出ていたらテーブル作成が必要(通常はstart.shが自動作成)

  3. IPFIX パケット受信の確認

    docker logs clab-clab-bgp-ipfix-pmacct-topo-collector 2>&1 | grep "stats \["
    

    packets=0 の場合、Exporterからパケットが届いていない

Exporterからパケットが送信されない

確認ポイント:

  1. pmacctdプロセスが起動しているか

    docker exec clab-clab-bgp-ipfix-pmacct-topo-r1 ps aux | grep pmacctd
    
  2. キャプチャインターフェースが正しいか

    docker exec clab-clab-bgp-ipfix-pmacct-topo-r1 ip link show eth1
    
  3. Collectorへの到達性確認

    docker exec clab-clab-bgp-ipfix-pmacct-topo-r1 ping -c 3 172.100.101.100
    docker exec clab-clab-bgp-ipfix-pmacct-topo-r1 nc -vz -u 172.100.101.100 4739
    

タイムアウトが長すぎてデータが見えない

対処法: nfprobe_timeoutsを短くする(検証用)

# pmacctd.confに追記
nfprobe_timeouts: tcp=5:udp=5:icmp=5:general=5:maxlife=30

再起動:

docker exec clab-clab-bgp-ipfix-pmacct-topo-r1 pkill pmacctd
docker exec clab-clab-bgp-ipfix-pmacct-topo-r1 /usr/sbin/pmacctd -f /etc/pmacct/pmacctd.conf

(再掲)まとめ

  • IPFIX + pmacctでBGPルータ環境にフローテレメトリ収集を実装
  • **pmacctd(nfprobeプラグイン)**でIPFIX Exporterとして動作
  • **nfacctd(sqlite3プラグイン)**でCollectorとしてSQLite3にデータ保存
  • SQLiteデータベースで時系列フロー分析とSQLクエリによる柔軟な集計が可能
  • macOS (ARM64) + Devcontainer環境でも動作確認完了

最後に、GMOコネクトでは研究開発や国際標準化に関する支援や技術検証をはじめ、幅広い支援を行っておりますので、何かありましたらお気軽にお問合せください。

お問合せ: https://gmo-connect.jp/contactus/

10
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?