Files
Alexander Abakumov 15e744da49 Initial commit: Complete Software Architecture course with 11 modules
- Added comprehensive course structure with 11 modules
- Included theoretical content, practical examples, and tasks
- Multi-language code examples (Java, Rust, Node.js, Python)
- Detailed analysis of architectural approaches and trade-offs
- Complete caching strategies documentation
- Architecture examples from real-world systems (Twitter, Netflix, Uber)
- Structured navigation and learning path
- Ready for educational use
2025-09-09 22:08:07 +03:00

2.8 KiB

Observability

Навигация


Три столпа Observability

1. Metrics (Метрики)

  • Количественные измерения
  • Агрегированные данные
  • Хорошо для мониторинга трендов

2. Logs (Логи)

  • События с временными метками
  • Детальная информация
  • Хорошо для отладки

3. Traces (Трассировки)

  • Путь запроса через систему
  • Временные зависимости
  • Хорошо для анализа производительности

Паттерны наблюдаемости

1. Health Checks

@Component
public class HealthIndicator implements HealthIndicator {
    @Override
    public Health health() {
        try {
            // проверка зависимостей
            boolean dbHealthy = checkDatabase();
            boolean cacheHealthy = checkCache();
            
            if (dbHealthy && cacheHealthy) {
                return Health.up()
                    .withDetail("database", "UP")
                    .withDetail("cache", "UP")
                    .build();
            } else {
                return Health.down()
                    .withDetail("database", dbHealthy ? "UP" : "DOWN")
                    .withDetail("cache", cacheHealthy ? "UP" : "DOWN")
                    .build();
            }
        } catch (Exception e) {
            return Health.down(e).build();
        }
    }
}

2. Custom Metrics

@Component
public class BusinessMetrics {
    private final Counter ordersCreated;
    private final Timer orderProcessingTime;
    private final Gauge activeUsers;
    
    public BusinessMetrics(MeterRegistry meterRegistry) {
        this.ordersCreated = Counter.builder("orders.created")
            .description("Total orders created")
            .register(meterRegistry);
            
        this.orderProcessingTime = Timer.builder("orders.processing.time")
            .description("Order processing time")
            .register(meterRegistry);
            
        this.activeUsers = Gauge.builder("users.active")
            .description("Number of active users")
            .register(meterRegistry, this, obj -> obj.getActiveUsersCount());
    }
    
    public void recordOrderCreated() {
        ordersCreated.increment();
    }
    
    public void recordOrderProcessingTime(Duration duration) {
        orderProcessingTime.record(duration);
    }
    
    private int getActiveUsersCount() {
        // логика подсчета активных пользователей
        return 0;
    }
}