المراقبة باستخدام Spring Boot Actuator
استخدم نقاط نهاية Spring Boot Actuator لمراقبة تطبيقك وإدارته وفحصه في بيئة الإنتاج.
المراقبة باستخدام Spring Boot Actuator درس مجاني في Spring Boot 4 Complete Guide على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Spring Boot 4 Complete Guide، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Spring Boot 4 Complete Guide 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Meet Spring Boot Actuator
Spring Boot Actuator is a powerful tool that helps you monitor and manage your application when it's running in production. Think of it as your app's built-in dashboard!
It provides production-ready features without requiring you to write much code.
- Monitoring: Check health, metrics, and environment details.
- Management: Log levels, shutdown, refresh context.
- Insight: Understand your app's internal workings.
Include Actuator in Your Project
To use Actuator, you just need to add its starter dependency to your project. This brings in all the necessary libraries.
For Maven, add this to your pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>Discover Actuator's Endpoints
Once Actuator is added, your application automatically exposes several "endpoints". These are HTTP URLs that provide specific information about your running app.
Some default endpoints include:
/actuator/health: Shows application health status./actuator/info: Displays general application information./actuator/metrics: Provides detailed metrics (CPU, memory, etc.).
By default, only /health and /info are exposed via web.
Run & Access Actuator
Let's create a simple Spring Boot app with Actuator. After running it, you can access the default endpoints in your browser or with a tool like curl.
Try running this and then navigate to http://localhost:8080/actuator/health.
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ActuatorDemoApplication {
public static void main(String[] args) {
SpringApplication.run(ActuatorDemoApplication.class, args);
}
}Deep Dive: The /health Endpoint
The /actuator/health endpoint is crucial for understanding your application's operational status. It aggregates information from various "health indicators".
- DiskSpace: Checks available disk space.
- DataSource: Verifies database connectivity (if configured).
- Liveness/Readiness: For Kubernetes deployments (newer versions).
It typically returns {"status": "UP"} if everything is fine, or details if something is down.
Custom Info with /info
The /actuator/info endpoint provides general information about your application. By default, it's empty, but you can easily populate it with useful details.
Add custom properties to your application.properties or application.yml:
info.app.name=MyActuatorApp
info.app.version=1.0.0
info.app.description=A demo for CoddyKitConfigure & Expose More Endpoints
By default, only /health and /info are exposed over the web. You can expose more endpoints like /beans (list all Spring beans) or /env (environment properties).
To expose all endpoints, add this to application.properties:
management.endpoints.web.exposure.include=*Monitor Performance with /metrics
The /actuator/metrics endpoint is invaluable for performance monitoring. It exposes various metrics about your application, JVM, and system.
Examples of metrics:
jvm.memory.used: Current JVM memory usage.system.cpu.usage: System CPU load.http.server.requests: Details about incoming HTTP requests.
You can query specific metrics like /actuator/metrics/jvm.memory.used for detailed data.
Build Your Own Health Checks
You can create custom health indicators to check the status of specific parts of your application, like an external service dependency or a custom cache.
Implement the HealthIndicator interface:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;
@SpringBootApplication
public class CustomHealthApp {
public static void main(String[] args) {
SpringApplication.run(CustomHealthApp.class, args);
}
}
@Component
class MyCustomHealthIndicator implements HealthIndicator {
@Override
public Health health() {
// Simulate checking an external service
boolean serviceIsUp = Math.random() > 0.5; // Randomly up or down
if (serviceIsUp) {
return Health.up().withDetail("myServiceStatus", "OK").build();
} else {
return Health.down().withDetail("myServiceStatus", "Failed").build();
}
}
}Quick Check: Actuator Endpoints
Which of the following Actuator endpoints are exposed by default over the web in a basic Spring Boot application with the Actuator dependency?
Actuator: Your App's Best Friend
Congratulations! You've learned how Spring Boot Actuator transforms your application into a production-ready, observable service.
- It provides crucial insights into your app's health and performance.
- You can easily add it with a single dependency.
- Default endpoints like
/healthand/infoare automatically available. - You can expose more endpoints and even create custom health checks.
Actuator is a must-have for any serious Spring Boot application!
الأسئلة الشائعة
هل درس «المراقبة باستخدام Spring Boot Actuator» مجاني؟
نعم — نص درس «المراقبة باستخدام Spring Boot Actuator» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Spring Boot 4 Complete Guide، انتقل إلى CoddyKit PRO. تتضمن دورة Spring Boot 4 Complete Guide 4 دروس في المجموع.
ماذا ستتعلم في «المراقبة باستخدام Spring Boot Actuator»؟
استخدم نقاط نهاية Spring Boot Actuator لمراقبة تطبيقك وإدارته وفحصه في بيئة الإنتاج. تتمرن على Spring Boot 4 Complete Guide مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Spring Boot 4 Complete Guide؟
لا تُشترط خبرة سابقة. Spring Boot 4 Complete Guide على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «المراقبة باستخدام Spring Boot Actuator»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Spring Boot 4 Complete Guide هذا؟
نعم. كل درس في Spring Boot 4 Complete Guide يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تحويل تطبيقات Spring Boot إلى حاويات Docker
- المراقبة باستخدام Spring Boot Actuator
- استراتيجيات النشر السحابي
- إنشاء مسارات CI/CD لتطبيقات Spring Boot