This script addresses a specific use case of monitoring for TCAM exhaustion for networks leveraging Cisco Security Group Tags. To date Cisco's management platforms do not collect these metrics. The script retrieves TCAM stats for SGT bindings, security acls, and IP bindings.
Python utility to connect to Cisco switches, parse command output with PyATS/Genie, and optionally write structured JSON.
It can also write slim TCAM metrics directly into InfluxDB for use in a TIG stack.
pip install -r requirements.txt
cp influx.env.example influx.env
# Edit influx.env with your InfluxDB credentials and endpointpython scripts/collect_pyats_command.py \
--testbed testbed.yaml \
--device sw1 \
--command "show interfaces status" \
--output outputs/sw1_interfaces.jsonpython scripts/collect_pyats_command.py \
--host 10.10.10.10 \
--username admin \
--device sw1 \
--command "show version" \
--output outputs/sw1_version.jsonThe inventory file specifies switches with their credentials and model. Commands are determined by model from the script:
python scripts/collect_pyats_command.py \ --inventory inventories/switches.example.yaml \ --output outputs/tcam_multi_switch.json
show platform hardware fed switch active fwd-asic resource tcam utilizationshow platform hardware fed active fwd-asic resource tcam utilizationYou can override the command for all switches:
python scripts/collect_pyats_command.py \
--inventory inventories/switches.example.yaml \
--command "show version" \
--output outputs/tcam_multi_switch.jsonFirst, create influx.env from the example:
cp influx.env.example influx.env
# Edit influx.env with your InfluxDB v2 credentialsThen use it for InfluxDB v2:
source influx.env python scripts/collect_pyats_command.py \ --inventory inventories/switches.example.yaml \ --no-output \ --influx-write \ --influx-url "$INFLUX_URL" \ --influx-org "$INFLUX_ORG" \ --influx-bucket "$INFLUX_BUCKET" \ --influx-token "$INFLUX_TOKEN"
Or for InfluxDB v1, update influx.env with v1 credentials instead:
python scripts/collect_pyats_command.py \
--inventory inventories/switches.example.yaml \
--no-output \
--influx-write \
--influx-url http://localhost:8086 \
--influx-db network \
--influx-user telegraf \
--influx-password 'replace-me'Measurement name defaults to tcam_utilization and can be changed with --influx-measurement.
You will be prompted for password if not provided through --password.
To run collection repeatedly at a fixed interval:
./scripts/runner.sh 300
This will run collection every 300 seconds (5 minutes), continuously.
This runs in Influx-only mode and does not write local JSON files. Press Ctrl+C to stop.
The runner requires influx.env to be configured with your InfluxDB credentials.
This path is cross-platform for Unix-like systems (macOS/Linux) and does not depend on launchd.
For Windows, use python scripts/collect_pyats_command.py ... with Task Scheduler at your desired interval.
The ops/ directory is optional. It contains a macOS LaunchAgent plist for users who prefer launchd instead of running ./scripts/runner.sh directly.
If you do not use launchd, you can ignore ops/com.tcam.monitor.ingest.plist.
Owner
Contributors
Categories
NetworkingProducts
Catalyst SwitchesLicense
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community