File size: 8,780 Bytes
eebf5c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
---
title: Crypto API Monitor
emoji: πŸ“Š
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 4.14.0
app_file: app_gradio.py
pinned: false
license: mit
---

# πŸ“Š Cryptocurrency API Monitor

> **Production-ready real-time health monitoring for 162+ cryptocurrency API endpoints**

A comprehensive monitoring dashboard that tracks the health, uptime, and performance of cryptocurrency APIs including block explorers, market data providers, RPC nodes, news sources, and more.

## 🌟 Features

### Core Capabilities
- **Real-Time Monitoring**: Async health checks for 162+ API endpoints
- **Multi-Tier Classification**: Critical (Tier 1), Important (Tier 2), and Others (Tier 3)
- **Persistent Storage**: SQLite database for historical metrics and incident tracking
- **Auto-Refresh**: Configurable background scheduler (1-60 minute intervals)
- **Category Organization**: Block Explorers, Market Data, RPC Nodes, News, Sentiment, etc.
- **Export Functionality**: Download status reports as CSV

### 5-Tab Interface

#### πŸ“Š Tab 1: Real-Time Dashboard
- Live status grid with color-coded health badges (πŸŸ’πŸŸ‘πŸ”΄)
- Summary cards: Total APIs, Online %, Critical Issues, Avg Response Time
- Advanced filtering: By category, status, or tier
- One-click CSV export
- Response time tracking per provider

#### πŸ“ Tab 2: Category View
- Accordion-style category breakdown
- Availability percentage per category
- Visual progress bars
- Average response time per category
- Interactive Plotly charts with dual-axis (availability + response time)

#### πŸ“ˆ Tab 3: Health History
- Uptime percentage trends (last 1-168 hours)
- Response time evolution charts
- Incident log with timestamps and severity
- Per-provider detailed history
- Automatic data retention (24-hour rolling window)

#### πŸ”§ Tab 4: Test Endpoint
- Interactive endpoint testing
- Custom endpoint override support
- CORS proxy toggle
- Example queries for each provider
- Formatted JSON responses
- Troubleshooting hints for common errors (403, 429, timeout)

#### βš™οΈ Tab 5: Configuration
- Refresh interval slider (1-60 minutes)
- Cache management controls
- Configuration statistics overview
- API key management instructions
- Scheduler status display

### Advanced Features
- **Async Architecture**: Concurrent health checks with semaphore-based rate limiting
- **Exponential Backoff**: Automatic retry logic for failed checks
- **Staggered Requests**: 0.1s delay between checks to respect rate limits
- **Caching**: 1-minute response cache to reduce API load
- **Incident Detection**: Automatic incident creation for Tier 1 outages
- **Alert System**: Database-backed alerting for critical issues
- **Data Aggregation**: Hourly response time rollups
- **Auto-Cleanup**: 7-day data retention policy

## πŸš€ Quick Start

### Local Development

```bash
# Clone repository
git clone https://github.com/nimazasinich/crypto-dt-source.git
cd crypto-dt-source

# Install dependencies
pip install -r requirements.txt

# Run the application
python app_gradio.py
```

Visit `http://localhost:7860` to access the dashboard.

### Hugging Face Spaces Deployment

1. **Create a new Space** on Hugging Face
2. **Link this GitHub repository** (Settings > Linked repositories)
3. **Set SDK to Gradio** in Space settings
4. **Configure app_file**: `app_gradio.py`
5. **Add API keys** as Space secrets (Settings > Repository secrets):
   - `ETHERSCAN_KEY`
   - `BSCSCAN_KEY`
   - `TRONSCAN_KEY`
   - `CMC_KEY` (CoinMarketCap)
   - `CRYPTOCOMPARE_KEY`
   - `NEWSAPI_KEY`

6. **Push to main branch** - Auto-deploy triggers!

## πŸ“¦ Project Structure

```
crypto-dt-source/
β”œβ”€β”€ app_gradio.py                    # Main Gradio application
β”œβ”€β”€ config.py                        # Configuration & JSON loader
β”œβ”€β”€ monitor.py                       # Async health check engine
β”œβ”€β”€ database.py                      # SQLite persistence layer
β”œβ”€β”€ scheduler.py                     # Background job scheduler
β”œβ”€β”€ requirements.txt                 # Python dependencies
β”œβ”€β”€ ultimate_crypto_pipeline_2025_NZasinich.json  # API registry
β”œβ”€β”€ all_apis_merged_2025.json       # Merged API resources
β”œβ”€β”€ data/                            # SQLite database & exports
β”‚   └── health_metrics.db
└── README_HF_SPACES.md             # This file
```

## πŸ”§ Configuration

### Environment Variables

All API keys are loaded from environment variables:

```bash
ETHERSCAN_KEY=your_key_here
BSCSCAN_KEY=your_key_here
TRONSCAN_KEY=your_key_here
CMC_KEY=your_coinmarketcap_key
CRYPTOCOMPARE_KEY=your_key_here
NEWSAPI_KEY=your_key_here
```

### Scheduler Settings

Default: 5-minute intervals
Configurable: 1-60 minutes via UI slider

### Database

- **Storage**: SQLite (`data/health_metrics.db`)
- **Tables**: status_log, response_times, incidents, alerts, configuration
- **Retention**: 7 days (configurable)
- **Fallback**: In-memory if persistent storage unavailable

## πŸ“Š API Resources Monitored

### Categories

1. **Block Explorer** (25+ APIs)
   - Etherscan, BscScan, TronScan, Blockscout, Blockchair, etc.

2. **Market Data** (15+ APIs)
   - CoinGecko, CoinMarketCap, CryptoCompare, Coinpaprika, etc.

3. **RPC Nodes** (10+ providers)
   - Infura, Alchemy, Ankr, PublicNode, QuickNode, etc.

4. **News** (5+ sources)
   - CryptoPanic, CryptoControl, NewsAPI, etc.

5. **Sentiment** (5+ APIs)
   - Alternative.me Fear & Greed, LunarCrush, Santiment, etc.

6. **Whale Tracking** (5+ services)
   - Whale Alert, ClankApp, BitQuery, Arkham, etc.

7. **On-Chain Analytics** (10+ APIs)
   - The Graph, Glassnode, Dune, Covalent, Moralis, etc.

8. **CORS Proxies** (5+ proxies)
   - AllOrigins, CORS.sh, Corsfix, ThingProxy, etc.

## 🎨 Visual Design

- **Theme**: Dark mode with crypto-inspired gradients
- **Color Scheme**: Purple/Blue primary, semantic status colors
- **Status Badges**:
  - 🟒 Green: Online (200-299 status)
  - 🟑 Yellow: Degraded (400-499 status)
  - πŸ”΄ Red: Offline (timeout or 500+ status)
  - βšͺ Gray: Unknown (not yet checked)
- **Charts**: Interactive Plotly with zoom, pan, hover details
- **Responsive**: Mobile-friendly grid layout

## πŸ”Œ API Access

### Gradio Client (Python)

```python
from gradio_client import Client

client = Client("YOUR_USERNAME/crypto-api-monitor")
result = client.predict(api_name="/status")
print(result)
```

### Direct Embedding

```html
<iframe
  src="https://YOUR_USERNAME-crypto-api-monitor.hf.space"
  width="100%"
  height="800px"
  frameborder="0"
></iframe>
```

### REST API (via Gradio)

```bash
# Get current status
curl https://YOUR_USERNAME-crypto-api-monitor.hf.space/api/status

# Get category data
curl https://YOUR_USERNAME-crypto-api-monitor.hf.space/api/category/Market%20Data
```

## πŸ“ˆ Performance

- **Concurrent Checks**: Up to 10 simultaneous API calls
- **Timeout**: 10 seconds per endpoint
- **Cache TTL**: 60 seconds
- **Stagger Delay**: 0.1 seconds between requests
- **Database**: Sub-millisecond query performance
- **UI Rendering**: <1 second for 162 providers

## πŸ›‘οΈ Error Handling

- **Graceful Degradation**: UI loads even if APIs fail
- **Connection Timeout**: 10s timeout per endpoint
- **Retry Logic**: 3 attempts with exponential backoff
- **User Notifications**: Toast messages for errors
- **Logging**: Comprehensive stdout logging for HF Spaces
- **Fallback Resources**: Minimal hardcoded set if JSON fails

## πŸ” Security

- **API Keys**: Stored as HF Spaces secrets, never in code
- **Input Validation**: Pydantic models for all inputs
- **SQL Injection**: Parameterized queries only
- **Rate Limiting**: Respects API provider limits
- **No Secrets in Logs**: Masked keys in error messages

## 🀝 Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit changes (`git commit -m 'Add amazing feature'`)
4. Push to branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## πŸ“ License

MIT License - See LICENSE file for details

## πŸ‘€ Author

**Nima Zasinich** (@NZasinich)
- GitHub: [@nimazasinich](https://github.com/nimazasinich)
- Country: Estonia (EE)
- Project: Ultimate Free Crypto Data Pipeline 2025

## πŸ™ Acknowledgments

- Built with [Gradio](https://gradio.app/) by Hugging Face
- Monitoring 162+ free and public crypto APIs
- Inspired by the crypto developer community's need for reliable data sources

## πŸ”— Links

- **Live Demo**: [Hugging Face Space](https://huggingface.co/spaces/YOUR_USERNAME/crypto-api-monitor)
- **GitHub Repo**: [crypto-dt-source](https://github.com/nimazasinich/crypto-dt-source)
- **Issues**: [Report bugs](https://github.com/nimazasinich/crypto-dt-source/issues)

---

**Built with ❀️ for the crypto dev community**