How tharkadharshana/cacti works
Project type and purpose
• Cacti is a monolithic, full-stack PHP web application with an accompanying CLI-based poller service.
• Purpose: network graphing and monitoring platform leveraging RRDtool and SNMP.
Main architectural layers & components
A. Presentation Layer (Web UI)
• Web server (Apache/Nginx) serving PHP via CGI/FPM
• PHP scripts under root (e.g., index.php, auth_*.php, graph_*.php)
• Themes, CSS/JS in include/themes and include/js
• Localization under locales/LC_MESSAGES
B. Application Layer (Business Logic)
• Core libraries (lib/*.php): data modeling, API endpoints, graph/render logic, authentication, templating, caching utilities
• Plugins framework (plugins/)
• Automation and discovery modules (automation_*.php)
C. Data Collection Layer (Poller Service)
• Systemd service cactid.service or cron invoking poller.php and its sub-modules (poller_*.php)
• SNMP Agent (snmpagent_*, remote_agent.php)
• CLI tools (cli/*.php) for on-demand data import, upgrades, audit, automation
D. Data Storage & Processing
• MySQL/MariaDB database (tables defined in cacti.sql, manipulated via cli/upgrade_database.php)
• RRD files under rra/ manipulated via RRDtool (rrd.php, rrdcheck.php, rrdcleaner.php)
• Cache files in cache/ for speeding up queries and graphs
E. External Dependencies & Integrations
• RRDtool binary
• Net-SNMP library for SNMP data collection
• PHP modules (snmp, pdo_mysql, rrdtool, etc.)
• Optional remote poller nodes communicating over HTTP/MySQL replication
Relationships & data flows
1. User → Browser → Web Server → PHP-FPM → Application Layer
• Authentication → Session management → UI controllers → Lib APIs → DB/RRD
2. Application Layer ↔ MySQL/MariaDB
• Configuration, templates, permissions, graph metadata
3. Application Layer ↔ RRDtool
• Graph definitions → RRDtool generates PNG/SVG → Served to UI
4. Poller Service → SNMP (via Net-SNMP or php-snmp) → Device → poller logic writes to RRD & DB
5. Cache Layer sits between Lib APIs and disk to reduce repeated DB/RRD calls
6. Plugins and Automation modules plug into core lib APIs
Key architectural patterns & principles
• Modular monolith: single deployable codebase, logically modular via lib/, plugins/, include/
• MVC-inspired separation: scripts (controllers/view entry points) vs. library classes (models/business logic)
• Cron/Systemd-driven workers for long-running pollers separated from HTTP requests
• Plugin framework for extensibility
• Templating for reusable graph/data source definitions
Elements
• Component labels: e.g., “Web Server (Apache/Nginx)”, “PHP-FPM / HTTP Entry Points”, “Application Core Libraries”, “Cron/Systemd Poller Service”, “MySQL/MariaDB”, “RRDtool Engine”, “Cache Storage”.