config sflow サブコマンド¶
概要¶
config sflow は sFlow のグローバル制御(admin / polling-interval / sample-direction / agent-id)と、インターフェイス単位のサンプル設定、最大 2 件のコレクタ登録を扱う。すべて config/main.py 内に直接定義され、3 段の click group (sflow / sflow interface / sflow collector / sflow agent-id) で構成される1。
config sflow enable だけは特殊で、SFLOW|global.admin_state を up にしたうえで systemctl is-active sflow を確認し、未アクティブなら systemctl enable sflow + start sflow を実行する。それ以外のコマンドは CONFIG_DB 書き込みのみ。
コマンド一覧¶
| コマンド | 用途 |
|---|---|
config sflow enable |
sFlow グローバル ON。サービス未起動なら起動 |
config sflow disable |
sFlow グローバル OFF |
config sflow polling-interval <0\|5-300> |
カウンタサンプル周期(秒)。0 で無効 |
config sflow sample-direction <rx\|tx\|both> |
グローバルサンプル方向 |
config sflow agent-id add <interface_name> |
sFlow agent 用インターフェイス登録 |
config sflow agent-id del |
agent 設定を削除 |
config sflow interface enable <ifname\|all> |
インターフェイス単位で有効化 |
config sflow interface disable <ifname\|all> |
インターフェイス単位で無効化 |
config sflow interface sample-rate <ifname> <256-8388608\|default> |
サンプルレート |
config sflow interface sample-direction <ifname> <rx\|tx\|both> |
インターフェイスサンプル方向 |
config sflow collector add <name> <ipv4/v6> [--port N] [--vrf default\|mgmt] |
コレクタ追加(最大 2 件) |
config sflow collector del <name> |
コレクタ削除 |
各コマンドの詳細¶
config sflow enable / disable¶
SFLOW|global の admin_state を up / down に書き換える。既存のテーブルが無い場合は {'global': {'admin_state': 'up'}} を新規作成。enable は加えて、systemd ユニット sflow が active でなければ enable + start する2。
config sflow polling-interval <interval>¶
範囲: 0 (無効) または 5-300 秒。SFLOW|global.polling_interval を整数で書く。
config sflow sample-direction <direction>¶
rx / tx / both の Choice。tx / both は STATE_DB.SWITCH_CAPABILITY|switch.PORT_EGRESS_SAMPLE_CAPABLE が true のプラットフォームでのみ許可される3。
📋 検証エビデンス: sonic-net/sonic-utilities/config/main.py#L9136-L9159 (sha: 39732bceb8bdefe706518ab40623bbbba6ff33b9)
出典:
sonic-net/sonic-utilities/config/main.py#L9136-L9159 (sha: 39732bceb8bdefe706518ab40623bbbba6ff33b9)
抜粋:
config sflow interface enable <ifname|all>¶
ifname は interface_name_is_valid で検証、ただし特殊値 all も許可。SFLOW_SESSION|<ifname> の admin_state を up に書く。テーブルにエントリが無ければ新規作成。
config sflow interface sample-rate <ifname> <rate|default>¶
rate は 256 〜 8388608 の整数文字列。default 指定時は当該インターフェイスエントリから sample_rate フィールドを削除する(エントリ自体は残る)。
config sflow interface sample-direction <ifname> <direction>¶
interface 用 sample-direction。グローバルと同じ tx/both の egress capability チェックを行う。
config sflow collector add <name> <ipaddr> [--port N] [--vrf default|mgmt]¶
制約:
<name>は 16 文字以下<ipaddr>はis_ipaddressで検証--port0-65535、default 6343--vrfはdefaultまたはmgmtのみSFLOW_COLLECTORは 最大 2 件まで4
書き込み: SFLOW_COLLECTOR|<name> に collector_ip / collector_port / collector_vrf を mod_entry で書く。
config sflow agent-id add <interface_name>¶
netifaces.interfaces() に存在する name のみ許可。SFLOW|global.agent_id を書き換える。既に agent_id が存在する場合は Agent already configured で終了し、del 経由で先に削除する必要がある。
関連する CONFIG_DB¶
| テーブル | key | 主なフィールド |
|---|---|---|
SFLOW |
global |
admin_state / polling_interval / sample_direction / agent_id |
SFLOW_SESSION |
<interface> |
admin_state / sample_rate / sample_direction |
SFLOW_COLLECTOR |
<name> |
collector_ip / collector_port / collector_vrf |
プラットフォーム依存¶
- egress sampling(
tx/both):STATE_DB.SWITCH_CAPABILITY|switch.PORT_EGRESS_SAMPLE_CAPABLEを見て無効化される。 - コレクタ数: 2 件固定(コード上のリテラル)。
- VRF:
defaultとmgmtのみ。任意 data VRF はサポート外。
関連リファレンス¶
引用元¶
実行例¶
典型的な使い方¶
よくある引数の組み合わせ¶
# Collector 追加 + agent ID 指定
sudo config sflow collector add collector1 10.0.0.50 --port 6343
sudo config sflow agent-id add Loopback0
# ポートごとの sampling-rate
sudo config sflow interface sample-rate Ethernet0 8192
期待される出力 (抜粋)¶
データフロー (自動生成)¶
flowchart LR
CLI["config sflow"]
SC["sonic-cfggen<br/>(config CLI のみ)"]
CLI --> SC
CDB0[("CONFIG_DB<br/>SFLOW")]
SC --> CDB0
DM0["sflowmgrd"]
CDB0 --> DM0
CDB1[("CONFIG_DB<br/>SFLOW_SESSION")]
SC --> CDB1
DM1["sflowmgrd"]
CDB1 --> DM1
凡例
config 系 (CLI → CONFIG_DB → daemon) のミニ図。テーブル → daemon 対応は docs/reference/config-db-orch-map.md から機械生成。
関連 Topics¶
運用ヒント¶
典型的な利用シーン¶
- sFlow agent / collector / sampling-rate の設定とインタフェース別 polling。
- テレメトリ収集系(InfluxDB / Kafka)連携前段。
よくある落とし穴¶
- sampling-rate を小さくしすぎると CPU 使用率が跳ねる。1:1024 程度を目安に。
- Mgmt port は sFlow 対象外。データプレーン経由で collector に到達できる経路が必要。
関連する show / debug¶
関連 CLI コマンド¶
show flowcnt— show flowcnt-trap / flowcnt-route サブコマンドshow snmpagentaddress— show snmpagentaddress サブコマンドshow snmptrap— show snmptrap サブコマンドshow techsupport— show techsupport コマンドconfig mirror session— config mirror_session サブコマンド
-
config sflowグループ定義はconfig/main.pyL9042-L9048。https://github.com/sonic-net/sonic-utilities/blob/39732bceb8bdefe706518ab40623bbbba6ff33b9/config/main.py#L9042 ↩ -
enableの systemd 起動分岐は L9070-L9079。https://github.com/sonic-net/sonic-utilities/blob/39732bceb8bdefe706518ab40623bbbba6ff33b9/config/main.py#L9070 ↩ -
egress capability チェック関数は
is_port_egress_sflow_supported(L9126-L9131)。 ↩ -
コレクタ件数チェックは L9354
len(collector_tbl) == 2で 2 件固定。https://github.com/sonic-net/sonic-utilities/blob/39732bceb8bdefe706518ab40623bbbba6ff33b9/config/main.py#L9354 ↩