Add information about local tesbed with Ollama + WebUI

This commit is contained in:
nicolargo 2025-12-29 09:01:24 +01:00
parent 22e90ee9dd
commit c1bfe0b063
3 changed files with 408 additions and 0 deletions

202
mcp/HOW_TO_TEST_LOCAL.md Normal file
View File

@ -0,0 +1,202 @@
# Glances MCP Server Testing Setup
## Prerequisites
```bash
# Install Docker and Docker Compose
sudo apt update
sudo apt install docker.io docker-compose
sudo usermod -aG docker $USER
# Log out and back in for group changes to take effect
```
## Setup Steps
### 1. Start the Services
Warning: you should use docker-compose v2. If you have v1 installed, please uninstall it first.
```bash
# Save the docker-compose.yml file and run:
docker compose up -d
# Check if services are running:
docker compose ps
```
### 2. Pull an LLM Model
```bash
# Pull a recommended model (choose based on your RAM):
# For 8GB RAM - Llama 3.2 (3B parameters)
docker exec -it ollama ollama pull llama3.2
# For 16GB RAM - Llama 3.1 (8B parameters)
docker exec -it ollama ollama pull llama3.1
# For 32GB+ RAM - Llama 3.1 (70B parameters)
docker exec -it ollama ollama pull llama3.1:70b
# List available models:
docker exec -it ollama ollama list
```
### 3. Access the Services
- **Open WebUI**: http://localhost:3000
- Create an account on first visit
- The LLM will be automatically detected
- **Glances API**: http://localhost:61208
- API endpoint: http://localhost:61208/api/4/
- Web interface: http://localhost:61208
### 4. Test the Glances API
```bash
# Test basic endpoints:
curl http://localhost:61208/api/4/status
curl http://localhost:61208/api/4/pluginslist
curl http://localhost:61208/api/4/cpu
curl http://localhost:61208/api/4/mem
curl http://localhost:61208/api/4/all
```
### 5. Configure MCP Server Connection
In Open WebUI, you'll need to configure the MCP server. Here's how to test if your Glances MCP server can access the API:
**Example MCP Configuration** (adjust based on your MCP implementation):
```json
{
"mcpServers": {
"glances": {
"command": "node",
"args": ["/path/to/your/glances-mcp-server/index.js"],
"env": {
"GLANCES_API_URL": "http://host.docker.internal:61208/api/4"
}
}
}
}
```
**Note**: Use `host.docker.internal` to access services on your host machine from within Docker containers.
## Intel GPU Acceleration (Optional)
If you want to enable Intel GPU acceleration:
### 1. Install Intel GPU Drivers
```bash
# Install Intel compute runtime
sudo apt update
sudo apt install -y intel-opencl-icd intel-media-va-driver-non-free
# Verify GPU is accessible
ls -la /dev/dri
```
### 2. Enable GPU in Docker Compose
Uncomment these lines in `docker-compose.yml`:
```yaml
devices:
- /dev/dri:/dev/dri
environment:
- OLLAMA_GPU_DRIVER=intel
```
Then restart:
```bash
docker-compose down
docker-compose up -d
```
## Testing Your MCP Server
### Manual Test with cURL
```bash
# Test if your MCP server can call Glances endpoints
# Example: Get CPU stats
curl http://localhost:61208/api/4/cpu
# Expected response: JSON with CPU stats
```
### Test in Open WebUI
1. Open http://localhost:3000
2. Start a new chat
3. Try prompts like:
- "What is the current CPU usage?"
- "Show me memory statistics"
- "List all available system plugins"
## Useful Commands
```bash
# View logs
docker-compose logs -f ollama
docker-compose logs -f open-webui
docker-compose logs -f glances
# Restart services
docker-compose restart
# Stop all services
docker-compose down
# Stop and remove volumes (clean start)
docker-compose down -v
# Check Ollama models
docker exec -it ollama ollama list
# Monitor resource usage
docker stats
```
## Troubleshooting
### Ollama not responding
```bash
docker-compose restart ollama
docker exec -it ollama ollama list
```
### Glances API not accessible
```bash
# Check if Glances is running
curl http://localhost:61208/api/4/status
# View Glances logs
docker-compose logs glances
```
### Low memory issues
```bash
# Use a smaller model
docker exec -it ollama ollama pull llama3.2:1b
# Or configure Ollama to use less memory
docker-compose down
# Add to ollama service environment:
# - OLLAMA_MAX_LOADED_MODELS=1
# - OLLAMA_NUM_PARALLEL=1
docker-compose up -d
```
## Recommended Models for Your Hardware
- **4-8GB RAM**: `llama3.2:1b` or `phi3:mini`
- **8-16GB RAM**: `llama3.2` or `mistral`
- **16GB+ RAM**: `llama3.1` or `mixtral`
Choose smaller models for better responsiveness on limited hardware.

52
mcp/docker-compose.yml Normal file
View File

@ -0,0 +1,52 @@
version: '3.8'
services:
# Ollama - Local LLM Runtime
ollama:
image: ollama/ollama:latest
container_name: ollama
ports:
- "11434:11434"
volumes:
- ollama_data:/root/.ollama
restart: unless-stopped
# Uncomment below for Intel GPU support (requires Intel GPU drivers on host)
# devices:
# - /dev/dri:/dev/dri
# environment:
# - OLLAMA_GPU_DRIVER=intel
# Open WebUI - Web Interface for Ollama
open-webui:
image: ghcr.io/open-webui/open-webui:main
container_name: open-webui
ports:
- "3000:8080"
environment:
- OLLAMA_BASE_URL=http://ollama:11434
- WEBUI_SECRET_KEY=your-secret-key-change-this
volumes:
- open_webui_data:/app/backend/data
depends_on:
- ollama
restart: unless-stopped
extra_hosts:
- "host.docker.internal:host-gateway"
# Glances - System Monitoring (with API enabled)
glances:
image: nicolargo/glances:latest
container_name: glances
ports:
- "61208:61208"
environment:
- GLANCES_OPT=-w
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /etc/os-release:/etc/os-release:ro
pid: host
restart: unless-stopped
volumes:
ollama_data:
open_webui_data:

154
mcp/test_script.sh Executable file
View File

@ -0,0 +1,154 @@
#!/bin/bash
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo "=========================================="
echo " Glances MCP Server Setup Verification"
echo "=========================================="
echo ""
# Check if Docker is running
echo -n "Checking Docker... "
if docker info > /dev/null 2>&1; then
echo -e "${GREEN}${NC}"
else
echo -e "${RED}${NC}"
echo "Error: Docker is not running. Please start Docker and try again."
exit 1
fi
# Check if services are running
echo -n "Checking Ollama service... "
if docker ps | grep -q ollama; then
echo -e "${GREEN}${NC}"
else
echo -e "${RED}${NC}"
echo "Error: Ollama container is not running. Run 'docker-compose up -d'"
exit 1
fi
echo -n "Checking Open WebUI service... "
if docker ps | grep -q open-webui; then
echo -e "${GREEN}${NC}"
else
echo -e "${RED}${NC}"
echo "Warning: Open WebUI container is not running."
fi
echo -n "Checking Glances service... "
if docker ps | grep -q glances; then
echo -e "${GREEN}${NC}"
else
echo -e "${RED}${NC}"
echo "Warning: Glances container is not running."
fi
echo ""
echo "Testing API endpoints..."
echo ""
# Test Ollama
echo -n "Testing Ollama API... "
if curl -s http://localhost:11434/api/tags > /dev/null 2>&1; then
echo -e "${GREEN}${NC}"
echo " Available models:"
curl -s http://localhost:11434/api/tags | grep -o '"name":"[^"]*"' | cut -d'"' -f4 | sed 's/^/ - /'
else
echo -e "${RED}${NC}"
echo " Error: Cannot connect to Ollama API"
fi
echo ""
# Test Glances
echo -n "Testing Glances API... "
if curl -s http://localhost:61208/api/4/status > /dev/null 2>&1; then
echo -e "${GREEN}${NC}"
# Test specific endpoints
echo " Testing endpoints:"
echo -n " - /api/4/pluginslist... "
if curl -s http://localhost:61208/api/4/pluginslist | grep -q '\['; then
echo -e "${GREEN}${NC}"
else
echo -e "${RED}${NC}"
fi
echo -n " - /api/4/cpu... "
if curl -s http://localhost:61208/api/4/cpu | grep -q 'total'; then
echo -e "${GREEN}${NC}"
else
echo -e "${RED}${NC}"
fi
echo -n " - /api/4/mem... "
if curl -s http://localhost:61208/api/4/mem | grep -q 'total'; then
echo -e "${GREEN}${NC}"
else
echo -e "${RED}${NC}"
fi
else
echo -e "${RED}${NC}"
echo " Error: Cannot connect to Glances API"
fi
echo ""
# Test Open WebUI
echo -n "Testing Open WebUI... "
if curl -s http://localhost:3000 > /dev/null 2>&1; then
echo -e "${GREEN}${NC}"
else
echo -e "${RED}${NC}"
echo " Error: Cannot connect to Open WebUI"
fi
echo ""
echo "=========================================="
echo " Access URLs"
echo "=========================================="
echo "Open WebUI: http://localhost:3000"
echo "Glances Web: http://localhost:61208"
echo "Glances API: http://localhost:61208/api/4"
echo "Ollama API: http://localhost:11434"
echo ""
# Check for models
echo "=========================================="
echo " Ollama Models Status"
echo "=========================================="
if docker exec ollama ollama list > /dev/null 2>&1; then
MODEL_COUNT=$(docker exec ollama ollama list | tail -n +2 | wc -l)
if [ "$MODEL_COUNT" -eq 0 ]; then
echo -e "${YELLOW}No models installed yet.${NC}"
echo ""
echo "To install a model, run:"
echo " docker exec -it ollama ollama pull llama3.2"
else
echo -e "${GREEN}Installed models:${NC}"
docker exec ollama ollama list
fi
else
echo -e "${RED}Cannot check models${NC}"
fi
echo ""
echo "=========================================="
echo " System Resources"
echo "=========================================="
echo "Container resource usage:"
docker stats --no-stream --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}"
echo ""
echo "=========================================="
echo " Next Steps"
echo "=========================================="
echo "1. Open WebUI at http://localhost:3000"
echo "2. Create an account (stored locally)"
echo "3. If no models, install one:"
echo " docker exec -it ollama ollama pull llama3.2"
echo "4. Test the Glances API in chat:"
echo " - 'What is the current CPU usage?'"
echo " - 'Show me memory statistics'"
echo ""