MagicTradeBot provides native support for integrating with Grafana Loki and Prometheus Alertmanager — powerful open-source observability tools. These enable centralized, real-time log streaming, metric collection, and alert management across all your bot instances.
🚀 Overview
MagicTradeBot core engine can forward logs and events from any bot instance to Loki for storage and querying, while Prometheus Alertmanager handles real-time alerting based on custom conditions.
Whether you are operating a single instance or managing hundreds of bot instances across various exchanges, accounts, and servers, this integration ensures you have a centralized view of all trading activities.
🔧 Key Features
- 📡 Real-time log forwarding to Grafana Loki
- 📊 Metric collection for strategies, trades, and performance
- 🚨 Rule-based alerting via Prometheus Alertmanager
- 🌐 Multi-instance and multi-server support
- 📈 Grafana dashboards for live visualization and filtering
🛠️ Prerequisites
- Grafana Loki stack deployed and running
- Prometheus server collecting metrics from bot instances
- Prometheus Alertmanager configured for notifications (e.g., Email, Slack, Webhooks)
- Bot instances configured with unique labels and log endpoints
⚙️ Configuration Steps
1. Enable Loki Logging in Bot Configuration
Edit the configuration file for each bot instance (e.g., config.yaml
or appsettings.json
):
logging:
loki:
enabled: true
endpoint: "http://your-loki-server:3100/loki/api/v1/push"
labels:
bot_instance: "bot-eu-1"
exchange: "binance"
environment: "production"
log_level: "info"
2. Enable Prometheus Metrics Export
Enable the Prometheus exporter inside each bot instance to expose metrics at a local endpoint:
metrics:
prometheus:
enabled: true
port: 9100
Prometheus will scrape metrics from http://localhost:9100/metrics
.
3. Add Bot Target to Prometheus Configuration
Edit your Prometheus prometheus.yml
to include the new bot endpoint:
scrape_configs:
- job_name: "magictradebot"
static_configs:
- targets: ["localhost:9100"]
4. Set Up Alert Rules in Prometheus
Define custom alert rules, for example:
groups:
- name: BotAlerts
rules:
- alert: HighErrorRate
expr: rate(bot_errors_total[5m]) > 5
for: 1m
labels:
severity: warning
annotations:
summary: "High error rate in MagicTradeBot"
5. Connect Alertmanager
Ensure Prometheus is connected to Alertmanager to deliver notifications via your preferred channel.
🧪 Example Loki Log Entry
{
"timestamp": "2025-06-20T09:32:10Z",
"level": "info",
"message": "Executed long trade",
"exchange": "binance",
"symbol": "ETH/USDT",
"strategy": "Breakout",
"profit": 5.12,
"bot_instance": "bot-eu-2"
}
✅ Benefits of Grafana Loki + Prometheus Integration
- 📍 Centralized observability for all bot activity
- ⚠️ Proactive alerts for error spikes, trade anomalies, or downtime
- 📊 Historical trend analysis and live dashboards in Grafana
- 🔌 Scalable for large deployments across regions or environments
- 🔍 Fast querying and log filtering by symbol, exchange, or strategy