Cacti Setup: Templates, Polling and Adding Devices at Scale - 夜莺博客

Cacti Setup: Templates, Polling and Adding Devices at Scale

Cacti has been graphing network data with RRDtool for two decades, and its strength is not novelty — it is templates. Once a device template exists, onboarding the next forty identical switches is a formality, and the graphs are consistent because nobody hand-built them. This guide covers the object model, the SNMP defaults that decide whether polling works at all, and the command-line path for onboarding a rack without clicking.

The Object Model

  • Device — a monitored thing: hostname, SNMP credentials, availability method, site, device template.
  • Device template (host template) — a bundle of graph templates and data queries applied to a class of device, for example Cisco Router or Net-SNMP Device.
  • Graph template — how the graph is drawn: size, legend, axes.
  • Data template — how data is stored in the RRD file and how often it is collected.
  • Data query — an SNMP walk that discovers indexable entities (interfaces, sensors) and offers them as options.

The reason to invest in templates rather than creating data sources by hand is arithmetic: at a hundred devices, a change made per device is a hundred changes, and at least three of them will be wrong.

Install, Briefly

sudo apt install cacti cacti-spine snmp snmp-mibs-downloader
# Follow the web installer at http://server/cacti, then log in and change the default admin password
sudo systemctl status cacti
sudo -u www-data php /var/www/html/cacti/poller.php --force

Install cacti-spine and select it as the poller when you exceed a few hundred data sources. The PHP poller is a fine default and a poor choice at scale.

SNMP Defaults Decide Everything

Configuration → Settings → Device Defaults sets what new devices inherit. Getting this right before onboarding devices is what prevents “I have to edit every device after adding it”.

General Defaults:
  Template         Net-SNMP Device (or your own)
  Site             your physical location
  Poller           main
  Device Threads   1 (spine only)

SNMP Defaults:
  Version          3
  Security Level   authPriv
  Auth Protocol    SHA
  Privacy Protocol AES
  Port Number      161
  Timeout          500 ms
  Retries          2

Prefer SNMPv3 with authPriv in production. SNMPv2c community strings travel in clear text on every poll.

Availability: Decide What “Up” Means

Method Behaviour
None Always assume up — for objects with no meaningful state
Ping ICMP or TCP check only
SNMP Uptime Query the sysUpTime instance only
Ping and SNMP Uptime Both must succeed; the strictest and most common choice
Ping or SNMP Uptime Either suffices — tolerant of a device that blocks ICMP
SNMP Desc For agents with no usable uptime OID

Combine this with the failure/recovery counts: how many consecutive cycles must fail before the device is declared down, and how many must succeed before it is considered recovered. Setting both to 1 makes a flapping device generate alert storms; setting them high delays genuine outage detection.

Add a Device in the UI

Console → Devices → Add: description, hostname, device template, availability method, SNMP version and credentials, then Create and Create Graphs for this Device to select which data queries to graph. For anything more than a handful of devices, do this from the CLI instead.

Add Devices from the CLI

cd /var/www/html/cacti/cli
php add_device.php --list-device-types

php add_device.php \
  --description="dc1-sw01" \
  --ip=10.10.20.1 \
  --template=3 \
  --avail=ping \
  --ping_method=icmp \
  --ping_timeout=500 \
  --ping_retries=2 \
  --version=3 \
  --username=cactimon \
  --password='authpass' \
  --authproto=SHA \
  --privpass='privpass' \
  --privproto=AES \
  --notes='DC1 Rack 42'

# Minimal form, relying on device defaults for everything else
php add_device.php --description=test --ip=192.168.1.15

--list-device-types prints the numeric template IDs; script that lookup rather than hard-coding 3, because template IDs differ between installs.

Graph the Interfaces

php add_graphs.php --host-id=45 --list-graph-types
php add_graphs.php --host-id=45 --graph-type=ds --graph-template-id=4 --snmp-query-id=1 --snmp-query-type-id=13 --snmp-field=ifDescr --snmp-value=GigabitEthernet0/1

For a whole rack, list the interfaces with an SNMP walk, then loop add_graphs.php over the output. That is the difference between a ten-minute onboarding and an afternoon of clicking.

Polling and Health

sudo -u www-data php poller.php --force          # run once, watch the output
sudo -u www-data php poller.php --force --debug  # per-data-source detail
tail -f /var/www/html/cacti/log/cacti.log
/usr/bin/spine --version

Check Console → Utilities → System Utilities for the poller cache and RRD file integrity, and watch the poller runtime: if a 5-minute cycle takes longer than 5 minutes, you are silently skipping polls, which shows up as gaps in graphs rather than as an alert. That is the point at which you install spine, spread polling across pollers, or reduce the data you collect.

The Habit That Makes Cacti Pleasant

Build one device template per platform, keep it in version control as an export, and resist per-device edits. Document the numeric template IDs and pin them in your onboarding script. A Cacti install that is consistent for a year is one where someone refused to make exceptions — and a Cacti install that nobody trusts is one where every device has three bespoke data sources.

Related Reading

Deeper dives on the same topics from our archive:

原文链接:https://docs.cacti.net/Devices.md