how to expose prometheus metrics from spring boot apps registered with spring cloud eureka server - spring-boot

I am trying to implement prometheus monitoring for spring boot apps but my spring boot apps are registered with spring cloud eureka server so I don't have an option to configure static ports for the apps in prometheus config, I can only configure scraping for eureka server like below but not for the apps registered with eureka. Can anyone please suggest?
static_configs:
- targets: ["http://mycompany.eurekaserver.net:8761"]

Came here to add new answer that, Eureka SD is supported now in Prometheus from 2.21 version onwards.
Documentation available at https://prometheus.io/docs/prometheus/latest/configuration/configuration/#eureka_sd_config
Sample configuration is available at Sample Eureka SD config

Currently eureka server has no direct integration with prometheus, so we have to use SD adapter, I would recommend below, which is working as expected without much effort.
https://github.com/twinformatics/eureka-consul-adapter

Related

Deployment of spring application on kubernetes cluster

I am going to create a kubernetes cluster to deploy all my spring boot microservices. Currently I have a spring cloud gateway server, a eureka discovery server and my back-end and front-end applications.
Do we need gateway server and discovery server if deployed on kubernetes, as these services are provided as part of cluster?
Thanks.
You are not required to use the Spring Cloud Gateway or Eureka discovery server. Kubernetes provides all basic building blocks (like Service) implemented without additional software requirements (for example with plain DNS).
If you need a more advanced setup you can integrate kubernetes API in Spring applications or use other ways to integrate. For the 90% case there is no need to do so.

Spring Boot Admin server on Cloud Foundry with SimpleDiscoveryClient

I am trying to setup a Spring Boot Admin server on a Cloud foundry. I am using the client Spring Cloud Discovery with SimpleDiscoveryClient configuration. We are not having any Thrid Party service discovery client like eureka. I can see the service getting registered to the spring boot admin server. But when i scale up any service, i see only one instance of that service and the actual number of instances are not reflected. I would like to know if that is possible without Eureka or any other service discovery, if yes how to achieve that without them.
Thanks

Turbine stream double port binding issue

I'm using Spring Boot 1.5.4 and Spring Cloud Dalston SR4 to stand up a Turbine server on Cloud Foundry and aggregate my application Hystrix streams. In addition I want to add Spring Boot Actuator monitoring and management to the Turbine server. I realize there is ample documentation on how to do this in a local environment and I do have it working locally. However it is a different matter when deploying to Cloud Foundry where I cannot use port numbers in a Url binding.
The issue is that the Turbine stream is provided by an RxNetty server on one port and the Actuator endpoints are provided by via Tomcat on another port. In Cloud Foundry I can only bind my Url to RxNetty endpoint or the Tomcat endpoint, not both.
No combination of management.port and turbine.stream.port allows me to access the turbine stream and the actuator endpoints from one host binding. The following is an example of what I would expect to be able to do:-
https://myapp.mydomain.com/info (to report actuator info details)
https://myapp.mydomain.com/turbine.stream (to stream turbine metrics)
Note: There are no port numbers in these Urls.
Requests to your app on Cloud Foundry go through the Cloud Foundry Go Router, which uses the http host header to direct traffic to all the container instances running your app. The http based gorouter expecter only one port to be opened by the app to forward http traffic to. However, the gorouter also support tcp routing which should allow you to have multiple ports open. see the docsfor an explanation of tcp vs. http routes on cloud foundry.
If you are running on Pivotal Cloud Foundry you can use the Circuit Breaker Dashboard provided by Spring Cloud Serviecs for PCF then you won't need to setup the turbine stream. The Spring Cloud Services Dashboard uses RabbitMQ instead of SSE events see SCS docs for details
Just getting back to this now. As noted by spencergibb, moving to springboot 2.0 and cloud Finchley works.

Load Balancing micro services using Spring cloud Netflix OSS

I have a microservice built using Spring Boot and Netflix OSS. I have used Central config server, Eureka and Zuul. Because of scalability multiple instances of the services is running on different port. All the instances are registered in Eureka but requests are going to only last registered server.
How to load balance services. Should I use ribbon in Zuul to load balance? Please let me know how to achieve load balancing on same service running on multiple instances.
If there is a code change required a snippet then please post a code snippet as well.
Application Config
spring.application.name=book-service
server.port=0
eureka.client.region = default
eureka.client.registryFetchIntervalSeconds = 5
eureka.client.serviceUrl.defaultZone=http://discUser:discPassword#localhost:10082/eureka/
#eureka.instance.metadataMap.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}
eureka.instance.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}
eureka.instance.leaseRenewalIntervalInSeconds=5
eureka.instance.leaseExpirationDurationInSeconds=5
Eureka Config
spring.application.name=discovery
server.port=10082
eureka.instance.hostname=localhost
eureka.client.serviceUrl.defaultZone=http://discUser:discPassword#localhost:10082/eureka/
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
spring.session.store-type=hash-map
ZUUL Config
spring.application.name=gateway
server.port=10080
eureka.client.region = default
eureka.client.registryFetchIntervalSeconds = 5
management.security.sessions=always
zuul.routes.book-service.path=/book-service/**
zuul.routes.book-service.sensitive-headers=Set-Cookie,Authorization
hystrix.command.book-service.execution.isolation.thread.timeoutInMilliseconds=600000
#zuul.routes.rating-service.path=/rating-service/**
#zuul.routes.rating-service.sensitive-headers=Set-Cookie,Authorization
#hystrix.command.rating-service.execution.isolation.thread.timeoutInMilliseconds=600000
zuul.routes.discovery.path=/discovery/**
zuul.routes.discovery.sensitive-headers=Set-Cookie,Authorization
zuul.routes.discovery.url=http://localhost:8082
hystrix.command.discovery.execution.isolation.thread.timeoutInMilliseconds=600000
logging.level.org.springframework.web.=debug
logging.level.org.springframework.security=debug
logging.level.org.springframework.cloud.netflix.zuul=debug
spring.session.store-type=hash-map
Registering application properly with Eureka will do the trick.
Below entries will uniquely register services with Eureka.
#eureka.instance.metadataMap.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}
eureka.instance.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}

Creating a Client/Service in Netflix Eureka

With regards to the Netflix Eureka Service Registry, I have setup the Eureka Netflix Server using Tomcat 8.0.35 successfully. I have also got the basic Example Service & Client to communicate with each other. I'm still new to Eureka and the management decision is to use Eureka with Spring as several new applications are written around the Spring framework.
I have been following the wiki in order to understand how the communication works (But with little to no success with registering services).. Eureka Github Wiki.
My question is: Do I need to create my own Eureka Service & Client in order to maintain a registry of about 50 cloud instances? (If so, can you please point me in the right direction).
I have hands on experience with Consul/RESTfull API, and have implemented Consul in production (using php, and qbit); however the Netflix Eureka Registry look's as though I need to learn eureka/spring + client/server java programming? I'm still getting used to the following terms.
Eureka Server (I successfully got this working using Tomcat8/JDK1.8 + the eureka.war)
Eureka Service (Some kind of stand-alone RESTfull service that queries the Eureka-Server and listens for client requests)
Eureka Client (Java snippet to be embedded into the Java servlets/jsp)?
Zuul (A type of routing/load-balancing app - similar to HaProxy ?)
Ribbon (A type of routing/load-balancing app - similar to HaProxy ?)
I would like to get the Service & Client configured for mostly non-AWS cloud instances. The Eureka Wiki is not very helpful when it comes to creating a working eureka service & client. Any help to point me in the right direction to implement a Eureka based RESTfull system would be helpful.
I suggest you to read this documentation about spring-cloud : http://cloud.spring.io/spring-cloud-static/spring-cloud.html
It should be a good start to setup a few simple spring-boot/spring-cloud services and start to use advanced tools like zuul/ribbon/hystrix ...
There is a simple example of distributed system using Spring Boot and Spring Cloud Netflix.
This project contains the following microservices:
requestor and responder which communicates via REST/HTTP
gateway microservice - Spring Boot app + Zuul
discovery microservice - Spring Boot app + Eureka
Moreover, requestor microservice uses Hystrix library.
As you can see, Spring Cloud provides a really good wrapper for Netflix solutions. As a result, you can start quickly with minimal configuration.

Resources