可视化平台
可视化平台
本节介绍 IoT 架构中的数据可视化平台——Grafana。学习完成后,您将能够:
- 理解 Grafana 在 IoT 方案中的作用
- 掌握 Grafana 的基本概念和功能
- 创建 IoT 监控仪表板
- 向客户展示数据可视化的业务价值
什么是 Grafana?
Section titled “什么是 Grafana?”Grafana 是一个开源的数据可视化和监控平台,支持多种数据源,是 IoT 数据展示层的核心组件。
核心价值: 将复杂的 IoT 数据转换为直观的可视化仪表板
InfluxDB (数据) → Grafana (可视化) → 客户 (洞察)| 特性 | 说明 | 售前价值 |
|---|---|---|
| 多数据源 | 支持 50+ 数据源 | 统一展示所有数据 |
| 丰富图表 | 折线图、柱状图、热力图等 | 满足各种可视化需求 |
| 交互仪表板 | 拖拽式编辑,变量过滤 | 客户可自主探索数据 |
| 告警系统 | 基于阈值的告警规则 | 异常实时通知 |
| 分享能力 | 分享链接、快照、导出 | 方便团队协作 |
| 开源免费 | Apache 2.0 许可证 | 无许可成本 |
Supported Data Sources
Section titled “Supported Data Sources”核心 IoT 数据源:┌──────────────────────────────────────┐│ Grafana │├──────────────────────────────────────┤│ ├─ InfluxDB ⭐ IoT 首选 ││ ├─ Prometheus ⭐ 服务器监控 ││ ├─ MySQL/MariaDB ⭐ 业务数据 ││ ├─ PostgreSQL ⭐ 关系数据 ││ ├─ MQTT ● 实时消息 ││ ├─ Elasticsearch ● 日志分析 ││ └─ 40+ 其他数据源 ... │└──────────────────────────────────────┘Grafana Architecture
Section titled “Grafana Architecture”┌──────────────────────────────────────────────┐│ Grafana Server │├──────────────────────────────────────────────┤│ ┌────────────────┐ ┌──────────────────┐ ││ │ Dashboard UI │ │ Alert Engine │ ││ │ 仪表板编辑器 │ │ 告警引擎 │ ││ └────────────────┘ └──────────────────┘ ││ ┌────────────────┐ ┌──────────────────┐ ││ │ Data Sources │ │ User & Auth │ ││ │ 数据源管理 │ │ 用户权限管理 │ ││ └────────────────┘ └──────────────────┘ │├──────────────────────────────────────────────┤│ ┌────────────────────────────────────────┐ ││ │ Plugin System (插件系统) │ ││ └────────────────────────────────────────┘ │└──────────────────────────────────────────────┘Deployment
Section titled “Deployment”Docker Deployment
Section titled “Docker Deployment”services: grafana: image: grafana/grafana:latest container_name: grafana restart: unless-stopped ports: - "3000:3000" volumes: - ./grafana/data:/var/lib/grafana - ./grafana/provisioning:/etc/grafana/provisioning environment: - GF_SECURITY_ADMIN_USER=admin - GF_SECURITY_ADMIN_PASSWORD=admin - GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource - TZ=Asia/ShanghaiQuick Start
Section titled “Quick Start”1. First-time Login
Section titled “1. First-time Login”URL: http://<server-ip>:3000Default: admin / admin2. Add InfluxDB Data Source
Section titled “2. Add InfluxDB Data Source”// 通过 API 添加数据源curl -X POST http://admin:admin@localhost:3000/api/datasources \ -H "Content-Type: application/json" \ -d '{ "name": "InfluxDB", "type": "influxdb", "url": "http://influxdb:8086", "access": "proxy", "basicAuth": false, "jsonData": { "version": "Flux", "organization": "iot-demo", "defaultBucket": "nodered" }, "secureJsonData": { "token": "your-influxdb-token" } }'3. Create IoT Dashboard
Section titled “3. Create IoT Dashboard”模板面板 - 实时温度监控:
{ "title": "Factory Temperature Monitor", "panels": [ { "title": "Current Temperature & Humidity", "type": "stat", "datasource": "InfluxDB", "targets": [{ "query": "from(bucket: \"nodered\") |> range(start: -5m) |> filter(fn: (r) => r._measurement == \"sensor_data\") |> filter(fn: (r) => r._field == \"temperature\") |> last()" }] }, { "title": "24h Temperature Trend", "type": "timeseries", "datasource": "InfluxDB", "targets": [{ "query": "from(bucket: \"nodered\") |> range(start: -24h) |> filter(fn: (r) => r._measurement == \"sensor_data\") |> filter(fn: (r) => r._field == \"temperature\") |> aggregateWindow(every: 5m, fn: mean)" }] } ]}Example IoT Dashboards
Section titled “Example IoT Dashboards”1. Factory Environment Monitor
Section titled “1. Factory Environment Monitor”┌────────────────────────────────────────────────┐│ Factory Environment Monitor │├────────────────────────────────────────────────┤│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ││ │ Temperature│ │ Humidity │ │ Air Quality│ ││ │ 25.3°C │ │ 68.2% │ │ 42 AQI │ ││ └──────────┘ └──────────┘ └──────────┘ │├────────────────────────────────────────────────┤│ 24h Temperature Trend ││ ┌────────────────────────────────────────┐ ││ │ ╱╲ ╱╲ ╱╲ ╱╲ │ ││ │╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱╲│ ││ │ ╲╱ ╲╱ ╲╱ ╲╱ ╱ ╲│ ││ └────────────────────────────────────────┘ │├────────────────────────────────────────────────┤│ Device Status Table ││ ┌─────────┬────────┬────────┬────────┐ ││ │ Device │Status │Last Seen│Value │ ││ ├─────────┼────────┼────────┼────────┤ ││ │SENSOR-01│ ▲ Online│ 10:30 │ 25.3°C │ ││ │SENSOR-02│ ▲ Online│ 10:30 │ 24.8°C │ ││ │SENSOR-03│ ✗ Offline│ 08:15 │ -- │ ││ └─────────┴────────┴────────┴────────┘ │└────────────────────────────────────────────────┘2. Energy Monitoring Dashboard
Section titled “2. Energy Monitoring Dashboard”| Panel | Type | Data Source |
|---|---|---|
| Current Power | Stat Gauge | InfluxDB |
| Daily Energy Consumption | Bar Chart | InfluxDB |
| Voltage & Current | Time Series | InfluxDB |
| Cost Summary | Table | MariaDB |
| Device Alerts | Alert List | Prometheus |
Alert System
Section titled “Alert System”Configure Alert Rules
Section titled “Configure Alert Rules”{ "alert": { "name": "High Temperature Alert", "condition": { "type": "query", "evaluator": { "type": "gt", "params": [30] } }, "notifications": [ {"type": "email"}, {"type": "webhook"} ], "message": "Temperature exceeded 30°C at {{$value}}°C" }}Notification Channels
Section titled “Notification Channels”| 通知方式 | 配置难度 | 适用场景 |
|---|---|---|
| ⭐ 简单 | 日常告警 | |
| Slack/Teams | ⭐⭐ 中等 | 团队协作 |
| Webhook | ⭐⭐ 中等 | 自定义集成 |
| PagerDuty | ⭐⭐⭐ 较复杂 | 生产环境 |
Grafana in Customer Demo
Section titled “Grafana in Customer Demo”Demo Script
Section titled “Demo Script”-
展示实时数据
- “This dashboard shows real-time temperature data from the factory floor”
- 数据每 5 秒自动刷新
-
时间范围切换
- “Let’s look at yesterday’s data to see the temperature pattern”
- 切换到 24h 视图展示趋势
-
设备过滤
- “We can filter to see data from a specific production line”
- 使用变量过滤展示灵活性
-
告警演示
- “When temperature exceeds threshold, alerts are sent automatically”
- 展示告警规则和通知
Common Customer Questions
Section titled “Common Customer Questions”Q1: Grafana 需要额外付费吗?
Section titled “Q1: Grafana 需要额外付费吗?”A: Grafana 核心功能完全免费(Apache 2.0 许可证)。Grafana Cloud 付费版提供托管服务,但自部署版本可免费使用所有功能。
Q2: Grafana 能连接多少个数据源?
Section titled “Q2: Grafana 能连接多少个数据源?”A: 无数量限制。常见配置是连接 1-2 个 InfluxDB 实例和 1 个 MySQL 实例即可满足大多数 IoT 场景。
Q3: 仪表板可以导出分享吗?
Section titled “Q3: 仪表板可以导出分享吗?”A: 可以。Grafana 支持仪表板导出为 JSON 文件,可以导入到其他 Grafana 实例。也支持生成分享链接(需配置权限)。
✅ 推荐做法:
- 使用 Dashboard 变量实现动态过滤
- 设置合理的刷新间隔(5-30 秒)
- 配置数据源缓存减少数据库查询
- 使用告警规则实现主动监控
- 建立 Dashboard 模板库
❌ 避免做法:
- 单个仪表板放置过多面板(建议 < 20 个)
- 刷新间隔过短(< 1 秒)
- 忽略数据源查询性能
- 未设置告警避免告警风暴
Summary
Section titled “Summary”- Grafana 是 IoT 数据可视化的首选平台
- 支持 50+ 数据源,与 InfluxDB 天然集成
- 丰富的图表类型满足各种展示需求
- 内置告警系统实现主动监控
- 开源免费,适合 PoC 和生产环境