Skip to content

Expose local HTTP/Unix socket API for real-time monitoring stats#52

Draft
rbas with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-51
Draft

Expose local HTTP/Unix socket API for real-time monitoring stats#52
rbas with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-51

Conversation

Copilot AI commented Sep 4, 2025

Copy link
Copy Markdown
Contributor

This PR implements a comprehensive local API system that exposes real-time monitoring statistics via both HTTP and Unix socket endpoints. The implementation enables building Terminal UI (TUI) applications and web interfaces while maintaining Fluxa's lightweight architecture.

Key Features

Real-time Monitoring API:

  • /api/services - List all monitored services with comprehensive stats
  • /api/services/{id} - Get individual service details (by index or URL)
  • Available via both HTTP and Unix socket for flexible access patterns

Comprehensive Service Statistics:

  • Health status (Healthy/Unhealthy)
  • Latest response time in milliseconds
  • Timestamps for last check and next scheduled check
  • Detailed error messages from failed requests
  • Current retry attempt count for unhealthy services

Enhanced Configuration:

[fluxa]
listen = "127.0.0.1:8080"        # HTTP server (existing)
api_socket = "/tmp/fluxa.sock"   # Unix socket API (new, optional)

Implementation Details

The solution follows SOLID principles and uses idiomatic Rust patterns:

  • Shared State Management: Thread-safe Arc<RwLock<MonitoringState>> enables real-time data sharing between monitoring tasks and API server
  • Extended Model: Enhanced MonitoredService with ServiceInfo and MonitoringStats structs that serialize cleanly to JSON
  • Axum Integration: Lightweight HTTP handlers with proper error handling and status codes
  • Unix Socket Support: Platform-specific Unix domain socket server for enhanced security and local access

API Usage Examples

HTTP API:

curl http://127.0.0.1:8080/api/services
curl http://127.0.0.1:8080/api/services/0

Unix Socket API:

curl --unix-socket /tmp/fluxa.sock http://localhost/api/services
curl --unix-socket /tmp/fluxa.sock http://localhost/api/services/0

Response Format:

{
  "services": [{
    "url": "https://example.com",
    "interval_seconds": 300,
    "max_retries": 3,
    "retry_interval_seconds": 5,
    "stats": {
      "status": "Healthy",
      "last_response_time_ms": 150,
      "last_check_timestamp": 1672531200,
      "next_check_timestamp": 1672531500,
      "last_error": null,
      "current_retry_count": 0
    }
  }],
  "total_count": 1
}

Testing

Added comprehensive test coverage including:

  • Shared state management operations
  • JSON serialization/deserialization of monitoring data
  • Configuration parsing with Unix socket options
  • Service information conversion and retrieval

All existing functionality remains unchanged and backward compatible.

Fixes #51.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.pushover.net
    • Triggering command: target/debug/fluxa --config config.test.toml (dns block)
    • Triggering command: target/debug/fluxa --config demo-config.toml (dns block)
  • httpbin.org
    • Triggering command: target/debug/fluxa --config config.test.toml (dns block)
    • Triggering command: target/debug/fluxa --config demo-config.toml (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: rbas <122783+rbas@users.noreply.github.com>
Copilot AI changed the title [WIP] Expose local HTTP/Unix socket API for real-time monitoring stats Expose local HTTP/Unix socket API for real-time monitoring stats Sep 4, 2025
Copilot AI requested a review from rbas September 4, 2025 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose local HTTP/Unix socket API for real-time monitoring stats

2 participants