如何将Azure App Insight集成到Node-RED中?
Node-RED 集成 Azure Application Insights 完整步骤
1. 准备Azure Application Insights连接信息
从Azure门户进入你的Application Insights资源,在概述页面复制连接字符串(推荐使用,替代旧的Instrumentation Key)。
2. 配置Node-RED中的App Insights全局连接
- 打开Node-RED编辑器,点击右上角菜单 → 配置节点
- 在配置节点列表中找到
Azure Application Insights,点击添加 - 粘贴之前复制的连接字符串,为配置项命名(比如
Production App Insights),点击完成保存
3. 收集自定义指标/事件的具体实现
该插件提供了多个节点用于不同类型的数据收集,以下是常用场景的示例:
场景1:收集自定义业务指标
- 拖拽
inject节点、function节点和appinsights-track-metric节点到画布 - 在
function节点中构造指标数据,示例代码:// 构造指标对象,name为指标名称,value为数值,dimensions为维度标签 msg.metric = { name: "Order_Processing_Count", value: 1, dimensions: { region: "East US", orderType: "Premium" } }; return msg; - 将节点按
inject → function → appinsights-track-metric连接,部署后触发inject,即可向App Insights发送指标
场景2:追踪自定义业务事件
- 使用
appinsights-track-event节点,在function节点中构造事件数据:// 构造事件对象,name为事件名称,properties为事件属性,measurements为关联数值 msg.event = { name: "User_Login_Success", properties: { userId: "user_12345", loginMethod: "Azure AD" }, measurements: { loginDuration: 850 // 单位:毫秒 } }; return msg; - 部署后触发事件,可在App Insights的事件面板中查看
4. 收集Node-RED自身运行指标(可选)
如果需要监控Node-RED的运行状态,可通过定时任务收集内置运行数据:
- 添加一个
inject节点,设置为重复触发(比如每1分钟) - 配合
function节点获取Node-RED运行时信息,示例:// 获取当前活跃节点数量 const activeNodes = RED.runtime.nodes.length; msg.metric = { name: "Node-RED_Active_Nodes", value: activeNodes, dimensions: { environment: "Production" } }; return msg; - 将节点连接到
appinsights-track-metric,即可定期上报运行指标
5. 验证数据上报
登录Azure门户进入你的Application Insights资源:
- 打开日志页面,运行以下Kusto查询查看最近10分钟的数据:
union customMetrics, customEvents | where timestamp > ago(10m) | order by timestamp desc - 若能看到你发送的指标/事件,说明集成成功
内容的提问来源于stack exchange,提问作者Randi
相关产品推荐
相关产品推荐

