Commit bb8adf5
feat: Implement real monitoring metrics with rate tracking and percentiles
Transform stub monitoring metrics into working implementation with real-time
calculations for queries per second, latency percentiles, and slow query detection.
**Monitoring Improvements:**
1. **Rate Tracking**
- Add RateTracker struct for calculating per-second metrics
- Implement queries_per_second calculation from atomic counters
- Implement requests_per_second for network metrics
- Track changes over time with configurable windows
2. **Percentile Tracking**
- Add PercentileTracker with efficient ring buffer (10k samples)
- Calculate p50/p95/p99 query latencies in real-time
- Convert microseconds to milliseconds for display
- Sort-based percentile calculation
3. **Slow Query Detection**
- Track slow queries with configurable threshold (default 1000ms)
- Public API for recording query latencies
- Automatic slow query counting
- Public method to configure threshold
4. **Enhanced Metrics Collection**
- queries_per_second: Real calculation (was 0.0 placeholder)
- p50_query_time_ms: Real percentile (was 0.0 placeholder)
- p95_query_time_ms: Real percentile (was 0.0 placeholder)
- p99_query_time_ms: Real percentile (was 0.0 placeholder)
- slow_queries_count: Real tracking (was 0 placeholder)
- requests_per_second: Real calculation (was 0.0 placeholder)
5. **Storage Metrics**
- WAL size tracking infrastructure (filesystem-based)
- Documentation for remaining TODOs (segment size, index size)
**Public API:**
- `record_query_latency(latency_us)`: Record query execution time
- `set_slow_query_threshold(threshold_ms)`: Configure slow query detection
**Implementation Details:**
- Rate calculations use time windows to avoid division by zero
- Percentile tracker uses VecDeque for memory efficiency
- All tracking structures are thread-safe with RwLock
- Minimal performance overhead with atomic operations
**Before:**
```rust
QueryMetrics {
queries_per_second: 0.0, // TODO: Calculate rate
p50_query_time_ms: 0.0, // TODO: Track percentiles
p95_query_time_ms: 0.0,
p99_query_time_ms: 0.0,
slow_queries_count: 0, // TODO: Track slow queries
}
```
**After:**
```rust
QueryMetrics {
queries_per_second: 1250.5, // Real value
p50_query_time_ms: 12.3, // Real p50
p95_query_time_ms: 45.2, // Real p95
p99_query_time_ms: 98.7, // Real p99
slow_queries_count: 15, // Real count
}
```
**Impact:**
- Operations teams can now monitor real performance metrics
- Slow queries are automatically detected and counted
- Percentile data enables SLA monitoring
- Rate calculations show throughput trends
**Files Changed:**
- crates/driftdb-core/src/monitoring.rs: +130 lines of implementation
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 1b1e3f1 commit bb8adf5
File tree
2 files changed
+154
-21
lines changed- .claude
- crates/driftdb-core/src
2 files changed
+154
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 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 | + | |
12 | 78 | | |
13 | 79 | | |
14 | 80 | | |
| |||
20 | 86 | | |
21 | 87 | | |
22 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
23 | 96 | | |
24 | 97 | | |
25 | 98 | | |
| |||
301 | 374 | | |
302 | 375 | | |
303 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
304 | 382 | | |
305 | 383 | | |
306 | 384 | | |
| |||
310 | 388 | | |
311 | 389 | | |
312 | 390 | | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
313 | 408 | | |
314 | 409 | | |
315 | 410 | | |
| |||
363 | 458 | | |
364 | 459 | | |
365 | 460 | | |
366 | | - | |
367 | | - | |
368 | | - | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
369 | 464 | | |
370 | 465 | | |
371 | 466 | | |
| |||
442 | 537 | | |
443 | 538 | | |
444 | 539 | | |
445 | | - | |
| 540 | + | |
446 | 541 | | |
447 | 542 | | |
448 | 543 | | |
| |||
453 | 548 | | |
454 | 549 | | |
455 | 550 | | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
456 | 564 | | |
457 | | - | |
| 565 | + | |
458 | 566 | | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
463 | 571 | | |
464 | | - | |
| 572 | + | |
465 | 573 | | |
466 | 574 | | |
467 | 575 | | |
468 | | - | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
469 | 588 | | |
470 | 589 | | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
475 | 594 | | |
476 | | - | |
| 595 | + | |
477 | 596 | | |
478 | 597 | | |
479 | 598 | | |
480 | | - | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
481 | 613 | | |
482 | 614 | | |
483 | 615 | | |
484 | 616 | | |
485 | | - | |
486 | | - | |
487 | | - | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
488 | 620 | | |
489 | 621 | | |
490 | 622 | | |
| |||
0 commit comments