时间:2025-05-10 12:46
人气:
作者:admin

n8n是一款基于Node.js的开源工作流自动化平台,由德国开发者Jan Oberhauser于2019年创立。其技术架构以微服务化设计为核心,通过可视化节点式工作流实现跨系统集成,技术研发聚焦于灵活性、扩展性与企业级能力。以下从技术架构、研发历程、核心优势及社区生态四方面展开分析:
一、技术架构:模块化与可扩展性
二、研发历程:从开源工具到企业级平台
三、技术优势:灵活性与可控性
四、社区与生态:开源协作与知识共享
已经帮助大家转发镜像
docker pull registry.cn-hangzhou.aliyuncs.com/megadotnet/docker.n8n.io.n8nio.n8n && docker tag registry.cn-hangzhou.aliyuncs.com/megadotnet/docker.n8n.io.n8nio.n8n docker.n8n.io/n8nio/n8n
运行
docker run -d --name n8n -e N8N_SECURE_COOKIE=false -p 5678:5678 -v /home/docker/n8n:/home/node/.n8n docker.n8n.io/n8nio/n8n
工作原理
需求
从N8N社区中找到模板,https://n8n.io/workflows/2327-host-your-own-uptime-monitoring-with-scheduled-triggers/
1. Schedule Trigger(定时触发器)
2. Get Sites(获取网站列表)
3. For Each Site...(对每个网站进行处理)
4. Perform Site Test(执行网站测试)
5. Calculate Status(计算状态)
6. Status Router(状态路由器)
7. Send Email Alert(发送邮件警报)
8. Send Chat Alert(发送聊天警报)
9. Log Uptime Event(记录正常运行时间事件)
10. Update Site Status(更新网站状态)
这个工作流通过定时检查网站状态,并在状态发生变化时发送通知,帮助用户及时了解网站的运行情况。
JSON数据
{ "meta": { "instanceId": "26ba763460b97c249b82942b23b6384876dfeb9327513332e743c5f6219c2b8e" }, "nodes": [ { "id": "acb0acd0-9bb6-4491-a1ca-4aa9a7820bbc", "name": "Schedule Trigger", "type": "n8n-nodes-base.scheduleTrigger", "position": [ 1440, 420 ], "parameters": { "rule": { "interval": [ { "field": "hours", "hoursInterval": 6 } ] } }, "typeVersion": 1.2 }, { "id": "c6bb51c4-aec4-4a6d-ade2-1080bbbb6fb3", "name": "Calculate Status", "type": "n8n-nodes-base.set", "position": [ 2367, 460 ], "parameters": { "options": {}, "assignments": { "assignments": [ { "id": "b0cbcff5-bfcf-46a5-a386-65c4dd56c42f", "name": "date", "type": "string", "value": "={{ $json.headers.date }}" }, { "id": "8c4155e4-bcc6-41dd-9582-346a57a7b997", "name": "Property", "type": "string", "value": "={{ $json.Property }}" }, { "id": "f0320678-d352-486f-a633-9980c4fc73b2", "name": "UP_FROM_UP", "type": "boolean", "value": "={{ $json.statusCode < 400 && $json.Status === 'UP' }}" }, { "id": "61783eb6-a683-44c9-aa0c-5fc5247da9fa", "name": "DOWN_FROM_DOWN", "type": "boolean", "value": "={{ $json.statusCode >= 400 && $json.Status === 'DOWN' }}" }, { "id": "1052a69e-4456-445d-bdd9-2765b334cf64", "name": "UP_FROM_DOWN", "type": "boolean", "value": "={{ $json.statusCode < 400 && $json.Status === 'DOWN' }}" }, { "id": "9af72278-5b29-406a-b4c5-f47f3d805063", "name": "DOWN_FROM_UP", "type": "boolean", "value": "={{ $json.statusCode >= 400 && $json.Status === 'UP' }}" } ] } }, "typeVersion": 3.3 }, { "id": "50307dca-fa88-4a19-91a4-456866e529d4", "name": "Get Sites", "type": "n8n-nodes-base.googleSheets", "position": [ 1700, 420 ], "parameters": { "options": {}, "sheetName": { "__rl": true, "mode": "list", "value": "gid=0", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1t2RT3lxyxXj3X1y6klWvyhEJEazpkT3Hpi2ttEJRVT4/edit#gid=0 ", "cachedResultName": "dashboard" }, "documentId": { "__rl": true, "mode": "list", "value": "1t2RT3lxyxXj3X1y6klWvyhEJEazpkT3Hpi2ttEJRVT4", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1t2RT3lxyxXj3X1y6klWvyhEJEazpkT3Hpi2ttEJRVT4/edit?usp=drivesdk ", "cachedResultName": "n8n uptime" } }, "credentials": { "googleSheetsOAuth2Api": { "id": "XHvC7jIRR8A2TlUl", "name": "Google Sheets account" } }, "typeVersion": 4.3 }, { "id": "4b0cb0cc-282b-4be9-a4ca-0c4eb10d896e", "name": "Send Chat Alert", "type": "n8n-nodes-base.slack", "position": [ 3100, 340 ], "parameters": { "text": "=From: n8n uptime\nDate: {{ $('Calculate Status').item.json[\"date\"] }}\n\n{{ $('Calculate Status').item.json.Property }} is {{ $('Calculate Status').item.json[\"DOWN_FROM_UP\"] ? 'DOWN' : 'UP' }}", "select": "channel", "channelId": { "__rl": true, "mode": "list", "value": "C06RS1WPUQ6", "cachedResultName": "general" }, "otherOptions": {} }, "credentials": { "slackApi": { "id": "VfK3js0YdqBdQLGP", "name": "Slack account" } }, "typeVersion": 2.1 }, { "id": "ab303995-bd82-4aef-8fe1-ce808c4dbd33", "name": "Send Email Alert", "type": "n8n-nodes-base.gmail", "position": [ 2940, 340 ], "parameters": { "sendTo": "no-reply@example.com", "message": "=From: n8n uptime\nDate: {{ $('Calculate Status').item.json[\"date\"] }}\n\n{{ $('Calculate Status').item.json.Property }} is {{ $('Calculate Status').item.json[\"DOWN_FROM_UP\"] ? 'DOWN' : 'UP' }}", "options": { "senderName": "n8n uptime", "appendAttribution": false }, "subject": "=n8n uptime: {{ $('Calculate Status').item.json.Property }} is {{ $('Calculate Status').item.json[\"DOWN_FROM_UP\"] ? 'DOWN' : 'UP' }}", "emailType": "text" }, "credentials": { "gmailOAuth2": { "id": "Sf5Gfl9NiFTNXFWb", "name": "Gmail account" } }, "typeVersion": 2.1 }, { "id": "63343e68-be07-4d89-8363-140299dcf0b6", "name": "Log Uptime Event", "type": "n8n-nodes-base.googleSheets", "position": [ 2940, 520 ], "parameters": { "columns": { "value": { "date": "={{ $json.date }}", "period": "={{ new Date($json.date).format(\"yyyy-MM\") }}" }, "schema": [ { "id": "period", "type": "string", "display": true, "removed": false, "required": false, "displayName": "period", "defaultMatch": false, "canBeUsedToMatch": true }, { "id": "date", "type": "string", "display": true, "required": false, "displayName": "date", "defaultMatch": false, "canBeUsedToMatch": true }, { "id": "Property", "type": "string", "display": true, "required": false, "displayName": "Property", "defaultMatch": false, "canBeUsedToMatch": true }, { "id": "UP_FROM_UP", "type": "string", "display": true, "required": false, "displayName": "UP_FROM_UP", "defaultMatch": false, "canBeUsedToMatch": true }, { "id": "DOWN_FROM_DOWN", "type": "string", "display": true, "required": false, "displayName": "DOWN_FROM_DOWN", "defaultMatch": false, "canBeUsedToMatch": true }, { "id": "UP_FROM_DOWN", "type": "string", "display": true, "required": false, "displayName": "UP_FROM_DOWN", "defaultMatch": false, "canBeUsedToMatch": true }, { "id": "DOWN_FROM_UP", "type": "string", "display": true, "required": false, "displayName": "DOWN_FROM_UP", "defaultMatch": false, "canBeUsedToMatch": true } ], "mappingMode": "defineBelow", "matchingColumns": [] }, "options": {}, "operation": "append", "sheetName": { "__rl": true, "mode": "name", "value": "={{ $('Calculate Status').item.json.Property }}" }, "documentId": { "__rl": true, "mode": "list", "value": "1t2RT3lxyxXj3X1y6klWvyhEJEazpkT3Hpi2ttEJRVT4", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1t2RT3lxyxXj3X1y6klWvyhEJEazpkT3Hpi2ttEJRVT4/edit?usp=drivesdk ", "cachedResultName": "n8n uptime" } }, "credentials": { "googleSheetsOAuth2Api": { "id": "XHvC7jIRR8A2TlUl", "name": "Google Sheets account" } }, "typeVersion": 4.3 }, { "id": "fe97a18b-902c-4fab-bf73-69b5b9e41a11", "name": "Update Site Status", "type": "n8n-nodes-base.googleSheets", "position": [ 3100, 520 ], "parameters": { "columns": { "value": { "Status": "={{ $json[\"DOWN_FROM_UP\"] || $json[\"DOWN_FROM_DOWN\"] ? 'DOWN' : 'UP' }}", "Property": "={{ $json.Property }}" }, "schema": [ { "id": "Property", "type": "string", "display": true, "removed": false, "required": false, "displayName": "Property", "defaultMatch": false, "canBeUsedToMatch": true }, { "id": "Status", "type": "string", "display": true, "required": false, "displayName": "Status", "defaultMatch": false, "canBeUsedToMatch": true } ], "mappingMode": "defineBelow", "matchingColumns": [ "Property" ] }, "options": {}, "operation": "appendOrUpdate", "sheetName": { "__rl": true, "mode": "list", "value": "gid=0", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1t2RT3lxyxXj3X1y6klWvyhEJEazpkT3Hpi2ttEJRVT4/edit#gid=0 ", "cachedResultName": "dashboard" }, "documentId": { "__rl": true, "mode": "list", "value": "1t2RT3lxyxXj3X1y6klWvyhEJEazpkT3Hpi2ttEJRVT4", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1t2RT3lxyxXj3X1y6klWvyhEJEazpkT3Hpi2ttEJRVT4/edit?usp=drivesdk ", "cachedResultName": "n8n uptime" } }, "credentials": { "googleSheetsOAuth2Api": { "id": "XHvC7jIRR8A2TlUl", "name": "Google Sheets account" } }, "typeVersion": 4.3 }, { "id": "b37537d1-eedf-446e-a5ed-2ef7388fd7bc", "name": "Perform Site Test", "type": "n8n-nodes-base.httpRequest", "position": [ 2207, 460 ], "parameters": { "url": "={{ $json.Property }}", "options": { "response": { "response": { "neverError": true, "fullResponse": true } } }, "sendHeaders": true, "headerParameters": { "parameters": [ {} ] } }, "typeVersion": 4.2 }, { "id": "22efcca8-81a8-4128-a03f-efd394e41977", "name": "For Each Site...", "type": "n8n-nodes-base.splitInBatches", "position": [ 2007, 460 ], "parameters": { "options": {} }, "typeVersion": 3 }, { "id": "b74d0b2c-8b08-42fe-a78f-103d4ea3b60f", "name": "Sticky Note3", "type": "n8n-nodes-base.stickyNote", "position": [ 1375.3365733151754, 160 ], "parameters": { "color": 7, "width": 533.3167991131336, "height": 451.46281790887826, "content": "## 1. Setting a Schedule\n[Read more about Scheduling Workflows](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.scheduletrigger/ )\n\nSince we expect downtime to be a rare occurance, our monitor should only check infrequently during the day. We'll use a schedule trigger for this purpose.\n\nOnce the schdule activates, we'll pull a list of sites to check from our google sheet." }, "typeVersion": 1 }, { "id": "6c570ff2-aa08-4458-b2da-7632d516c4e3", "name": "Sticky Note4", "type": "n8n-nodes-base.stickyNote", "position": [ 1940, 247.83581204342858 ], "parameters": { "color": 7, "width": 596.6620781418152, "height": 464.2968162619932, "content": "## 2. Perform Site Checks\n[Read more about using HTTP requests](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.httprequest/ )\n\nn8n makes it easy to communicate with external websites by offering a powerful HTTP request node which can handle GET and POST requests as well as pagination.\n\nHere, we're only interested in the status code of our requests." }, "typeVersion": 1 }, { "id": "d1f67650-1409-43b1-b197-0e5a821d8b6f", "name": "Sticky Note5", "type": "n8n-nodes-base.stickyNote", "position": [ 2580, 117.20168629145996 ], "parameters": { "color": 7, "width": 720.3351531809235, "height": 600.2604061412927, "content": "## 3. Sending Alerts and Logging Results\n[Read more about using Switch for powerful control flow](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.switch )\n\nThe switch node is powerful control flow tool that makes your workflows smart. Here, we're able to use Switch to trigger alert notifications whenever we have DOWN status or whenever we get a status change.\n\nWe store the event in our Sites Google Sheet and update the site's status which will be used to calculate our state on the next scheduled run." }, "typeVersion": 1 }, { "id": "244291de-7ce1-48c9-9d7a-c04fc7d069ab", "name": "Status Router", "type": "n8n-nodes-base.switch", "position": [ 2640, 520 ], "parameters": { "rules": { "values": [ { "outputKey": "UP_FROM_UP", "conditions": { "options": { "leftValue": "", "caseSensitive": true, "typeValidation": "strict" }, "combinator": "and", "conditions": [ { "operator": { "type": "boolean", "operation": "true", "singleValue": true }, "leftValue": "={{ $json.UP_FROM_UP }}", "rightValue": 200 } ] }, "renameOutput": true }, { "outputKey": "UP_FROM_DOWN", "conditions": { "options": { "leftValue": "", "caseSensitive": true, "typeValidation": "strict" }, "combinator": "and", "conditions": [ { "id": "f50ae8d6-4359-4163-aedb-fddf100ad676", "operator": { "type": "boolean", "operation": "true", "singleValue": true }, "leftValue": "={{ $json.UP_FROM_DOWN }}", "rightValue": 200 } ] }, "renameOutput": true }, { "outputKey": "DOWN_FROM_DOWN", "conditions": { "options": { "leftValue": "", "caseSensitive": true, "typeValidation": "strict" }, "combinator": "and", "conditions": [ { "id": "417e93d8-08b7-468d-a3bb-f0d395b3026a", "operator": { "type": "boolean", "operation": "true", "singleValue": true }, "leftValue": "={{ $json.DOWN_FROM_DOWN }}", "rightValue": "" } ] }, "renameOutput": true }, { "outputKey": "DOWN_FROM_UP", "conditions": { "options": { "leftValue": "", "caseSensitive": true, "typeValidation": "strict" }, "combinator": "and", "conditions": [ { "id": "7191e7cb-f2e1-4288-aa68-21f6efefafc5", "operator": { "type": "boolean", "operation": "true", "singleValue": true }, "leftValue": "={{ $json.DOWN_FROM_UP }}", "rightValue": "" } ] }, "renameOutput": true } ] }, "options": {} }, "typeVersion": 3 }, { "id": "a2a683fa-1fa5-4595-856a-de4f717eadf0", "name": "Sticky Note6", "type": "n8n-nodes-base.stickyNote", "position": [ 1063.07390978683, 160 ], "parameters": { "width": 276.590892958905, "height": 299.942498076894, "content": "## Try It Out!\n### Thie workflow showcases how you can build a simple website monitoring service using Scheduled Triggers and the HTTP Requests node. \n\n### Need Help?\nJoin the [Discord](https://discord.com/invite/XPKeKXeB7d ) or ask in the [Forum](https://community.n8n.io/ )!\n\nHappy Hacking!" }, "typeVersion": 1 }, { "id": "704ce21f-6b96-4dc5-a27f-fca4b326efd1", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "position": [ 1620, 380 ], "parameters": { "width": 262.6069985025353, "height": 379.4991553144906, "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### Google Sheet Required!\nYou'll need the following columns:\n* **Property** - the website address to monitor\n* **Status** - either one of \"UP\" or \"DOWN\"" }, "typeVersion": 1 } ], "pinData": {}, "connections": { "Get Sites": { "main": [ [ { "node": "For Each Site...", "type": "main", "index": 0 } ] ] }, "Status Router": { "main": [ [ { "node": "Log Uptime Event", "type": "main", "index": 0 } ], [ { "node": "Send Email Alert", "type": "main", "index": 0 }, { "node": "Log Uptime Event", "type": "main", "index": 0 } ], [ { "node": "Log Uptime Event", "type": "main", "index": 0 }, { "node": "Send Email Alert", "type": "main", "index": 0 } ], [ { "node": "Send Email Alert", "type": "main", "index": 0 }, { "node": "Log Uptime Event", "type": "main", "index": 0 } ] ] }, "Calculate Status": { "main": [ [ { "node": "Status Router", "type": "main", "index": 0 } ] ] }, "For Each Site...": { "main": [ null, [ { "node": "Perform Site Test", "type": "main", "index": 0 } ] ] }, "Log Uptime Event": { "main": [ [ { "node": "Update Site Status", "type": "main", "index": 0 } ] ] }, "Schedule Trigger": { "main": [ [ { "node": "Get Sites", "type": "main", "index": 0 } ] ] }, "Send Email Alert": { "main": [ [ { "node": "Send Chat Alert", "type": "main", "index": 0 } ] ] }, "Perform Site Test": { "main": [ [ { "node": "Calculate Status", "type": "main", "index": 0 } ] ] }, "Update Site Status": { "main": [ [ { "node": "For Each Site...", "type": "main", "index": 0 } ] ] } } }
左侧有一个“Try it Out!”区域,鼓励用户尝试这个工作流,并提供了加入Discord或论坛寻求帮助的链接。
https://n8n.io/workflows/2327-host-your-own-uptime-monitoring-with-scheduled-triggers/
n8n实现站点监控的核心优势解析
n8n作为一款开源工作流自动化平台,在站点监控场景中展现出独特的技术优势,其设计理念与功能特性深度契合了现代站点运维的复杂需求。以下从技术实现、应用场景及生态协同三个维度展开分析:
一、技术架构优势:灵活性与可控性的双重保障
n8n通过可视化节点拖拽构建监控逻辑,每个节点代表一个原子化操作(如HTTP请求、数据库查询、邮件通知)。例如,可创建“定时触发→HTTP检查→结果判断→警报通知”的完整监控链,无需编码即可实现:
n8n预置覆盖主流服务的节点库,可直接调用:
开发者可通过TypeScript/JavaScript编写专属节点,例如:
二、自动化能力:从被动响应到主动预防
三、生态协同:开源社区与第三方服务的深度整合
四、安全与成本优势:企业级监控的性价比之选
典型应用场景实践
是一个开源的Docker Compose模板,可快速搭建功能完备的本地AI和低代码开发环境。
该套件由n8n团队精心策划,将自托管的n8n平台与一系列兼容的AI产品及组件相结合,助力用户快速构建自托管AI工作流。
套件包含内容:
✅ 自托管n8n:拥有400+集成和高级AI组件的低代码平台
✅ Ollama:跨平台大型语言模型平台,支持部署运行最新本地LLM
✅ Qdrant:开源高性能向量数据库,提供全套API接口
✅ PostgreSQL:数据工程领域的核心基础设施,安全处理海量数据
中文教程
https://n8n.akashio.com/article/how-to-find-the-right-node
n8n通过其模块化架构、强大的自动化引擎与活跃的开源生态,为站点监控提供了高定制化、低成本的解决方案。无论是个人博客还是企业级应用,均可通过可视化工作流快速构建覆盖“监控→警报→恢复→分析”全链路的自动化体系,显著提升站点稳定性与运维效率。
如有想了解更多软件设计与架构, 系统IT,企业信息化, 团队管理 资讯,请关注我的微信订阅号:
作者:Petter Liu
出处:http://www.cnblogs.com/wintersun/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
该文章也同时发布在我的独立博客中-Petter Liu Blog。
下一篇:AI大模型基本原理