ការតាមដាន metrics សម្រាប់ Spring microservices
សេវាកម្មស្តុក ការបញ្ជាទិញ និងរទេះទំនិញ ចុះឈ្មោះជាមួយ Eureka ទាញការកំណត់ពី Config Server ហើយបញ្ចេញ metrics តាម Micrometer ដែល Prometheus ប្រមូល និង Grafana បង្ហាញជាក្រាហ្វ។
- ប្រភេទ
- គម្រោងផ្ទាល់ខ្លួន
- ឆ្នាំ
- 2025
- ស្ថានភាព
- ដំណើរការលើម៉ាស៊ីនផ្ទាល់
- បច្ចេកវិទ្យា
ការសិក្សាករណីលម្អិតនេះមានជាភាសាអង់គ្លេសនៅឡើយ។
បញ្ហា
A small e-commerce-shaped system used to practise running several Spring services together and seeing what each of them is doing.
With six processes running, it is hard to tell which one is slow or down. The goal was one place to see request rates, latencies and JVM health for every service.
តួនាទីរបស់ខ្ញុំ
Personal project. I wrote the services, the Prometheus scrape configuration and the Grafana dashboard.
វិធីសាស្ត្រ
Every service exposes the same Actuator metrics endpoint, so adding a service to monitoring is one scrape target rather than new code. Discovery and configuration are centralised the same way, through Eureka and the Config Server.
ស្ថាបត្យកម្ម
Services pull configuration from the Config Server and register with Eureka at startup. Each exposes /actuator/prometheus; Prometheus scrapes them every 15 seconds and Grafana reads from Prometheus.
- api-gateway
- service-registry
- configserver
- inventory-service
- order-service
- cart-service
- Prometheus
- Grafana
លំហូរសំណើ
ការសម្រេចចិត្តបច្ចេកទេស
- Eureka
- Services find each other by name, so ports can change without editing every caller.
- Spring Cloud Config
- Shared configuration in one place instead of copied into each service.
- Micrometer + Actuator
- Standard JVM and HTTP metrics with no custom instrumentation code.
- Prometheus
- Pull-based scraping: a service that stops responding shows up as a failed target, not silence.
- Grafana
- Dashboards kept as JSON next to the code they describe.
ការអនុវត្ត
Each service is its own Gradle project with the Actuator and the Micrometer Prometheus registry on the runtime classpath. Scrape targets and labels are declared in Prometheus/Prometheus.yml.
Prometheus and Grafana run in Docker Compose while the Spring services run on the host and are reached through host.docker.internal.
បញ្ហាប្រឈម និងដំណោះស្រាយ
បញ្ហាប្រឈម
With six processes, it is hard to tell which one is slow or down.
ដំណោះស្រាយ
Prometheus scrapes /actuator/prometheus on every service every 15 seconds and labels each series with the application name; one Grafana dashboard reads them all.
បញ្ហាប្រឈម
Hard-coded ports break callers whenever a service moves.
ដំណោះស្រាយ
Services register with Eureka at startup and find each other by name.
បញ្ហាប្រឈម
Prometheus and Grafana run in Docker, while the services run on the host.
ដំណោះស្រាយ
Scrape targets point at host.docker.internal, so the containers can reach the host processes.
សុវត្ថិភាព និងភាពជឿជាក់
- Actuator endpoints are reachable without authentication. That is acceptable on a laptop; anywhere shared they belong on a separate management port or behind authentication.
- Grafana’s admin credentials are set in the Compose file and are for local use only.
ការធ្វើតេស្ត
Each service includes the generated context-load test. The monitoring configuration has no automated checks.
ការប្តូរយកអ្វីមួយ
ជម្រើស
Pull-based scraping every 15 seconds
តម្លៃដែលត្រូវបង់
Values are sampled, so a short-lived change between two scrapes is not recorded, and Prometheus must be able to reach every service.
ជម្រើស
Services on the host, monitoring in Docker
តម្លៃដែលត្រូវបង់
Fast to iterate on a service, but the system is not one reproducible Compose stack.
ជម្រើស
Metrics only
តម្លៃដែលត្រូវបង់
A dashboard shows that something is slow, not which call in a request chain caused it.
លទ្ធផល
A compact, reproducible example of service discovery, central configuration and metrics collection across several Spring services.
មេរៀន និងជំហានបន្ទាប់
ចំណុចខ្វះខាតដែលដឹង
- The Compose file mounts ./prometheus/prometheus.yml, but the file is committed as Prometheus/Prometheus.yml. On case-sensitive file systems such as Linux the paths must match.
- Grafana’s runtime database and plugin files are committed alongside the dashboard JSON; only the JSON needs to be versioned.
- Images use the latest tag, so a fresh pull can change behaviour.
- Metrics only — no distributed tracing or log aggregation yet.
អ្វីដែលខ្ញុំនឹងកែប្រែបន្ទាប់
- Fix the case of the Prometheus configuration path so the stack runs on Linux.
- Version only the dashboard JSON, and pin image tags.
- Add distributed tracing so a slow request can be followed across services.
គម្រោងបន្ទាប់Pipeline DevSecOps ជាមួយ Jenkins