swf-fastmon-agent
is a fast monitoring service for the ePIC streaming workflow testbed.
This agent monitors STF (Super Time Frame) files, samples TF (Time Frame) subsets, and distributes metadata via Server-Sent Events (SSE) streaming, enabling real-time remote monitoring of ePIC data acquisition processes. The agent includes both server-side monitoring capabilities and a client for remote visualization.
The fast monitoring agent is designed as part of the SWF testbed ecosystem and integrates with:
- swf-monitor: PostgreSQL database and Django web interface for persistent monitoring data
- swf-testbed: Infrastructure orchestration and process management
- swf-common-lib: Shared utilities and BaseAgent framework for messaging
- swf-data-agent: Receiving messages when STF files are available for fast monitoring
The agent operates as a managed service within the swf-testbed ecosystem, automatically configured and monitored through the central CLI. It extends the BaseAgent class from swf-common-lib for consistent messaging and logging across the ecosystem.
- Complete SWF testbed ecosystem (swf-testbed, swf-monitor, swf-common-lib as siblings)
- Docker Desktop for infrastructure services
- Python 3.9+ virtual environment
# The agent runs as a managed service within the testbed
cd $SWF_PARENT_DIR/swf-testbed
swf-testbed status # Check if fast monitoring agent is running
# Manual development run (message-driven mode - default)
cd ../swf-fastmon-agent
export SWF_MONITOR_HTTP_URL="http://localhost:8002"
export SWF_API_TOKEN="your_api_token_here"
python -m swf_fastmon_agent.main
# Continuous monitoring mode (for testing)
cd ../swf-fastmon-agent
export FASTMON_MODE=continuous
export SWF_MONITOR_HTTP_URL="http://localhost:8002"
export SWF_API_TOKEN="your_api_token_here"
python -m swf_fastmon_agent.main
The fast monitoring agent is configured through the swf-testbed ecosystem:
- SWF_MONITOR_HTTP_URL: swf-monitor REST API base URL (default: http://localhost:8002)
- SWF_API_TOKEN: Authentication token for swf-monitor API access (required)
- FASTMON_MODE: Operation mode -
message
(default) orcontinuous
- STF File Monitoring: Monitors directories for newly created STF files
- TF Sampling: Simulates TF subsamples from STF files based on configuration
- REST API Integration: Records STF and TF metadata via swf-monitor REST API endpoints
- SSE Message Broadcasting: Distributes TF file notifications via swf-monitor's SSE streaming API
- Dual Operation Modes:
- Message-driven mode: Responds to data_ready messages from swf-data-agent
- Continuous mode: Periodically scans directories (for development/testing)
- Status Reporting: Provides health checks and performance metrics via BaseAgent
- Token-based Authentication: Secure API access using token authentication
- Real-time Display: Receives and displays TF file notifications in terminal via SSE streaming
- Statistics Tracking: Monitors per-run TF counts and data volume
- Graceful Shutdown: Handles Ctrl+C with summary statistics
- Message Filtering: Filter by message types and agent names
- Authentication: Uses API tokens for secure SSE stream access
- Configurable Connection: Supports custom monitor URLs and filtering options
- STF File Detection: Agent monitors directories for new STF files or receives data_ready messages
- TF Simulation: Generates TF subsamples from STF files based on configuration parameters
- Database Recording: Records both STF and TF metadata in swf-monitor database via REST API
- SSE Message Broadcasting: Agent sends TF file notifications to swf-monitor's
/api/messages/
endpoint - Real-time Streaming: swf-monitor broadcasts messages via SSE to connected clients at
/api/messages/stream/
- Client Display: Client receives SSE stream and displays formatted TF information in real-time
- Historical Access: All data accessible via swf-monitor Django web application
- Simplified Architecture: No ActiveMQ dependency for clients - only HTTP access required
- Better Scalability: SSE handles many concurrent read-only client connections efficiently
- Enhanced Security: API token-based authentication with fine-grained access control
- Web Integration Ready: Easy to add web-based dashboards that consume the same SSE stream
- Message Filtering: Built-in filtering by message types and agent names at the server level
- Lower Latency: Direct HTTP streaming eliminates message broker overhead
# Start the SSE client with default settings
python -m swf_fastmon_client.main start
# Connect to a specific monitor URL
python -m swf_fastmon_client.main start --monitor-url https://my-monitor.domain.com
# Filter by specific message types
python -m swf_fastmon_client.main start --message-types tf_file_registered,fastmon_status
# Filter by specific agents
python -m swf_fastmon_client.main start --agents swf-fastmon-agent
# Combined filtering
python -m swf_fastmon_client.main start --message-types tf_file_registered --agents swf-fastmon-agent
# Set up environment variables (recommended)
export SWF_MONITOR_URL="http://localhost:8002"
export SWF_API_TOKEN="your_api_token_here"
# Then start with defaults
python -m swf_fastmon_client.main start
# Check client configuration
python -m swf_fastmon_client.main status
# Show version information
python -m swf_fastmon_client.main version
# Run all testbed tests (includes fast monitoring agent)
cd $SWF_PARENT_DIR/swf-testbed
./run_all_tests.sh
# Test agent integration specifically
cd ../swf-fastmon-agent
python -m pytest src/swf_fastmon_agent/tests/
# Check agent status in testbed
swf-testbed status
# Format and lint (from swf-fastmon-agent directory)
black .
flake8 .
This library follows the ePIC streaming workflow testbed development guidelines for portability, maintainability, and consistency across the ecosystem. See CLAUDE.md
for detailed development guidelines and project-specific conventions.
Symptoms: "Auth failed" or "SSE endpoint not available" errors Solutions:
- Verify
SWF_API_TOKEN
is set and valid - Check
SWF_MONITOR_URL
points to the correct monitor instance - Ensure swf-monitor is running and SSE endpoints are enabled
- For production: Verify Apache/WSGI configuration passes Authorization headers
Symptoms: "Error sending SSE message" or API timeout errors in agent logs Solutions:
- Verify agent has valid API token with message posting permissions
- Check monitor's
/api/messages/
and/api/stf-files/
endpoints are accessible - Ensure monitor database is running and accepting connections
- Verify API field names match (e.g.,
stf_filename
notfile_url
,status='registered'
notREGISTERED
) - Check that monitor ViewSets have proper filtering configured (DjangoFilterBackend)
- Review monitor logs for 400/500 errors with detailed error messages
Symptoms: Client connects successfully but receives no messages Solutions:
- Check if agent is actually processing files and sending messages
- Verify message type filters match what agent is sending (
tf_file_registered
) - Check agent name filters match the actual agent name
- Monitor swf-monitor logs for message processing issues
Symptoms: Client receives messages but fails to parse them Solutions:
- Ensure agent uses
create_sse_tf_message()
utility function - Check message contains required fields:
msg_type
,processed_by
,timestamp
- Verify JSON formatting is correct in agent message creation
# Required for both agent and client
export SWF_MONITOR_URL="http://localhost:8002"
export SWF_API_TOKEN="your_token_here"
# Optional - for custom endpoints
export SWF_MONITOR_HTTP_URL="http://localhost:8002" # Agent API calls
# Test agent message sending (check monitor logs)
python -m swf_fastmon_agent.main
# Test client SSE reception in another terminal
python -m swf_fastmon_client.main start --message-types tf_file_registered
# Verify with curl (if SSE endpoint is accessible)
curl -H "Authorization: Token your_token" \
-H "Accept: text/event-stream" \
http://localhost:8002/api/messages/stream/