Module Overview
In this module, you'll configure Grafana to connect to the LibreNMS MySQL database, enabling visualization of SNMP-based network device metrics including interface traffic, device availability, BGP session status, and environmental sensors.
🏗️ Understanding the LibreNMS Data Model
LibreNMS stores all collected metrics in a MySQL/MariaDB database. Understanding the schema is critical for writing effective queries. The database uses a relational model where devices are the central entity, with related tables storing ports, sensors, BGP peers, and historical metrics.
Step 1: Core Database Tables
LibreNMS organizes data across several key tables. Here are the most important ones for dashboard creation:
| Table Name | Purpose | Key Columns |
|---|---|---|
devices |
Network devices inventory | device_id, hostname, sysName, location, status, uptime |
ports |
Network interfaces and statistics | port_id, device_id, ifName, ifAlias, ifSpeed, ifOperStatus |
bgpPeers |
BGP neighbor relationships | bgpPeer_id, device_id, bgpPeerRemoteAddr, bgpPeerState |
sensors |
Environmental and hardware sensors | sensor_id, device_id, sensor_class, sensor_current, sensor_limit |
bill_port_counters |
95th percentile billing data | bill_id, timestamp, in_delta, out_delta |
eventlog |
Device and interface events | event_id, device_id, type, message, datetime |
Pro Tip: Table Relationships
Almost all queries will join back to the devices table using device_id
as the foreign key. This allows you to filter by hostname, location, or device attributes while
retrieving port or sensor data. The ports table is your primary source for interface
bandwidth metrics.
Content to add: Database diagram, table relationships, example queries showing data structure
🔐 Section 2: Creating Read-Only Database User
- Why use dedicated read-only credentials
- MySQL user creation commands
- Granting SELECT permissions
- Testing database connectivity
⚙️ Section 3: Adding MySQL Data Source in Grafana
- Navigate to Data Sources configuration
- Select MySQL data source type
- Configure connection parameters (host, port, database, credentials)
- Set connection pooling options
- Test connection and troubleshoot
Content to add: Screenshots of Grafana UI, step-by-step configuration walkthrough
📊 Section 4: Writing Your First LibreNMS Query
- Query device inventory
- Retrieve interface statistics
- Calculate bandwidth utilization
- Time-based filtering with $__timeFilter()
- Using Grafana variables in queries
🎨 Section 5: Creating Dashboard Variables
- Device selection variable (query: SELECT DISTINCT hostname FROM devices)
- Interface selection variable
- Multi-value and "All" options
- Variable dependency and chaining
📈 Section 6: Building Network Monitoring Panels
- Panel 1: Device availability status (Stat panel)
- Panel 2: Interface bandwidth time series
- Panel 3: BGP peer status table
- Panel 4: Top interfaces by utilization
- Panel 5: Device error rates
Content to add: Complete SQL queries for each panel, panel configuration options, expected output examples
🔧 Section 7: Common LibreNMS Query Patterns
- Joining devices and ports tables
- Aggregating data across multiple interfaces
- Calculating percentages and ratios
- Handling NULL values and missing data
- Performance optimization tips
✅ Section 8: Verification and Testing
- Verify data source shows green status
- Test queries return expected results
- Compare values with LibreNMS UI
- Check query performance (execution time)
- Validate timestamp accuracy
🎯 Expansion Guidelines
When expanding this module, include:
- Step-by-step screenshots of Grafana UI
- Complete, tested SQL queries with explanations
- Common error messages and solutions
- Real-world examples from production environments
- Security best practices and warnings
- Performance benchmarks and optimization tips