Create custom home monitoring dashboard

Create Custom Home Monitoring Dashboard

This tutorial will guide you through the process of setting up a custom home monitoring dashboard using open-source tools and technologies. This is perfect for developers and homelab enthusiasts who want to have real-time insights into their home's environment.

Hardware or Software Requirements

Step-by-Step Instructions

    • Set up your Raspberry Pi:
      • Install Raspbian OS on your Raspberry Pi.

    • Update and upgrade the system using the following commands:

      sudo apt-get update
      sudo apt-get upgrade
    • Install necessary software:
    • Install Node.js, Nginx, and PM2 (a process manager for Node.js applications) using the following commands:

      curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
      sudo apt-get install -y nodejs
      sudo apt-get install nginx
      npm install pm2 -g
    • Create a directory for your project:

      mkdir home-monitoring-dashboard
      cd home-monitoring-dashboard
    • Install and configure InfluxDB, Telegraf, and Grafana:
    • Add the InfluxDB repository key and install InfluxDB:

      curl -s https://repos.influxdata.com/influxdb.key | sudo apt-key add -
      echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
      sudo apt-get update
      sudo apt-get install influxdb
    • Start and enable InfluxDB service:

      sudo systemctl start influxdb
      sudo systemctl enable influxdb
    • Install Telegraf using the package manager:

      sudo apt-get install telegraf
    • Edit the Telegraf configuration file to include your sensors and desired data collection intervals. For example, you can add a section for each sensor type.

      [sensor_type]
        measurement = "sensor_data"
        tags = ["location"]
        interval = "10s"
    • Start and enable Telegraf service:

      sudo systemctl start telegraf
      sudo systemctl enable telegraf
    • Install Grafana using the package manager:

      sudo apt-get install grafana
    • Edit the Grafana configuration file to allow remote access if needed. You can change the `HTTP_PORT` and `ALLOWED_DOMAINS` settings.

      [http]
        bind-address = "0.0.0.0"
        http_port = "3000"
      [security]
        allowed_domains = ["*.local", "*.example.com"]
    • Start and enable Grafana service:

      sudo systemctl start grafana-server
      sudo systemctl enable grafana-server
    • Create a custom dashboard in Grafana:
      • Add panels for each sensor type you are monitoring. You can use the built-in panel types or create custom ones using the Grafana editor.

      • Configure data sources in Grafana to connect with InfluxDB. This will allow you to visualize your sensor data on the dashboard.

    • Deploy and run your application:
    • Create a simple Node.js application that fetches data from InfluxDB and serves it via an API endpoint. You can use Express.js for this purpose.

      npm init -y
      npm install express influx
    • Write the server code to interact with InfluxDB and serve JSON responses:

      const express = require('express');
      const Influx = require('influx');
      
      const app = express();
      app.use(express.json());
      
      const client = new Influx.InfluxDB({
        host: 'localhost',
        port: 8086,
        database: 'sensor_data'
      });
      
      app.get('/api/sensors', async (req, res) => {
        const result = await client.query('SELECT * FROM sensor_data');
        res.json(result.raw);
      });
      
      const PORT = process.env.PORT || 3001;
      app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
    • Run the Node.js application using PM2:

      pm2 start app.js --name "home-monitoring-api"
    • Configure Nginx to proxy requests from Grafana to your API endpoint. Edit the Nginx configuration file and add a server block for this purpose.

      server {
        listen 80;
        server_name localhost;
      
        location /api/sensors {
          proxy_pass http://127.0.0.1:3001/api/sensors;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
        }
      
        location / {
          proxy_pass http://localhost:3000;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
        }
      }
    • Restart Nginx to apply the changes:

      sudo systemctl restart nginx

      Comments