Nhà thông minh
Geek Playground
  • Welcome to my HomeLAB
    • Script: Thiết lập toàn bộ dịch vụ smarthome cơ bản
    • Script: Thiết lập các dịch vụ để làm media server
    • Script: Thiết lập dịch vụ theo dõi và tự động hoá
    • Docker Compose Template - Manual Setup
  • Kiến thức nền tảng - Cần biết trước khi bắt đầu
    • Bảng thống kê chi phí đầu tư thiết bị phục vụ SmartHome
    • Các phương án chơi nhà thông minh tính tới hiện tại
  • Cài đặt (Install)
    • Cài đặt HomeBridge - Đưa thiết bị lên HomeKit
    • Một HUB kết nối được toàn bộ thiết bị Zigbee của tất cả các hãng
    • Apple HomeKit - Cho thiết bị không hỗ trợ
      • Scrypted - Đưa camera lên Apple HomeKit
      • Đưa samsungTV lên Apple Home
      • Mở cửa cuốn bằng eWeLink (SonOFF) 4CH Pro
    • DIY thiết bị hỗ trợ Apple HomeKit
      • Cảm biến hiện diện bằng bất cứ thiết bị bluetooth nào (đồng hồ, xe hơi...)
      • Cảm biến hiện diện chia theo khu vực
      • Biến quạt thường thành quạt thông minh full chức năng
      • Hướng dẫn làm bộ điều khiển máy lạnh thông minh hoạt động trên Apple HomeKit và có tính năng phản hồ
  • Những dự án thú vị với HomeLAB
    • Hệ thống giải trí, xem phim tại nhà miễn phí
      • Tự động tìm kiếm phim ảnh và subtitle có trên internet
      • Tự động tải về phim yêu thích
      • Cài đặt Plex Media Server
    • Thiết lập hệ thống dashboard (theo dõi hiệu năng, tiền điện, cảm biến)
      • Hiển thị dữ liệu lên Grafana với Prometheus và InfluxDB
      • Tự động thu thập dữ liệu từ cảm biến thông qua NodeRED
      • Theo dõi sử dụng mạng
        • Sử dụng Window/MacOS/Linux
      • Theo dõi tiền điện
        • Thực tế sử dụng điện của một số thiết bị vận hành 24/7
    • Chia sẻ file trong mạng LAN, backup dữ liệu
      • Chia sẻ file trong mạng LAN - Hệ thống NAS nhà làm
      • Backup toàn bộ hệ điều hành trên Cloud, phòng trường hợp lỗi thẻ nhớ
    • Làm đẹp - trang trí không gian làm việc, giải trí
      • Cấu hình Ambilight LED cho TV, gia tăng trải nghiệm xem
      • Cài server chạy Ambilight
  • Pro Tips
    • Các lỗi thường gặp và cách xử lý
      • Sub directory not working
      • Adguard Home: Sửa lỗi fail to bind on port 53
    • Frequently used command
      • Thao tác với Caddy Proxy
      • Thao tác với ổ cứng
      • Thao tác với Docker
    • Pin thủ nhào vào đây
      • Biến sạc thường thành sạc nhanh PD
      • Tự làm bộ sạc nhiều cổng hỗ trợ PD siêu rẻ, có thể gắn lên xe máy & oto để sạc nhanh
      • Tận dụng pin cũ của điện thoại
    • Use memory card as RAM
    • Xử lý phân quyền trên linux
      • Tự động phân quyền trên linux
Powered by GitBook
On this page
  • Cài đặt
  • Cấu hình
  • Khởi tạo InfluxDB - Nơi lưu trữ dữ liệu
  • Chỉnh cấu hình prometheus - Service lấy dữ liệu
  • Cấu hình Grafana
  • Cấu hình NodeRED-Flow

Was this helpful?

Edit on GitHub
  1. Những dự án thú vị với HomeLAB
  2. Thiết lập hệ thống dashboard (theo dõi hiệu năng, tiền điện, cảm biến)

Hiển thị dữ liệu lên Grafana với Prometheus và InfluxDB

Tôi muốn theo dõi trực quan các dữ liệu thu thập từ cảm biến, tốc độ mạng hiện tại, tiền điện sử dụng hàng tháng. Tập trung tất cả trên một dashboard

Serices
Description

Node-RED

Thiết lập các automation flows, tuỳ biến thêm kịch bản mới hoặc gửi dữ liệu từ các cảm biến vào InfluxDB

InfluxDB

Chứa dữ liệu log từ Node-RED gửi về

Prometheus

Đóng vai trò trigger để collect dữ liệu từ các service lấy dữ liệu. Lưu tạm trên RAM và cho phép Grafana query trực tiếp vào để visually

Node_exporter

Đọc các chỉ số hệ thống linux (CPU, RAM, Nhiệt độ...)

SNMP_exporter

Đọc các chỉ số trên Mikrotik (tốc độ mạng, số thiết bị đang kết nối)

Grafana

Đóng vai trò visually các dữ liệu trên dưới dạng dashboard

Cài đặt

Sử dụng câu lệnh sau để cài hàng loạt: Script: Thiết lập dịch vụ theo dõi và tự động hoá

Hoặc cài đặt thủ công theo hướng dẫn:

Cấu hình Docker Compose cho tất cả dịch vụ trên

Cấu hình

Khởi tạo InfluxDB - Nơi lưu trữ dữ liệu

docker exec -it influxdb influx
CREATE DATABASE sensor_data
quit

Chỉnh cấu hình prometheus - Service lấy dữ liệu

sudo nano /mnt/sda1/Config/prometheus/prometheus.yml

File cấu hình mẫu prometheus.yml
# Sample config for Prometheus.

global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
      monitor: 'Mikrotik'

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets: ['localhost:9093']

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 10s
    scrape_timeout: 10s
    tls_config:
      insecure_skip_verify: true
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'cadvisor'
    static_configs:
    - targets: ['172.16.0.16:8082']
#     label:
#       instance: 'BPI'
    - targets: ['172.16.0.15:8082']
#     label: 
#       service: 'Pi-III'

  - job_name: 'node_exporter'
    static_configs:
     - targets: ['172.16.0.16:9100']   
#     - targets: ['192.168.88.11:9100']

  - job_name: 'adguard-exporter'
    static_configs:
     - targets: ['155.248.160.112:9617']
     - targets: ['172.16.0.16:9617']

#  - job_name: homebridge-exporter
#   static_configs:
#    - targets:
#      - homebridge-host:36123

#
  - job_name: Mikrotik
    static_configs:
      - targets:
        - 172.16.0.1 # mikrotik_ip
    metrics_path: /snmp
    params:
      module: [mikrotik]
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: mk_snmp_exporter:9116  # The SNMP exporter's real hostname:port.


Cấu hình Grafana

  1. Cấu hình source data từ Prometheus

  2. Import dashboard có sẵn hoặc tạo dashboard bằng các câu query thủ công

Một số file config cho các dashboard mình đang sử dụng

Theo dõi chỉ số cảm biến, mạng, tiền điện (tất cả trong 1)

Cấu hình NodeRED-Flow

  1. Cài thêm các Palette sau:

    • node-red-contrib-homebridge-automation

    • node-red-contrib-influxdb

PreviousThiết lập hệ thống dashboard (theo dõi hiệu năng, tiền điện, cảm biến)NextTự động thu thập dữ liệu từ cảm biến thông qua NodeRED

Last updated 7 months ago

Was this helpful?

Import Flow lấy log sensors từ Homebridge: https://raw.githubusercontent.com/leolionart/smarthome/main/Monitoring/node-red-flow.json