Does PCF Dev show Actuator endpoints and expose log level configuration for Java app? - spring-boot

I'm running a demo Spring Boot app with an actuator enabled in pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
however the endpoints the actuator is supposed to provide (Health Checks, Traces, etc.) are not showing in the PCF Dev Apps Manager:
Is that normal behavior and they would be enabled on the public cloud deployment or am I missing something in my configuration?
Similarly, on the Logs tab I don't see a log level configuration control through which setting a log level on a particular Java package is possible. Is that the regular behavior? How to configure logging and tracing?

For logging setup , you need to add configurations in applications.properties and it is not available as separate option in the logs window. For changing your logs at run time, you need to setup a config server/environment variable and use your actuator ends point to refresh it at run time. Hope this helps.

Related

Spring boot actuator for commandline runner application

I want to enable actuator for health check in PCF for the non web or batch or commandLineRunner spring boot application.
Could some one please share some details to resolve this issue.
Please let me know if any other details required
I tried the below options
Adding actuator dependency
Adding http and jmx related properties
Since localhost:8081/actuator is not accessible could not view endpoints
How to enable url for non web app
add
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
application.properties
spring.jmx.enabled = true
management.endpoints.jmx.exposure.include=*
management.endpoints.jmx.domain=com.example.demomail
management.endpoints.jmx.unique-names=true
run jconsole find your application name then connect.
find Tab MBeans, find com.example.demomail in left tree.
As far as I understand you need to enable the Actuator endpoints.
You must add the Spring Boot Actuator dependency (as you have already done).
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Then in your application.properties file enable HTTP and JMX support (as you have already done).
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
management.endpoint.jmx.exposure.include=*
Now you will have to push your app to PCF and create a binding to a route to create access for the Actuator endpoint/s.
The URL to access the actuator endpoint will be something like this http://<route-url>/actuator/health
In the command line, I would use something like this to return a list of routes and the URL route of the application.
cf curl /v2/apps/<app-guid>/routes

Spring boot micrometer - expose metrics in an endpoint

Is it possible to expose all the Spring metrics in an rest endpoint?
In our environment Micrometer cannot forward directly the metrics to our monitoring system, then my idea was to have all the metrics exposed in a rest endpoint (or on a file, json format but the endpoint is preferable) and then having a script to fetch all the metrics at once, manipulate the payload and forward the metrics to our customized monitoring api.
If micrometer is not the right choice, what is it?
EDIT
I tried to use the actuator/prometheus endpoint. I can see the endpoint but as soon as I hit the endpoint, it hang and does not return anything:
I am using spring boot 2.2.2 and I added this dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.3.1</version>
</dependency>
application.yml
management:
endpoints:
web:
exposure:
include: health, metrics, prometheus
You could use Spring Boot's built-in prometheus endpoint. It exposes all of the Micrometer-based metrics. It's primarily intended for periodic fetching by a Prometheus server, but you could do similar in a script of your own that transforms the data to the necessary format and forwards it to your custom monitoring API.
At the level of idea you did everything right, and Micrometer is indeed the way to go here.
At the level of pom.xml definitions, you don't need to set the version:
If the version or micrometer/micrometer-prometheus module that your spring boot comes with clashes with your definitions it might not work properly.
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
Other than that, if you work only with core-micrometer (without even prometheus integration) you have metrics endpoint that also shows all the metrics in the "common" format. Prometheus shows the metrics in a format that prometheus can scrape. For your use case it seems like both ways can work but you'll have to be familiar with the formats in either way you chose.
Another thought: you say that the application can't forward to monitoring system, is it because some security constraints or because you use some kind of custom solution or something that micrometer can't integrate with?
If its not a security thing, you can consider to write your own micrometer registry that will act as a bridge between micrometer and the monitoring system.
One more thing I would like to answer on: you say that the endpoint doesn't finish.
I can only speculate, because basically there can be many reasons (one of which is clash of versions that I've referred above) - but all are bugs, it should not work like that.
Another reason reason is that you might have defined a Gauge in micrometer that in order to be calculated performs some "expensive" calculations: goes to the database that for some reason takes ages to access, calls some expensive http endpoint, etc.
When the rest endpoint gets invoked, it takes "snapshots" (the current values) of all the metering primitives, for gauges it actually invokes your custom code that can do anything, so I would have checked that.
Yet another reason might be connectivity / security configurations (the request doesn't reach actuator at all) but given the information you've presented I can't tell more than that...

How to enable actuator endpoints which are set in custom starter / library?

I have got custom starter application (library) which has actuator and prometheus dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.5.2</version>
</dependency>
in application.properties
management.endpoints.web.exposure.include=health, info, metrics, prometheus
I am using this starter in my other applications and I want to pass also this exposition of the endpoints from the starter.
Actuator and Prometheus dependecies works in applications but not show selected endpoints in starter. Ofc I can add also line with management.endpoints.web.exposure.include=health, info, metrics, prometheus to my apps but with several apps using this starter I want to pass this once for all and change endpoints only in starter if needed.
Do you have an idea how to expose those endpoints in my app which are set in starter?
Spring Boot v2.3.2 /
Maven 3.6.3
You can pass this as command line args or as ENV vars to your jar, when you start your application.
This way you can pass it to required application, as and when needed w/o updating application.properties.
It will also safeguard against exposing the actuator endpoints when not required, as actuator endpoints reveal sensitive info about the application.
eg. java -Dmanagement.endpoints.web.exposure.include=health, info, metrics, prometheus -jar myapp.jar

spring boot refresh the properties files without config server

I want to refresh the properties files in spring boot.
version - 2.1.4.RELEASE
In case of spring config server have to connect all my app to config server which i dont want as our application is in prod and we dont want a bigger change.
Is it possible in the same application i can refresh the prop file using config server if not using config server then using some spring code
can i do it.
NOT application.properties , Have a application-optional.properties outside of project want to refresh only this.
The RefreshEndpoint is provided by Spring Cloud. Adding the spring cloud starter config will get you the required beans and API to refresh.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
Additionally you will need to expose the API via management.endpoints.web.exposure.include="health,info,refresh" or you can use "*" to expose every enabled actuator endpoint to the web.

Log action in Spring Boot Admin

How to configure Spring Boot Admin to log action. For example, I want Spring Boot Admin log action when someone change log level form INFO to DEBUG or when someone change configuration value in JMX tab and write wrong configure override the existing.
Do Spring Boot Admin has a feature to do that?
No it doesn't but you could write a zuul filter intercepting, analyzing the request to /api/applications/{id}/logfile and writing a log statement.
Spring Boot includes a number of additional features to help you
monitor and manage your application when it’s pushed to production.
You can choose to manage and monitor your application using HTTP
endpoints, with JMX or even by remote shell (SSH or Telnet). Auditing,
health and metrics gathering can be automatically applied to your
application.
Actuator HTTP endpoints are only available with a Spring MVC-based
application. In particular, it will not work with Jersey unless you
enable Spring MVC as well.
You can also activate a listener by invoking the SpringApplication.addListeners(…​) method and passing the appropriate Writer object. This method also allows you to customize the file name and path via the Writer constructor.
Customize your requirement in Actuator
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready
Maven :
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <version>1.5.2.RELEASE</version>
</dependency>
http://www.baeldung.com/spring-boot-authentication-audit

Resources