PM Counter Monitoring MCP Server
Enables monitoring and querying of telecom performance management (PM) counters from remote SFTP locations, providing access to interface statistics, CPU/memory utilization, BGP peer data, and system metrics through a conversational interface.
README
PM Counter Monitoring System
A comprehensive system for monitoring telecom performance monitoring (PM) counters from remote SFTP locations, storing them in a time-series database, and providing access through API endpoints and a Streamlit chat interface.
Architecture
Remote SFTP Location → Job Server (periodic fetch) → PostgreSQL Database
↓
MCP Server ← API Endpoints ← Streamlit Frontend
Components
- SFTP Client (
sftp_client.py) - Handles file downloads from remote SFTP server - Job Server (
job_server.py) - Periodically fetches and processes XML files - XML Parser (
xml_parser.py) - Parses PM counter XML files - Database (
database.py) - PostgreSQL schema and models - Data Storage (
data_storage.py) - Saves parsed data to database - API Server (
api_server.py) - FastAPI REST endpoints - MCP Server (
mcp_server.py) - Model Context Protocol server - Streamlit Frontend (
streamlit_app.py) - Chat bot interface
Quick Start with Docker (Recommended)
The easiest way to run the entire system is using Docker Compose:
Step 1: Create Environment File
Create a .env file in the project root with your configuration:
# Copy the example file
cp .env.example .env
# Edit .env and add your Groq API key (required for RAG system)
# Get your API key from: https://console.groq.com/
The .env file should include at minimum:
GROQ_API_KEY=your_groq_api_key_here
Note: The Groq API key is required for the RAG (Retrieval Augmented Generation) system to work. Without it, the system will fall back to simple pattern matching.
Step 2: Build and Start Services
# Build and start all services
make build
make up
# Or using docker-compose directly
docker-compose up -d
# Initialize database schema
make init-db
# View logs
make logs
# Access the application
# - Streamlit: http://localhost:8501
# - API: http://localhost:8000
# - MCP Server: http://localhost:8001
The Docker setup includes:
- PostgreSQL database
- SFTP server (for testing, with example XML files)
- Job server (fetches files every hour)
- API server
- MCP server
- Streamlit frontend
All services are automatically configured to work together.
Manual Setup (Without Docker)
1. Install Dependencies
pip install -r requirements.txt
2. Configure Environment
Copy .env.example to .env and update with your settings:
cp .env.example .env
Edit .env with your database, SFTP credentials, and Groq API key:
# Required for RAG system
GROQ_API_KEY=your_groq_api_key_here
# Database settings
DB_NAME=pm_counters_db
DB_USER=postgres
DB_PASSWORD=postgres
# SFTP settings
SFTP_HOST=localhost
SFTP_USERNAME=sftp_user
SFTP_PASSWORD=sftp_password
Get your Groq API key: Visit https://console.groq.com/ to create an account and generate an API key.
3. Setup Remote Location (SFTP Server)
The remote location is where your XML files are stored. You have several options:
Option A: Use Local Files for Testing (Easiest)
# Process local XML files directly (no SFTP needed)
python test_local_files.py
Option B: Set Up Local SFTP Server
See SETUP_REMOTE.md for detailed instructions on setting up a local SFTP server.
Option C: Use Existing Remote SFTP Server
Update .env with your remote SFTP server credentials:
SFTP_HOST=your-sftp-server.com
SFTP_USERNAME=your_username
SFTP_PASSWORD=your_password
SFTP_REMOTE_PATH=/path/to/xml/files
For more details, see SETUP_REMOTE.md.
4. Setup PostgreSQL Database
# Create database
createdb pm_counters_db
# Or using psql
psql -U postgres -c "CREATE DATABASE pm_counters_db;"
5. Initialize Database Schema
from database import init_db
init_db()
Or run:
python -c "from database import init_db; init_db()"
Running the System
With Docker (Recommended)
# Start all services
make up
# Or
docker-compose up -d
# View logs
make logs
# Stop all services
make down
Without Docker
1. Start Job Server
The job server fetches files from SFTP at configured intervals:
python job_server.py
2. Start API Server
python api_server.py
Or using uvicorn:
uvicorn api_server:app --host 0.0.0.0 --port 8000
3. Start MCP Server
python mcp_server.py
Or using uvicorn:
uvicorn mcp_server:app --host 0.0.0.0 --port 8001
4. Start Streamlit Frontend
streamlit run streamlit_app.py
Docker Commands
Use the Makefile for convenient commands:
make build # Build Docker images
make up # Start all services
make down # Stop all services
make restart # Restart all services
make logs # View logs from all services
make logs-job # View logs from job server only
make logs-api # View logs from API server only
make logs-streamlit # View logs from Streamlit only
make clean # Stop and remove everything (including volumes)
make init-db # Initialize database schema
make ps # Show running containers
make shell-api # Open shell in API server container
make shell-job # Open shell in job server container
Or use docker-compose directly:
docker-compose up -d # Start services
docker-compose down # Stop services
docker-compose logs -f # View logs
docker-compose exec api_server bash # Open shell
Configuration
Changing Fetch Interval
The fetch interval can be configured in two ways:
- Environment Variable: Set
FETCH_INTERVAL_HOURSin.envfile (for Docker) or environment - Docker Compose: Update
FETCH_INTERVAL_HOURSindocker-compose.ymlor.envfile
For Docker, update the environment variable and restart the job server:
# Edit .env file
FETCH_INTERVAL_HOURS=2.0
# Restart job server
docker-compose restart job_server
For non-Docker, update Config.FETCH_INTERVAL_HOURS in config.py or set environment variable.
API Endpoints
Main API (Port 8000)
GET /- API informationGET /network-elements- List all network elementsGET /interfaces/{interface_name}/counters- Get interface countersGET /system/counters- Get system countersGET /cpu/utilization- Get CPU utilizationGET /memory/utilization- Get memory utilizationGET /bgp/peers- List BGP peersGET /bgp/peers/{peer_address}/counters- Get BGP peer countersGET /files/processed- List processed filesGET /stats/summary- Get summary statistics
MCP Server (Port 8001)
POST /mcp- MCP protocol endpointGET /mcp/methods- List available MCP methods
MCP Methods:
get_interface_counters- Get interface countersget_system_counters- Get system countersget_cpu_utilization- Get CPU utilizationget_memory_utilization- Get memory utilizationget_latest_metrics- Get latest metrics summary
Streamlit Chat Interface
The Streamlit frontend provides a chat bot interface where you can ask questions like:
- "What is the current CPU utilization?"
- "Show me memory usage for the last 12 hours"
- "Get interface counters for GigabitEthernet1/0/1"
- "What are the latest metrics?"
- "Show me system statistics"
Database Schema
The system stores data in the following tables:
file_records- Track downloaded XML filesnetwork_elements- Network element informationmeasurement_intervals- Time intervals for measurementsinterface_counters- Interface performance countersip_counters- IP layer counterstcp_counters- TCP layer counterssystem_counters- System performance countersbgp_counters- BGP peer countersthreshold_alerts- Threshold alerts from XML files
Testing with Local Files
For testing without a real SFTP server, you can:
- Use the existing
example_1.xmlandexample_2.xmlfiles - Modify the job server to process local files directly
- Use a local SFTP server like
openssh-serverfor testing
Troubleshooting
- Database Connection Issues: Ensure PostgreSQL is running and credentials are correct
- SFTP Connection Issues: Verify SFTP server is accessible and credentials are correct
- API Not Responding: Check if services are running on correct ports
- No Data: Ensure job server has processed files and data is in the database
License
MIT License
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。