Homelab Monitoring Made Easy - Part 2: Creating Dashboards For Docker, Crowdsec, and Sophos XG

4 min read 1 year ago
Published on Aug 03, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

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

  1. Open the telegraph.conf file.

  2. Add the following output configuration at the bottom:

    [[outputs.influxdb]]
      url = "http://influxdb:8086"
      token = "your_generated_token"
      organization = "home"
      bucket = "home_lab"
    
  3. 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.
  4. 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

  1. Open Grafana and navigate to Data Sources.

  2. Click "Add Data Source" and select InfluxDB.

  3. Set the following configurations:

    • URL: http://influxdb:8086
    • InfluxDB Version: v2
    • Query Language: Flux
    • Authentication: Basic Auth (provide your credentials)
  4. Paste the API token generated in the previous steps.

  5. Set the Default Bucket to "home_lab."

  6. Click "Save & Test" to confirm the connection works.

Step 5: Import a Docker Dashboard in Grafana

  1. Go to Grafana's dashboard section.
  2. Click "New" and then "Import."
  3. Enter the dashboard ID (e.g., 17020 for a Docker dashboard) or paste the URL.
  4. 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

  1. Open the prometheus.yml configuration file.

  2. Add a new scrape job for CrowdSec:

    scrape_configs:
      - job_name: 'crowdsec'
        static_configs:
          - targets: ['<crowdsec_ip>:6060']
    
  3. 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

  1. In Grafana, go to Data Sources.
  2. Click "Add Data Source" and select Prometheus.
  3. Set the URL to http://prometheus:9090 and click "Save & Test."

Step 4: Import CrowdSec Dashboards

  1. Go to the CrowdSec GitHub page and copy the raw dashboard JSON.
  2. In Grafana, click "New" and then "Import."
  3. Paste the raw JSON and click "Load."
  4. Select your Prometheus data source and import the dashboard.

Chapter 3: Creating a Sophos XG Dashboard

Step 1: Enable SNMP on Sophos XG

  1. Access the Sophos XG firewall interface.
  2. Navigate to Administration > SNMP.
  3. Create a new SNMP community with a name (e.g., "sophos_XG").
  4. 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

  1. 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
    
  2. Restart the Telegraph container to apply changes.

Step 4: Create a Dashboard for Sophos XG

  1. In Grafana, create a new dashboard and select a stat panel.
  2. Use the Flux query editor to pull data from InfluxDB.
  3. 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!