Spring Boot Actuator Cannot Show diskSpace Information - spring

I have two Spring Boot application. I've added Spring Boot Actuator both of them. When I run one of them I can see diskSpace:
{
"status": "UP",
"diskSpace": {
"status": "UP",
"total": 399055067136,
"free": 346446485504,
"threshold": 10485760
}
}
However at other service I can only see:
{
"status": "UP"
}
Even I add that property to second service:
management:
health:
diskspace:
enabled: true
I still cannot see diskSpace information. When I debug the system I see that such properties are collected but not returned to UI. What can be the problem?

Because only ADMINs are authorized to see any more info than this
{
"status": "UP"
}
To see all the metrics, authenticate with any user who has a spring security role ADMIN.
Or
(less preferable option)
Disable security for actuator endpoint like this
in application properties yaml file
management:
security:
enabled: false

In case if you are using spring security which is by default ON for actuator endpoints, you can disable it in your yml file -
management:
security:
enabled: false

management.security.enabled is deprecated now.
You can get full health details by adding a line in application.properties:
management.endpoint.health.show-details=always

Just add a line in application.properties:
management.endpoint.health.show-details = always
this made health show details to all users other than authorized people.

Spring boot actuator's HealthIndicator checks available disk space and reports a status of Status#DOWN when it drops below a configurable threshold.
so in your case for the second application the free space available is more than the threshold hence hou don't see any thing being reported.
you probably can debug and see in your code the values free disk space and the threshold.
let me know if this make sense...

Related

How to disable management endpoint probing with Spring Boot Admin?

We are running Spring Boot Admin in our k8s cluster. Applications with SBA client library are discovered during startup and SBA(server) is calling management endpoint during specified interval. We are actually interested to only probe i.e /health and /info endpoint without /actuator.
Currently SBA is calling also management endpoint /actuator.
How to configure it to run server without calling management endpoint?
We would like to disable management endpoint for security purpose.
SBA Admin & SB version 2.6.6
I tried tweaking the settings but none of them solved my issue.
/actuator is the "meta" endpoint providing information about the available actuator endpoints. But you cannot "manage" anything there. The docs call it the "discovery page".
If you activate health and info, then /actuator will tell that these are enabled and output should be something like
GET http://127.0.0.1:8100/actuator
{
"_links": {
"self": {
"href": "http://127.0.0.1:8100/actuator",
"templated": false
},
"health": {
"href": "http://127.0.0.1:8100/actuator/health",
"templated": false
},
"health-path": {
"href": "http://127.0.0.1:8100/actuator/health/{*path}",
"templated": true
},
"info": {
"href": "http://127.0.0.1:8100/actuator/info",
"templated": false
}
}
}
The SBA server uses this endpoint to know which actuators are available.
However, you can disable the endpoint in the monitored apps and everything should still work fine:
management.endpoints.web.discovery.enabled=false

Spring-Boot-Actuator Endpoint Prometheus not shown correctly

I want to show some metrics using micrometer prometheus in combination with the spring-boot-actuator. My project is totally based on spring-boot and has the actuator feature enabled and mapped on the following url: http://localhost:9000/actuator
Other endpoints are shown correctly but the http://localhost:9000/actuator/prometheus isnĀ“t. Below you find a screenshot that I get when accessing this http-endpoint.
Can anybody help me? Why is this happening and how do i fix it?
Cause normally prometheus is configured automatically for spring-boot-actuator when you provide the suitable dependency.
you need to check many things to be sure to enable Prometheus by Actuator
First thing you should put the following dependency on your pom.xml to enable Prometheus on your project.
<!-- enable prometheus-->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.10.2</version>
</dependency>
The second point you must check if the actuator exists on your
project or not if doesn't exist, you need to add the following
dependency.
<!--to enable actuator help to trace project-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
You need to add the following scripts to your application.yml to
enable the actuator and Prometheus by actuator.
.
management:
security:
enabled: false
server:
port: 9000
endpoint:
metrics:
enabled: true
prometheus:
enabled: true
health:
show-details: always
show-components: always
probes:
enabled: true
shutdown:
enabled: true
info:
env:
enabled: true
enabled: true
endpoints:
web:
exposure:
include: prometheus, metrics, info, health, shutdown, beans
using the above script the actuator will run on port 9000 and you can send a request to the following URL to access the actuator.
http://localhost:9000/actuator/prometheus
and the following URL to access Prometheus
http://localhost:9000/actuator/prometheus
Note: you must check where you are writing your script because I was confused between endpoint and endpoints
The endpoint to set the actuator config.
The endpoints to set the actuator URLs endpoint
Note: you can delete the port from application.yml and the actuator will run by current application port
best luck
This is auto-cofigured by default, here are some pointers for troubleshooting:
Check if you added micrometer-registry-prometheus (without defining the version, the version should come from the BOM)
Check if the actuator endpoint is enabled: management.endpoints.web.exposure.include=*
Check if there is a controller that maps the path of the prometheus endpoint or any of its sub-paths (/, /actuator, /actuator/prometheus)
Check if you browser tricks you curl localhost:9090/actuator/prometheus
ok i solved it with the solution:
i created a bean of type prometheusMeterRegistry manually and so spring boot didn't configure it automatically leading to no metrics provided at the prometheus endpoint
see below code snippet for further details:
// #Bean
// public PrometheusMeterRegistry prometheusMeterRegistry() {
// return new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
// }
In my case I was trying to set up prometheus on old project where was MetricsAutoConfiguration excluded. So removing exclude solved the problem.
#EnableAutoConfiguration(exclude = { MetricsAutoConfiguration.class})

Spring Boot Actuator Change the format of /health

Recently I update spring-boot-starter-actuator to 2.2.2 and when I consume the /health endpoint i got:
{
"groups": [],
"status": {
"code": "UP",
"description": ""
}
}
instead of:
{
"status": "UP"
}
And i don't have any clue the reason of this. Any idea? Or how I can refomat the output json to the original format? Not overwrite the HealthIndicator, only reformat.
Thanks in advance.
Spring Actuator 2.2 Health Endpoint JSON documentation says:
The /actuator/health endpoint has changed the resulting JSON format by
renaming details to components for the first-level elements. This
helps to differentiate the actual details returned by a
HealthIndicator from the component indicators that make up composite
health.
As a result of the change, the actuator media type has been bumped
from application/vnd.spring-boot.actuator.v2+json to
application/vnd.spring-boot.actuator.v3+json. If you have tools that
need to consume the older format, you can use an HTTP Accept: header
with the V2 media type, application/vnd.spring-boot.actuator.v2+json.
In addition if you want to see all documentation related to health and what is groups ? how to custom the health indicator take a look the
Current Health Information

How to create more than one health check endpoints with Spring Boot Actuator

What I want to do
Create two (different) endpoints using Spring Boot Actuator
My environment
Spring Boot 1.4.2
spring-boot-starter-actuator embedded in Spring Boot 1.4.2
Detail
I'm creating a Web app using Spring Boot and will need to create two separated endpoints: one for just checking application health including the app's DB connection and so on (This will be realized by the default behavior of "/health") and the other for just checking if the app is ready for accepting HTTP requests (say "/httpcheck").
To implement health check feature, I guess it's the fastest way to use Spring Boot Actuator (by default, /health is mapped to health check endpoint).
I also understand we can configure this endpoint by extending AbstractHealthIndicator (so that it will include DB health check).
But as far as I could see, I could not find a way to create more than one endpoints to do different health checks.
Do you have any ideas?
Thanks in advance.
Thanks for your answer.
Actually, I dealt with this problem by implementing a new endpoint (/httpcheck) to simply check if its HTTP stack works well or not.
HttpCheckEndpoint.java
#Component
#ConfigurationProperties(prefix = "endpoints.httpcheck") // Specifies the prefix on application.yml
public class HttpCheckEndpoint extends AbstractMvcEndpoint {
public HttpCheckEndpoint() {
super("/httpcheck", false);
}
/**
* Check if simply the app can connect to their own HTTP stack and return 200 OK.
* <ul>
* <li>Method: GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS</li>
* <li>Endpoint: "/httpcheck"</li>
* </ul>
*/
#RequestMapping
#ResponseBody
public ResponseEntity<String> checkHttpConnecton() {
if (!isEnabled()) {
return new ResponseEntity<String>("", HttpStatus.NOT_FOUND);
} else {
return new ResponseEntity<String>("{\"status\": \"UP\"}", HttpStatus.OK);
}
}
}
application.yml
endpoints:
enabled: false # Default enabled/disabled on endpoints on Spring Boot Actuator
health: # Health check (already prepared in Spring Boot Actuator)
enabled: true
httpcheck: # Simple HTTP connection check (newly created by myself)
enabled: true
I've confirmed it worked well, although not sure if it's the best solution...
Solution
You can use Jolokia end points in your Spring-boot application and get it registered with o.s.b.a.e.jmx.EndpointMBeanExporter along with your Actuator Plugins.
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
<version>1.2.2</version>
</dependency>
Jolokia Configurations in application.properties
jolokia.config.debug=true
endpoints.jolokia.enabled=true

How to store application.properites values using manifest.yml to contain passwords?

So my application.properties would look like:
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=mydb
spring.datasource.username=user
spring.datasource.password=123456
spring.jpa.database-platform=org.hibernate.dialect.SQLServer2012Dialect
I don't want others to be able to see my user and password when they go into my application.properties file.
Is there an alternative way to push values to cloud foundry? Something like manifest.yml?
Attempt to create manifest.yml
I tried to make a manifest file so I can bind it with my application on cloud foundry.
VCAP_SERVICES =
{
"oraclesql": [
{
"name": "OrcaleDb",
"label": "oraclesql",
"tags": [
"oracledb",
"oracle",
"relational"
],
"plan": "free",
"credentials": {
"uri": "jdbc:sqlserver://localhost:1433;databaseName=mydb",
"username": "user",
"password": "123456"
}
}
]
}
Created application.yml
//this works
spring:
application:
name: tester
datasource:
driverClassName: jdbc:sqlserver://localhost:1433;databaseName=mydb
username: user
password: 123456
initialize: false
jpa:
databasePlatform: org.hiberate.dialect.Oracle10gDialect
Yes and no. Unfortunately the manifest.yml doesn't work quite like that. The file provides the settings that will be used for cf push. It's application agnostic and doesn't know anything about Spring, Java, your programming language or your application framework of choice. Thus it cannot make changes to your application.properties file or other framework specific configuration.
Fortunately, there are many ways to configure Spring Boot (see here) and one of them is via environment variables. What's fortunate about this is that you can set environment variables via manifest.yml. Thus if you set the proper environment variables in manifest.yml, you can configure your application.
For reference, here are instructions for setting env variables in manifest.yml.
https://docs.cloudfoundry.org/devguide/deploy-apps/manifest.html#env-block
It looks roughly like this:
---
...
env:
ENV_1: val_1
ENV_2: val_2
Spring Boot will map environment variables to properties using the rules explained here. A basic example would be SPRING_DATASOURCE_USERNAME maps to spring.datasource.username in application.properties.
What you actually want to do here is have your database connection as a cloud foundry service rather than defined in your application.properties. As Daniel's answer suggests, Spring can pick up ENV variables, but setting connection details in the manifest is not the idiomatic way to do this.
By having a service, the connection details are stored in the VCAP_SERVICES variable when bound to the application - spring can read from there. The spring-music app shows the prototypical way of doing this.

Resources