2 Years Self Hosted Finally Proud
Welcome fellow DevOps enthusiasts! Today were going to delve into a journey I embarked on two years ago, the construction of a self-hosted dashboard for mana....
2 Years Self Hosted Finally Proud: A Comprehensive Guide to Building a Powerful Dashboard for Homelab and Self-Hosted Environments
Welcome fellow DevOps enthusiasts! Today we’re going to delve into a journey I embarked on two years ago, the construction of a self-hosted dashboard for managing and monitoring my homelab environment. The goal was to have a centralized tool to streamline tasks, improve efficiency, and maintain optimal system performance. In this post, we’ll discuss the setup, configuration, and operations of this powerful dashboard that I’m proud to say I’ve built from scratch.
Prerequisites
- Operating System: Ubuntu 20.04 LTS or later (we’ll be using version 20.04 in our examples)
- Hardware: Minimum: 4 cores, 8GB RAM, SSD storage; Recommended: 8 cores, 16GB RAM, NVMe SSD
- Software: Node.js v14.x, Nginx, MySQL (or MariaDB), Redis, InfluxDB, Grafana
- Network Requirements: Static IP address, port forwarding for external access
- User Permissions: A dedicated user with sudo privileges and a separate database user
Installation & Setup
- Install Node.js:
sudo apt install nodejs
- Install required packages:
sudo npm install -g pm2
(for managing processes) - Clone the dashboard repository:
git clone https://github.com/[your-username]/[your-dashboard].git
- Configure environment variables in a
.env
file (see example below):1 2 3 4 5 6 7
DB_HOST=localhost DB_USER=[your-db-user] DB_PASSWORD=[your-db-password] REDIS_URL=redis://localhost INFLUXDB_URL=http://influxdb:8086 INFLUXDB_ORG=[your-influxdb-org] INFLUXDB_BUCKET=[your-influxdb-bucket]
- Install dependencies and start the dashboard:
cd [your-dashboard] && npm install && pm2 start index.js
- Configure Nginx as a reverse proxy for the dashboard:
1 2 3 4 5 6 7 8 9 10 11 12
server { listen 80; server_name yourdomain.com; location / { proxy_pass http://localhost:3000; proxy_set_header Host $host; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header X-Real-IP $remote_addr; } }
- Reload Nginx configuration:
sudo systemctl reload nginx
- Verify the dashboard is accessible at your domain or IP address
Configuration
- Customize the dashboard’s appearance and add widgets as needed (Grafana’s UI allows for extensive customization)
- Configure data sources to connect to your monitoring tools like Prometheus, Elasticsearch, etc.
- Secure your installation by following Grafana’s security best practices, such as enabling two-factor authentication and restricting IP addresses
- Optimize performance by adjusting Grafana’s settings, including limiting the number of panels per dashboard and configuring alerts properly
Usage & Operations
- Common operations include creating and editing dashboards, adding data sources, and setting up alerts
- Monitor your environment with real-time graphs, logs, and other tools integrated into the dashboard
- Backup the Grafana database regularly to ensure data integrity (see official documentation)
- Recover from a backup in case of an incident by following Grafana’s recovery procedures
- Scale the dashboard horizontally by adding more resources or vertically by upgrading hardware as needed
Troubleshooting
- Check the logs for any errors or warnings (
sudo journalctl -u grafana-agent
) - Debug common issues such as connection errors and performance bottlenecks
- Adjust Grafana’s settings to improve performance and stability
- Secure your installation by following best practices like enforcing strong passwords, limiting user permissions, and keeping software up-to-date
In conclusion, we’ve walked through the process of setting up a self-hosted dashboard for managing and monitoring a homelab environment. By completing this guide, you’ll have gained valuable insights into the practical aspects of building such a tool, as well as tips on how to optimize its performance and enhance its security.
As always, stay curious and keep learning! For further study, consult Grafana’s official documentation and explore other resources like monitoring tools, alerting systems, and more. Happy dashboarding! 🚀