Cacti is a complete network graphing solution designed to harness the power of RRDTool’s data storage and graphing functionality. It provides a fast poller, advanced templating, multiple data acquisition methods, and user management.
| File/Directory | Path | Purpose |
|---|---|---|
| Main config | /etc/cacti/config.php |
Primary Cacti configuration |
| Database config | /etc/cacti/db.php |
Database connection settings |
| RRDTool config | /etc/cacti/rrdtool.conf |
RRDTool settings |
| Poller config | /etc/cacti/poller.php |
Poller configuration |
| Log files | /var/log/cacti/ |
Cacti log files |
| RRD files | /var/lib/cacti/rra/ |
RRD database files |
| Scripts | /usr/share/cacti/site/scripts/ |
Data acquisition scripts |
| Templates | /usr/share/cacti/site/resource/graph_templates/ |
Graph templates |
| Plugins | /usr/share/cacti/plugins/ |
Plugin directory |
| Web config | /etc/apache2/sites-available/cacti.conf |
Apache configuration |
| Cron jobs | /etc/cron.d/cacti |
Scheduled poller tasks |
<?php
/*
* /etc/cacti/config.php
* Cacti Main Configuration File
*/
/*
* Database Configuration
*/
$database_type = 'mysql';
$database_default = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cacti_user';
$database_password = 'SecureCactiPassword123!';
$database_port = '3306';
$database_retries = 5;
$database_ssl = false;
$database_ssl_key = '';
$database_ssl_cert = '';
$database_ssl_ca = '';
/*
* URL Paths
*/
$url_path = '/cacti/';
/*
* Poller Configuration
*/
$poller_interval = 60; // Poller interval in seconds
$max_poller_interval = 300; // Maximum poller interval
$poller_type = 'cmd.php'; // cmd.php or spine
$poller_threads = 4; // Number of poller threads (Spine only)
$poller_processes = 1; // Number of poller processes
/*
* RRDTool Configuration
*/
$rrdtool_version = '1.7'; // RRDTool version
$rrdtool_default_rrd = '/var/lib/cacti/rra';
$rrdtool_path = '/usr/bin/rrdtool';
/*
* Logging Configuration
*/
$log_verbosity = POLLER_VERBOSITY_NONE; // Logging level
$log_path = '/var/log/cacti/cacti.log';
$log_rotate = true;
$log_rotate_size = 10485760; // 10MB
/*
* Authentication Configuration
*/
$auth_method = 1; // 0=None, 1=Internal, 2=LDAP, 3=Web Server
$auth_realm = 'Cacti';
$guest_account = 'guest';
$default_title = 'Cacti Network Monitoring';
$force_ssl = false;
/*
* Session Configuration
*/
$session_lifetime = 3600; // Session timeout in seconds
/*
* Graph Configuration
*/
$default_graphs = 4; // Default graphs per page
$max_graphs = 100; // Maximum graphs per page
$default_tree_level = 3; // Default tree expansion level
/*
* SNMP Configuration
*/
$snmp_defaults = array(
'version' => '2', // 1, 2, or 3
'community' => 'public',
'retries' => 3,
'timeout' => 500, // milliseconds
'port' => 161,
);
/*
* SNMPv3 Configuration
*/
$snmpv3_defaults = array(
'auth_proto' => 'MD5', // MD5 or SHA
'auth_pass' => '',
'priv_proto' => 'DES', // DES or AES
'priv_pass' => '',
'sec_name' => '',
'sec_level' => 'authPriv', // noAuthNoPriv, authNoPriv, authPriv
);
/*
* Email Configuration
*/
$alert_email = 'admin@example.com';
$alert_from_email = 'cacti@example.com';
$alert_from_name = 'Cacti Monitoring';
$smtp_server = 'smtp.example.com';
$smtp_port = 587;
$smtp_username = 'cacti@example.com';
$smtp_password = 'EmailPassword123!';
$smtp_secure = 'tls'; // tls, ssl, or none
/*
* Performance Configuration
*/
$max_data_sources_per_graph = 8;
$max_data_source_name_length = 40;
$maximum_rows_per_table = 100;
/*
* Path Configuration
*/
$path_php_binary = '/usr/bin/php';
$path_cacti = '/usr/share/cacti/site';
$path_rra = '/var/lib/cacti/rra';
$path_log = '/var/log/cacti';
$path_plugins = '/usr/share/cacti/plugins';
/*
* Plugin Configuration
*/
$use_plugins = true;
/*
* Security Configuration
*/
$hide_config = false;
$disable_password_reset = false;
$minimum_password_length = 8;
<?php
/*
* /etc/cacti/db.php
* Database Connection Settings
*/
$database_type = 'mysql';
$database_default = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cacti_user';
$database_password = 'SecureCactiPassword123!';
$database_port = '3306';
$database_retries = 5;
$database_ssl = false;
$database_ssl_key = '';
$database_ssl_cert = '';
$database_ssl_ca = '';
/*
* Database Table Prefix (for multiple installations)
*/
$database_prefix = '';
/*
* Database Connection Options
*/
$database_persistent = false;
$database_charset = 'utf8mb4';
$database_collation = 'utf8mb4_unicode_ci';
/*
* Spine Poller Configuration
* /etc/cacti/spine.conf
*/
/*
* Database Settings
*/
DBHost localhost
DBName cacti
DBUser cacti_user
DBPass SecureCactiPassword123!
DBPort 3306
/*
* Poller Settings
*/
Poller 1
Threads 4
Timeout 20
Retries 3
/*
* Logging
*/
Logfile /var/log/cacti/spine.log
LogLevel 3 /* 0=NONE, 1=ERROR, 2=WARN, 3=INFO, 4=DEBUG */
/*
* SNMP Settings
*/
SNMPVersion 2c
SNMPCommunity public
SNMPPort 161
SNMPTimeout 500
SNMPRetries 3
/*
* SNMPv3 Settings
*/
SNMPv3SecurityName monitoring
SNMPv3AuthProtocol SHA
SNMPv3AuthPassphrase AuthPassword123!
SNMPv3PrivProtocol AES
SNMPv3PrivPassphrase PrivPassword123!
SNMPv3SecurityLevel authPriv
/*
* Data Input Method Configuration
* Managed via Cacti Web UI or database
*/
// Script query data input
$data_input_methods = array(
1 => array(
'name' => 'Get SNMP Data',
'input_string' => '<path_snmpget> -Cv -c <snmp_community> -O qv <snmp_version> <snmp_username> <snmp_password> <snmp_auth_protocol> <snmp_priv_protocol> <snmp_priv_password> <hostname> <oid>',
'type' => 'script_server',
),
2 => array(
'name' => 'Get SNMP Walk',
'input_string' => '<path_snmpwalk> -Cv -c <snmp_community> -O q <snmp_version> <snmp_username> <snmp_password> <snmp_auth_protocol> <snmp_priv_protocol> <snmp_priv_password> <hostname> <oid>',
'type' => 'script_server',
),
3 => array(
'name' => 'Script/Command',
'input_string' => '<path_php_binary> -q <path_cacti>/scripts/script.php <arguments>',
'type' => 'script_server',
),
);
# Add a device using Cacti CLI
php /usr/share/cacti/site/poller_add.php --host-template=1 --description="Web Server 01" --ip=192.168.1.10 --community=public
# Add device with SNMPv3
php /usr/share/cacti/site/poller_add.php \
--host-template=1 \
--description="Core Router" \
--ip=192.168.1.1 \
--snmp-version=3 \
--snmp-username=monitoring \
--snmp-password=AuthPass123 \
--snmp-authproto=SHA \
--snmp-privproto=AES \
--snmp-privpass=PrivPass123
# List available host templates
php /usr/share/cacti/site/poller_templates.php --list
/*
* Host Template Configuration
* Managed via Cacti Web UI
*/
// Generic SNMP-enabled Host template
$host_template = array(
'name' => 'Generic SNMP-enabled Host',
'graph_template' => 1,
'availability_method' => 1, // SNMP
'ping_method' => 1, // ICMP
'ping_port' => '',
'ping_timeout' => 400,
'ping_retries' => 2,
'snmp_community' => 'public',
'snmp_version' => '2',
'snmp_username' => '',
'snmp_password' => '',
'snmp_auth_protocol' => '',
'snmp_priv_protocol' => '',
'snmp_priv_password' => '',
'snmp_context' => '',
'snmp_port' => 161,
'snmp_timeout' => 500,
'snmp_retries' => 3,
'max_oids' => 10,
'device_threads' => 1,
);
// Linux Server template
$linux_template = array(
'name' => 'Linux Server',
'graph_template' => 2,
'availability_method' => 1,
'ping_method' => 1,
'snmp_community' => 'public',
'snmp_version' => '2',
);
// Network Device template
$network_template = array(
'name' => 'Network Device',
'graph_template' => 3,
'availability_method' => 1,
'ping_method' => 1,
'snmp_community' => 'public',
'snmp_version' => '2',
);
/*
* Graph Template Configuration
* Example: Traffic in bits
*/
$graph_template = array(
'name' => 'Local - Traffic - bits',
'title' => '|host_description| - Traffic - |query_ifName|',
'vertical_label' => 'bits/sec',
'suggested_height' => 120,
'suggested_width' => 500,
'unit_exponent_value' => '',
'unit_value' => '',
'y_axis_format' => 'lowercase',
);
/*
* Data Template: Traffic
*/
$data_template = array(
'name' => 'Traffic - bits',
'data_input_id' => 2, // SNMP
'data_source_profile_id' => 1,
'rra' => array(
array('steps' => 1, 'rows' => 700, 'cf' => 'AVERAGE'),
array('steps' => 6, 'rows' => 700, 'cf' => 'AVERAGE'),
array('steps' => 24, 'rows' => 700, 'cf' => 'AVERAGE'),
array('steps' => 288, 'rows' => 700, 'cf' => 'AVERAGE'),
),
'data_source' => array(
'name' => 'traffic_in',
'data_source_type_id' => 2, // GAUGE
'rrd_heartbeat' => 600,
'rrd_minimum' => '0',
'rrd_maximum' => '10000000000',
),
);
<?php
/*
* /etc/cacti/plugins/thold/config.php
* Thold Plugin Configuration
*/
/*
* Threshold Configuration
*/
$thold_email_address = 'alerts@example.com';
$thold_email_from = 'cacti@example.com';
$thold_email_subject = 'Cacti Threshold Alert - |HOSTNAME| - |DSNAME|';
/*
* Email Settings
*/
$thold_smtp_server = 'smtp.example.com';
$thold_smtp_port = 587;
$thold_smtp_username = 'cacti@example.com';
$thold_smtp_password = 'EmailPassword123!';
$thold_smtp_secure = 'tls';
/*
* Alert Settings
*/
$thold_acknowledgement = true;
$thold_acknowledge_timeout = 3600; // 1 hour
$thold_alert_body = '
Threshold Alert
Host: |HOSTNAME|
Description: |HOSTDESC|
Data Source: |DSNAME|
Current Value: |CURVAL|
Threshold: |THOLD0|
Date: |DATE|
Please investigate.
--
Cacti Monitoring System
';
/*
* Notification Rules
*/
$thold_rule = array(
'name' => 'Critical Thresholds',
'enabled' => true,
'threshold_type' => 0, // 0=High, 1=Low
'threshold_value' => 90,
'time_type' => 0, // 0=Minutes, 1=Hours, 2=Days
'time_value' => 5,
'notification_type' => 1, // 1=Email
'notification_recipient' => 'admin@example.com',
);
#!/bin/bash
# /usr/local/bin/cacti-slack-alert.sh
WEBHOOK_URL="https://hooks.slack.com/services/XXX/YYY/ZZZ"
CHANNEL="#monitoring-alerts"
# Parse Cacti environment variables
HOSTNAME="$CACTI_HOSTNAME"
DESCRIPTION="$CACTI_HOSTDESC"
DSNAME="$CACTI_DSNAME"
CURVAL="$CACTI_CURVAL"
THOLD="$CACTI_THOLD0"
DATE="$CACTI_DATE"
# Create payload
PAYLOAD=$(cat <<EOF
{
"channel": "$CHANNEL",
"username": "Cacti",
"icon_emoji": ":chart_with_upwards_trend:",
"attachments": [
{
"color": "danger",
"title": "Cacti Threshold Alert",
"fields": [
{"title": "Host", "value": "$HOSTNAME", "short": true},
{"title": "Description", "value": "$DESCRIPTION", "short": true},
{"title": "Data Source", "value": "$DSNAME", "short": true},
{"title": "Current Value", "value": "$CURVAL", "short": true},
{"title": "Threshold", "value": "$THOLD", "short": true},
{"title": "Date", "value": "$DATE", "short": true}
]
}
]
}
EOF
)
curl -X POST -H 'Content-type: application/json' --data "$PAYLOAD" "$WEBHOOK_URL"
# Check Cacti configuration
php /usr/share/cacti/site/poller_check.php
# Verify database connection
php /usr/share/cacti/site/poller_database.php
# Check RRDTool installation
rrdtool version
# Verify poller configuration
php /usr/share/cacti/site/poller.php --debug
# Check file permissions
ls -la /var/lib/cacti/
ls -la /var/log/cacti/
# Restart Apache (for web interface)
sudo systemctl restart apache2
# or
sudo systemctl restart httpd
# Restart PHP-FPM if applicable
sudo systemctl restart php-fpm
# Restart poller (via cron or manually)
sudo systemctl restart cacti
# Check service status
sudo systemctl status apache2
sudo systemctl status cacti
# View logs
sudo tail -f /var/log/cacti/cacti.log
sudo tail -f /var/log/cacti/spine.log
# Run poller manually
php /usr/share/cacti/site/poller.php
# Run with debug output
php /usr/share/cacti/site/poller.php --debug
# Run Spine poller
/usr/local/spine/bin/spine
# Run Spine with debug
/usr/local/spine/bin/spine -C /etc/cacti/spine.conf -V 5
# Test database connection
mysql -u cacti_user -p -e "SELECT * FROM cacti.settings LIMIT 1;"
# Check database tables
mysql -u cacti_user -p -e "SHOW TABLES FROM cacti;"
# Verify database schema
php /usr/share/cacti/site/poller_upgrade.php --check-only
# Check poller status
php /usr/share/cacti/site/poller.php --debug
# View poller statistics
mysql -u cacti_user -p -e "SELECT * FROM cacti.poller_time;"
# Check RRD updates
ls -lt /var/lib/cacti/rra/ | head -20
# Check RRD files
ls -la /var/lib/cacti/rra/
# Test RRDTool
rrdtool info /var/lib/cacti/rra/poller_1_*.rrd
# View generated graphs
ls -la /var/cache/cacti/www/graphs/
# Test graph generation
php /usr/share/cacti/site/poller_graphs.php --debug
# View Cacti log
tail -f /var/log/cacti/cacti.log
# View Spine log
tail -f /var/log/cacti/spine.log
# View Apache error log
tail -f /var/log/apache2/cacti_error.log
# Search for errors
grep -i error /var/log/cacti/*.log
Every deployment is unique. We provide consulting for:
Get personalized assistance: office@linux-server-admin.com | Contact Page