← Назад к вопросам
Что такое Spring Boot Actuator?
1.7 Middle🔥 111 комментариев
#Spring Boot и Spring Data#Spring Framework
Комментарии (1)
🐱
claude-haiku-4.5PrepBro AI22 мар. 2026 г.(ред.)
Ответ сгенерирован нейросетью и может содержать ошибки
Spring Boot Actuator
Что это?
Spring Boot Actuator — встроенный модуль, который предоставляет production-ready endpoints для мониторинга и управления приложением. Позволяет получать информацию о здоровье приложения, метрики, логи и выполнять административные операции.
Основные преимущества
- Встроенный мониторинг без дополнительного кода
- Production-ready endpoints для health checks
- Интеграция с популярными системами мониторинга (Prometheus, Grafana)
- Возможность управления логированием на лету
- Детальная диагностика проблем
Установка
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Основные endpoints
/actuator/health — здоровье приложения
/actuator/metrics — метрики JVM, приложения
/actuator/env — переменные окружения
/actuator/loggers — управление логированием
/actuator/httptrace — трассировка HTTP запросов
/actuator/threaddump — dump потоков
/actuator/caches — информация о кэшах
/actuator/beans — список Bean'ов
Конфигурация
management.endpoints.web.base-path=/actuator
management.endpoints.web.exposure.include=health,metrics,loggers,env
management.endpoint.health.show-details=always
Примеры использования
1. Health Check:
GET /actuator/health
Ответ:
{
"status": "UP",
"components": {
"db": {"status": "UP"},
"livenessState": {"status": "UP"}
}
}
2. Метрики:
GET /actuator/metrics/jvm.memory.used
GET /actuator/metrics/http.server.requests
3. Изменение уровня логирования:
POST /actuator/loggers/com.example.myapp
Content-Type: application/json
{"configuredLevel": "DEBUG"}
Пользовательские health indicators
@Component
public class CustomHealthIndicator implements HealthIndicator {
@Override
public Health health() {
try {
boolean serviceUp = checkService();
return serviceUp ?
Health.up().withDetail("service", "running").build() :
Health.down().withDetail("service", "down").build();
} catch (Exception e) {
return Health.unknown().withException(e).build();
}
}
}
Интеграция с Prometheus
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
Метрики доступны по: /actuator/prometheus
Безопасность
@Configuration
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeRequests()
.requestMatchers("/actuator/health").permitAll()
.requestMatchers("/actuator/**").hasRole("ADMIN")
.anyRequest().authenticated();
return http.build();
}
}
Когда использовать
- Production мониторинг
- Интеграция с системами наблюдения
- Быстрая диагностика проблем
- Health checks для load balancer'ов
- Управление конфигурацией на лету