Performance monitoring system for the bt_api ecosystem. Provides real-time metrics collection, exchange health monitoring, and integrations with Prometheus, Grafana, and ELK stack.
- MetricsCollector — Centralized metrics collection with global collector support
- Counter / Gauge / Histogram — Standard metric types with Prometheus naming conventions
- PerformanceTimer — High-precision timing utilities for performance profiling
@monitor_performance— Decorator for automatic performance monitoring@monitor_async_performance— Async-aware performance monitoring decorator@monitor_calls— Call count and frequency monitoring
- ExchangeHealthMonitor — Health check framework for exchange connections
- HealthCheck / HealthCheckResult — Standardized health check types
- HealthStatus — Enum for UP / DOWN / DEGRADED states
- PrometheusExporter — Push metrics to Prometheus Pushgateway
- GrafanaDashboardBuilder — Generate Grafana dashboard JSON configs
- ELKIntegration — Elasticsearch / Logstash / Kibana integration via
ElasticsearchClientandLogstashHandler
- SystemMetricsCollector — CPU, memory, disk, network usage tracking
- BusinessMetricsCollector — Custom business-level metric collection
pip install bt_api_monitoring- Python >= 3.9
- psutil >= 5.9.0
- aiohttp >= 3.9.0
- pydantic >= 2.0.0
frombt_api_monitoringimportMetricsCollector, counter, gauge, histogram# Use the global collectorcollector=MetricsCollector()
# Increment a countercounter("requests_total", tags={"endpoint": "/api/v1/ticker"}).inc()
# Set a gaugegauge("active_connections", tags={"exchange": "binance"}).set(42)
# Record a histogramhistogram("request_latency_seconds", tags={"method": "GET"}).observe(0.123)
# Start global monitoringfrombt_api_monitoringimportstart_global_monitoring, stop_global_monitoringstart_global_monitoring()
# ... your code ...stop_global_monitoring()frombt_api_monitoringimportExchangeHealthMonitor, HealthCheckFactorymonitor=ExchangeHealthMonitor()
check=HealthCheckFactory.create("binance_spot", timeout=5.0)
result=monitor.check_sync(check)
print(f"Status: {result.status}, latency: {result.latency_ms}ms")frombt_api_monitoringimportstart_prometheus_exporter, stop_prometheus_exporterstart_prometheus_exporter(port=9090)
# Metrics are now available at http://localhost:9090/metrics| Class / Function | Description |
|---|---|
MetricsCollector | Centralized metrics collector |
Counter(name, tags) | Increment-only metric |
Gauge(name, tags) | Settable metric |
Histogram(name, tags) | Distribution metric |
timer(name, tags) | Context manager for timing |
ExchangeHealthMonitor | Exchange health monitoring |
PrometheusExporter | Prometheus push gateway exporter |
GrafanaDashboardBuilder | Grafana dashboard JSON generator |
ELKIntegration | Elasticsearch/Logstash integration |
SystemMetricsCollector | System resource metrics |
Full documentation available at bt_api_py documentation.
MIT License