Skip to content

Repository files navigation

bt_api_monitoring

Python 3.9-3.14License: MIT

Performance monitoring system for the bt_api ecosystem. Provides real-time metrics collection, exchange health monitoring, and integrations with Prometheus, Grafana, and ELK stack.

Features

Core Monitoring

  • 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

Decorators

  • @monitor_performance — Decorator for automatic performance monitoring
  • @monitor_async_performance — Async-aware performance monitoring decorator
  • @monitor_calls — Call count and frequency monitoring

Exchange Health

  • ExchangeHealthMonitor — Health check framework for exchange connections
  • HealthCheck / HealthCheckResult — Standardized health check types
  • HealthStatus — Enum for UP / DOWN / DEGRADED states

Observability Integrations

  • PrometheusExporter — Push metrics to Prometheus Pushgateway
  • GrafanaDashboardBuilder — Generate Grafana dashboard JSON configs
  • ELKIntegration — Elasticsearch / Logstash / Kibana integration via ElasticsearchClient and LogstashHandler

System Metrics

  • SystemMetricsCollector — CPU, memory, disk, network usage tracking
  • BusinessMetricsCollector — Custom business-level metric collection

Installation

pip install bt_api_monitoring

Requirements

  • Python >= 3.9
  • psutil >= 5.9.0
  • aiohttp >= 3.9.0
  • pydantic >= 2.0.0

Quick Start

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()

Exchange Health Check

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")

Prometheus Export

frombt_api_monitoringimportstart_prometheus_exporter, stop_prometheus_exporterstart_prometheus_exporter(port=9090)
# Metrics are now available at http://localhost:9090/metrics

API Reference

Class / FunctionDescription
MetricsCollectorCentralized 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
ExchangeHealthMonitorExchange health monitoring
PrometheusExporterPrometheus push gateway exporter
GrafanaDashboardBuilderGrafana dashboard JSON generator
ELKIntegrationElasticsearch/Logstash integration
SystemMetricsCollectorSystem resource metrics

Documentation

Full documentation available at bt_api_py documentation.

License

MIT License

About

bt_api monitoring module - unified monitoring and metrics for cryptocurrency exchange trading APIs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages