使用说明
Contoso PoC-使用Azure AI与您的数据日志对话
概述
此概念验证演示了混合云架构,其中:
- 本地模拟(东南亚地区Azure中的4个虚拟机):
- 电子商务虚拟机 --生成交易日志的简单网店(Nginx+Flask/Gunicorn)
- Zabbix虚拟机 --使用web仪表板进行基础设施监控
- Elasticsearch虚拟机 --集中式日志存储 基巴纳 web UI和 日志收集处理工具 摄入
- 流式VM --AI聊天机器人前端(Streamlit)+MCP服务器后端
- Azure云服务:AI Foundry(GPT-4o+嵌入)+AI Search支持对所有操作日志进行自然语言查询
关键演示:客户浏览Contoso商店,将商品添加到购物车,结账→ 所有事件都记录到Elasticsearch→ 可在Kibana查看→ 通过矢量嵌入与Azure AI搜索同步→ 可通过自然语言查询(“今天显示失败的付款订单”)
认证
重要:Azure订阅强制执行
disableLocalAuth=true认知服务。 所有代码使用DefaultAzureCredential(VM上的Azure管理身份,az login对于本地开发人员)。 Azure OpenAI的API密钥为 未使用 --theAZURE_OPENAI_KEY领域.env是空的。 AI搜索仍然使用管理员密钥身份验证(AI搜索支持本地身份验证)。
建筑
┌─────────────────────────────────────────────────────────────────────────┐
│ ON-PREMISES SIMULATION (4 VMs in southeastasia) │
│ │
│ ┌──────────────────┐ │
│ │ E-Commerce VM │ Nginx (port 80) → Flask/Gunicorn (port 5000) │
│ │ ecommerce-web-01 │──┐ Purchase/cart/page logs │
│ └──────────────────┘ │ │
│ │ │
│ ┌──────────────────┐ │ ┌─────────────────────────────────────┐ │
│ │ Zabbix VM │──┼─>│ Elasticsearch VM │ │
│ │ Dashboard: │ │ │ ES API: http://<es-ip>:9200 │ │
│ │ http://<ip>/ │ │ │ Kibana: http://<es-ip>:5601 │ │
│ │ zabbix │──┘ │ Logstash (:5044, HTTP input) │ │
│ │ (Admin/zabbix) │ └──────────────┬──────────────────────┘ │
│ └──────────────────┘ │ │
│ │ Bulk sync (Python) │
│ ┌────────────────────────────────────┐ │ + vector embeddings │
│ │ Streamlit VM │ │ │
│ │ MCP Server (:8080, 5 tools) │<─┘ │
│ │ Streamlit UI (:8501, chatbot) │ │
│ │ DefaultAzureCredential (MI) │ │
│ └────────────────────────────────────┘ │
│ │
└──────────────────────────────────────────┼──────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ AZURE CLOUD │
│ │
│ ┌────────────────────┐ ┌─────────────────────┐ │
│ │ Azure AI Search │<────│ Bulk Sync Service │ │
│ │ (Semantic + Vec) │ │ (Python on │ │
│ │ logs-index │ │ Streamlit VM) │ │
│ │ 1618 docs │ └─────────────────────┘ │
│ └────────┬───────────┘ │
│ │ │
│ ▼ │
│ ┌────────────────────┐ ┌─────────────────────┐ │
│ │ Azure AI Foundry │<────│ MCP Server │ │
│ │ (GPT-4o + Embed) │ │ (5 Tools, port 8080)│ │
│ │ DefaultAzureCred │ │ Streamable HTTP │ │
│ └────────────────────┘ └──────────┬──────────┘ │
│ │ │
│ ┌─────────▼──────────┐ │
│ │ Streamlit Frontend │ │
│ │ (Chat + E-Commerce │ │
│ │ Quick Actions) │ │
│ └─────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────┘
组件
| 组件 | 技术 | 目的 |
|---|---|---|
| 电子商务 | Nginx+Flask/Gunicorn(VM) | 生成购买/购物车/支付日志的简单网店 |
| 监控 | Zabbix 6.4(VM) | 基础设施指标、警报、web仪表板 |
| 日志存储 | Elasticsearch 8.x(VM) | 集中式日志存储和索引 |
| 日志UI | Kibana(在ES VM上,端口5601) | 用于日志探索的可视化Elasticsearch仪表板 |
| 摄入 | Logstash(HTTP输入→ ES)+批量同步(ES→ 带有嵌入的AI搜索) | 实时日志管道 |
| 搜索索引 | Azure AI搜索(语义+向量) | 使用语义配置对日志进行索引 my-semantic-config |
| AI模型 | Azure AI Foundry(GPT-4o+文本嵌入-ada-002) | NLU、分析和向量嵌入 |
| 后端 | MCP服务器(Python、5个工具、流式HTTP) | 编排AI搜索查询+AI Foundry分析 |
| 前端 | Streamlit(端口8501) | 用于“与日志对话”的聊天界面 |
VM设置(全部在东南亚地区)
| VM | Azure名称 | 用途 | 访问 |
|---|---|---|---|
| Elasticsearch+Kibana | vm-elasticsearch |
集中式日志+Kibana UI | ES: http://<ip>:9200 /Kibana: http://<ip>:5601 |
| Zabbix | vm-zabbix |
监控服务器+网络仪表板 | http://<ip>/zabbix (管理员/zabbix) |
| 电子商务 | vm-ecommerce |
Nginx+Flask网店 | http://<ip>/ (浏览并购买) |
| 流光灯+MCP | vm-streamlit |
AI聊天机器人+MCP后端 | Streamlit: http://<ip>:8501 /MCP: http://<ip>:8080 |
所有虚拟机:标准_B2ms、Ubuntu 22.04、SSH密钥认证、用户
tccadmin
你能看到的
1.Zabbix仪表板→ http://<zabbix-vm-ip>/zabbix
- 登录:管理员/zabbix
- 监控所有虚拟机的CPU、内存、磁盘和网络
- 查看警报、事件历史和触发器状态
2.Kibana(Elasticsearch用户界面)→ http://<es-vm-ip>:5601
- 浏览中的所有日志
infrastructure-logs索引(800+文档) - 使用 发现 浏览原始日志条目(infra+电子商务)
- 带有8个可视化效果的预构建仪表板(由自动创建)
check-health.sh)
3.电子商务商店→ http://<ecommerce-vm-ip>/
- 浏览产品目录(8个产品:电子产品,配件,家具)
- 将商品添加到购物车,输入名称,结账
- 约90%的支付成功率(10%模拟失败进行演示)
- 每个操作都会生成日志→ 弹性搜索→ 基巴纳
4.流媒体AI聊天→ http://<streamlit-vm-ip>:8501
- 自然语言查询:“显示今天所有失败的付款订单”
- 基础设施查询:“哪些服务器的CPU使用率高?”
- 用于基础设施+电子商务查询的快速操作按钮
- 由Azure AI Foundry(GPT-4o)+Azure AI搜索提供技术支持
MCP服务器工具
后端通过模型上下文协议(MCP)流式HTTP传输公开了5个工具:
| 工具 | 说明 | 数据源 |
|---|---|---|
search_infrastructure_logs |
对所有索引日志进行语义+矢量搜索 | Azure AI搜索 |
analyze_log_data |
基于GPT-4o的日志模式分析 | Azure AI Foundry |
get_recent_alerts |
查询Zabbix监控警报 | Elasticsearch(直接) |
get_ecommerce_transactions |
查询电子商务购买/购物车/支付日志 | Elasticsearch(直接) |
get_system_health_summary |
人工智能生成的健康报告(基础设施+电子商务) | 合并 |
数据摄取管道
电子商务→ 弹性搜索
Contoso Shop (Flask) → HTTP POST → Logstash (:5044) → Elasticsearch (infrastructure-logs)
弹性搜索→ Azure人工智能搜索
批量同步(主):Streamlit VM上的Python脚本轮询所有ES文档,通过Azure OpenAI生成向量嵌入(text-embedding-ada-002),并推送到Azure AI搜索 mergeOrUpload.
连续同步(可选): ingestion/sync_es_to_ai_search.py 每30秒轮询一次增量更新。
备注:Azure功能应用程序(
func-tcc-poc-ingestion)也部署了,但有一个容器重启循环。Streamlit VM上的批量同步方法是可行的解决方案。
快速开始
# 1. Deploy Azure infrastructure (4 VMs + AI services)
cd infra
chmod +x deploy.sh
./deploy.sh
# 2. Run health check (fixes NSGs, starts VMs, sets up Kibana dashboard)
cd infra
bash check-health.sh
# 3. Access services:
# - Zabbix: http://<zabbix-ip>/zabbix (Admin / zabbix)
# - Kibana: http://<es-ip>:5601 (explore logs)
# - E-Commerce: http://<ecommerce-ip>/ (browse & buy)
# - Streamlit: http://<streamlit-ip>:8501 (AI chatbot)
# - MCP Server: http://<streamlit-ip>:8080 (backend API)
# 4. (Optional) Run bulk sync to push all ES data to AI Search
ssh tccadmin@<streamlit-ip>
cd /opt/tcc
source venv/bin/activate
python ingestion/bulk_sync.py
# 5. (Optional) Run local development
pip install -r backend/requirements.txt
pip install -r frontend/requirements.txt
# Ensure az login and managed identity / RBAC is configured
python backend/mcp_server.py &
streamlit run frontend/app.py
先决条件
- Azure CLI已安装并通过身份验证(
az login) - Python 3.10+
- Azure订阅:
- Azure AI Foundry(GPT-4o+文本嵌入ada-002部署)
- Azure人工智能搜索(基本层)
- 4个Azure虚拟机(标准_B2ms)
- 管理身份:Streamlit VM必须具有系统分配的托管标识
Cognitive Services OpenAI UserAI Foundry资源中的角色 - 地区: 东南亚 (VM+AI搜索), 东亚 (AI铸造厂-GPT-4o全球标准)
文件夹结构
PoC/
├── README.md # This file
├── ARCHITECTURE.md # Detailed architecture document
├── TASKS.md # Task tracking
├── .env.example # Environment variables template
├── .env # Actual environment variables (gitignored)
├── infra/ # Azure CLI deployment scripts
│ ├── deploy.sh # Main deployment (runs all scripts)
│ ├── destroy.sh # Tear down all resources
│ ├── variables.sh # Environment variables / naming
│ ├── 01-resource-group.sh # Resource group creation
│ ├── 02-network.sh # VNet, subnets, NSGs
│ ├── 03-onprem-vms.sh # ES+Kibana, Zabbix, E-Commerce VMs
│ ├── 04-ai-search.sh # Azure AI Search + index + semantic config
│ ├── 05-ai-foundry.sh # AI Foundry (GPT-4o + Embeddings)
│ ├── 06-function-app.sh # Ingestion Function App (has restart issue)
│ ├── 07-streamlit-vm.sh # Streamlit + MCP Server VM
│ └── check-health.sh # Health check, recovery & dashboard setup
├── ecommerce-app/ # E-Commerce web application
│ ├── app.py # Flask app (products, cart, checkout)
│ ├── requirements.txt # Flask dependencies
│ ├── nginx-ecommerce.conf # Nginx reverse proxy config
│ └── ecommerce.service # systemd service unit file
├── ingestion/ # Elasticsearch → AI Search sync
│ ├── sync_es_to_ai_search.py # Continuous sync (30s polling)
│ ├── logstash.conf # Logstash config (HTTP input → ES)
│ ├── config.py # Configuration
│ └── requirements.txt # Dependencies (incl. azure-identity)
├── backend/ # MCP Server (5 tools)
│ ├── mcp_server.py # FastMCP server (Streamable HTTP)
│ ├── config.py # Configuration
│ ├── requirements.txt # Dependencies
│ └── tools/
│ ├── search_logs.py # AI Search (semantic + vector)
│ ├── analyze_logs.py # AI Foundry GPT-4o analysis
│ ├── zabbix_alerts.py # Zabbix alert query (ES direct)
│ └── ecommerce_logs.py # E-Commerce transaction query (ES direct)
├── frontend/ # Streamlit UI
│ ├── app.py # Streamlit chat app + MCP client
│ ├── config.py # Configuration
│ └── requirements.txt # Dependencies
└── sample-data/ # Sample log data for testing
├── sample_logs.json # Infrastructure + e-commerce sample logs
└── generate_logs.py # Log generator (infra + ecommerce entries)
预计成本(约330-380美元/月)
| 资源 | 成本 |
|---|---|
| 4个虚拟机(标准_B2ms) | ~240美元 |
| Azure人工智能搜索(基础) | ~70美元 |
| Azure OpenAI(GPT-4o+嵌入) | ~20-40美元 |
| 功能应用+存储 | ~1-5美元 |
健康检查和恢复(infra/check-health.sh)
一个诊断和自动修复整个环境的脚本:
bash infra/check-health.sh
| 第节 | 它的作用 |
|---|---|
| 1.NSG规则 | 检查并重新创建 AllowAllInbound 在两个NSG上(Azure策略会删除它们) |
| 2.VM电源状态 | 检测已停止的VM并发送启动命令 |
| 3.VM清单 | 列出所有具有公共/私有IP和电源状态的VM |
| 4.服务运行状况 | SSH进入每个VM,检查systemd服务,自动重启失败的服务 |
| 5.端点验证 | 在NSG修复后自动重试测试HTTP端点(ES、Kibana、Zabbix、电子商务、Streamlit、MCP) |
| 6.Zabbix凭据 | 通过API验证管理员登录,列出受监控的主机,自动注册丢失的主机(vm-ecommerce,vm-elasticsearch) |
| 7.Kibana仪表板 | 使用Kibana 8.x保存的对象API创建/重新创建8个可视化+仪表板 |
Kibana仪表板可视化:
- 日志严重性分布(圆环)、按主机列出的日志(条形图)、按服务列出的日志
- 日志时间线(行)、CPU指标(条形)、错误日志(直方图)
- 热门产品-购买量最高(酒吧),热门买家-订单量最高(甜甜圈)
已知问题
- 函数应用容器重启循环:
func-tcc-poc-ingestion成功部署,但进入启动/停止循环。绕过直接在Streamlit VM上运行批量同步。 - NSG规则:Azure策略条
AllowAllInbound定期地。跑check-health.sh自动修复。
清理
az group delete --name rg-tcc-poc --yes --no-wait