Homelab Monitoring Made Easy - Part 2: Creating Dashboards For Docker, Crowdsec, and Sophos XG
Table of Contents
Introduction
In this tutorial, we will walk through the process of creating dashboards for Docker, CrowdSec, and Sophos XG using Grafana and InfluxDB. This guide is designed to help you configure your monitoring tools, connect them effectively, and visualize the collected metrics in a user-friendly manner.
Chapter 1: Creating a Docker Dashboard
Step 1: Configure Telegraph for Docker Metrics
-
Open the
telegraph.conf
file. -
Add the following output configuration at the bottom:
[[outputs.influxdb]] url = "http://influxdb:8086" token = "your_generated_token" organization = "home" bucket = "home_lab"
-
Create an API token in InfluxDB:
- Navigate to the Buckets section.
- Click on "Generate API Token."
- Name the token (e.g., "home lab 2") and copy it.
-
Replace
"your_generated_token"
in the configuration with the copied token.
Step 2: Restart Telegraph
-
Run the following command to restart the Telegraph Docker container:
docker restart <telegraph_container_name>
Step 3: Verify Data in InfluxDB
- Go to the InfluxDB Buckets section and check if the "home_lab" bucket contains data. This may take a few minutes to populate.
Step 4: Connect Grafana to InfluxDB
-
Open Grafana and navigate to Data Sources.
-
Click "Add Data Source" and select InfluxDB.
-
Set the following configurations:
- URL:
http://influxdb:8086
- InfluxDB Version: v2
- Query Language: Flux
- Authentication: Basic Auth (provide your credentials)
- URL:
-
Paste the API token generated in the previous steps.
-
Set the Default Bucket to "home_lab."
-
Click "Save & Test" to confirm the connection works.
Step 5: Import a Docker Dashboard in Grafana
- Go to Grafana's dashboard section.
- Click "New" and then "Import."
- Enter the dashboard ID (e.g.,
17020
for a Docker dashboard) or paste the URL. - Select the InfluxDB data source and click "Import."
Step 6: Customize Your Dashboard
- Once imported, check the default time range and modify the visualizations as necessary. Explore the queries to tweak metrics to your liking.
Chapter 2: Creating a CrowdSec Dashboard
Step 1: Configure Prometheus for CrowdSec
-
Open the
prometheus.yml
configuration file. -
Add a new scrape job for CrowdSec:
scrape_configs: - job_name: 'crowdsec' static_configs: - targets: ['<crowdsec_ip>:6060']
-
Ensure port
6060
is exposed in your Docker Compose file for CrowdSec and redeploy the container.
Step 2: Confirm Prometheus is Scraping CrowdSec
- Visit the Prometheus UI and check the "Targets" section to ensure the CrowdSec target is being scraped successfully.
Step 3: Connect Grafana to Prometheus
- In Grafana, go to Data Sources.
- Click "Add Data Source" and select Prometheus.
- Set the URL to
http://prometheus:9090
and click "Save & Test."
Step 4: Import CrowdSec Dashboards
- Go to the CrowdSec GitHub page and copy the raw dashboard JSON.
- In Grafana, click "New" and then "Import."
- Paste the raw JSON and click "Load."
- Select your Prometheus data source and import the dashboard.
Chapter 3: Creating a Sophos XG Dashboard
Step 1: Enable SNMP on Sophos XG
- Access the Sophos XG firewall interface.
- Navigate to Administration > SNMP.
- Create a new SNMP community with a name (e.g., "sophos_XG").
- Add your Docker host IP address to allow querying.
Step 2: Download and Configure MIBs
- Download the MIBs file from Sophos XG's website and place it in a designated MIB folder within your Docker host. Ensure this folder is referenced in your
Docker Compose
file.
Step 3: Configure Telegraph for SNMP
-
Open the
telegraph.conf
file and add SNMP inputs referencing the MIBs:[[inputs.snmp]] agents = ["<sophos_xg_ip>"] community = "sophos_XG" # Additional OIDs can be added here
-
Restart the Telegraph container to apply changes.
Step 4: Create a Dashboard for Sophos XG
- In Grafana, create a new dashboard and select a stat panel.
- Use the Flux query editor to pull data from InfluxDB.
- Customize the panel to display relevant metrics.
Conclusion
You have successfully created dashboards for Docker, CrowdSec, and Sophos XG using Grafana, InfluxDB, and Prometheus. These dashboards will help you monitor your home lab effectively. Feel free to explore additional visualizations and metrics to enhance your insights, and share your dashboard creations with the community!