Microservices Monitoring using Hystrix, Promethus, Graffana - vidyasekaran/current_learning GitHub Wiki
We use spring actuator, promethius deps in pom. So here the spring actuator expose performance metrics and that is converted from spring actuator format to promethius by MicroMeter act like bridge.. Micrometer can convert to any monitor tool.
https://www.youtube.com/watch?v=2wr9njNdywk
In Tamil : https://www.youtube.com/watch?v=CyxhFWzpTsM
-
https://prometheus.io/docs/prometheus/latest/getting_started/
-
cd D:\softwares\prometheus-2.22.1.windows-amd64 > double click on "prometheus.exe" and promethus starts up and listens on http://localhost:8080
-
git clone and setup in local E:\build_complete_microservices\spring-boot-micrometer-master https://github.com/Java-Techie-jt/spring-boot-micrometer
Copy prometheus.yml from prometheus software and copy it in springboot project "E:\build_complete_microservices\spring-boot-micrometer-master" and put server and port 127.0.0.1 and 9090 where prometheus server listens and also springboot server port number in -targets['127.0.01:8080']
- prometheus server listens @ 127.0.0.1 and 9090
- Our application runs at 127.0.0.1:8080
scrape_configs:
The job name is added as a label job=<job_name> to any timeseries scraped from this config.
-
job_name: 'prometheus' metrics_path defaults to '/metrics' scheme defaults to 'http'. static_configs:
- targets: ['127.0.0.1:9090']
-
job_name: 'spring-actuator' metrics_path: '/actuator/prometheus' # Promethis is going to pull the performance metric from app 127.0.0.1:8080/actuator/promethues scrape_interval: 5s static_configs:
- targets: ['127.0.0.1:8080']
-
Hit this url from postman 127.0.0.1:8080/actuator to see what end points exposed by spring actuator and you 127.0.0.1:8080/actuator/prometheus
-
start up springboot project and hit microservies multiple times @ http://localhost:8080/message
-
go to http://localhost:9090/ select any stats and see result in promethus graph.
NOTE: graffana is downloaded as msi, installed and present in C:\Program Files\GrafanaLabs\grafana\bin http://localhost:3000/login - admin/Oranges1974
- add datasource as prometheus - copy query from promethus and create a dashboard and edit it and put this query there example : "go_memstats_gc_sys_bytes" and you can see the chart.
- In the target microservice pom we need to have below deps
- Need to have promethes.yml in resource withe config
scrape_configs:
-
job_name: 'prometheus'
static_configs:
- targets: ['127.0.0.1:9090']
-
job_name: 'spring-actuator' metrics_path: '/actuator/prometheus' scrape_interval: 5s static_configs:
- targets: ['127.0.0.1:8080']
- download promethis which starts at localhost 9090.
- start up springboot project and hit microservies multiple times Example : http://localhost:8080/message
- build and start microservice and go to http://localhost:9090 to view graph.
https://www.youtube.com/watch?v=ivtIQ0wc11w
Sets to setup hystix dashboard http://www.munonye.com/microservices/hystrix-circuit-breaker-step-by-step-configuration-with-feign-client-part-4-hystrix-dashboard/
**App taken for monitoring ** Refer : https://github.com/vidyasekaran/current_learning/wiki/Hystrix-Circuit-Breaker-Pattern-%E2%80%93-Spring-Cloud We used the code in here : E:\build_complete_microservices\spring-hystrix-student-service
directly hit student service http://localhost:8098/getStudentDetailsForSchool/abcschool
To do the testing, fire up all the applications.
Visit http://localhost:8090/hystrix
You will see the Hystrix Dashboard as shown below:
Learning Promethues
https://stackabuse.com/monitoring-spring-boot-apps-with-micrometer-prometheus-and-grafana/
Micrometer To solve this problem of being a vendor-neutral data provider, Micrometer came to be. It exposes Actuator metrics to external monitoring systems such as Prometheus, Netflix Atlas, AWS Cloudwatch, and many more.
They quite correctly describe themselves as:
Think SLF4J, but for metrics.
Just as a refresher, SLF4J is a logging facade for other Java logging frameworks. SLF4J itself does not have any logging implementation. The idea is that you write code using SLF4J API's and the real implementation of it comes from the framework you choose. It could be any of the popular frameworks like log4j, logback, etc.
Similarly, Micrometer automatically exposes /actuator/metrics data into something your monitoring system can understand. All you need to do is include that vendor-specific micrometer dependency in your application.
Micrometer is a separate open-sourced project and is not in the Spring ecosystem, so we have to explicitly add it as a dependency. Since we will be using Prometheus, let's add it's specific dependency in our pom.xml: org.springframework.boot spring-boot-starter-actuator
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
This will generate a new endpoint - /actuator/prometheus. Opening it, you will see data formatted specific for Prometheus:
run app : E:\build_complete_microservices\spring-boot-micrometer-master
add in below in prometheus.yml and run below cmd to start prometheus
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
- job_name: 'spring_micrometer'
metrics_path: '/actuator/prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:8080']
Click : http://localhost:9090/targets
D:\softwares\prometheus-2.22.1.windows-amd64>prometheus --config.file=D:\softwares\prometheus-2.22.1.windows-amd64\prometheus.yml
Go to : http://localhost:9090/ and check statis and graphs