Java Spring Boot Actuator Metrics system load aver

2019-09-13 05:26发布

问题:

I am a new user to Spring Boot Actuator Metrics, I need to determine the CPU utilization of the system. The /metrics url does give me rest of the details, however the systemload.average returns -1 (if load average is not available -1 is returned). Could you let me know where I went wrong and how do I correct it? I am using maven and Eclipse IDE (Mars). I am accessing metric details on localhost itself. the url is http://localhost:8080/details/metrics (details used for context path)

Here is my code: Application.java file package spring.boot.admin.actuator;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.PropertySource;

@EnableAutoConfiguration
@ComponentScan
@PropertySource(value = "classpath:application.properties")
public class Application{

public static void main(final String[] args) {
    SpringApplication.run(Application.class, args);
}
}

POM File http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

  <groupId>spring.boot.admin</groupId>
  <artifactId>actuator</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>actuator</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.7.RELEASE</version>
</parent>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

  </dependencies>
</project>

**application.properties file**

management.port=8080
management.context-path=/details
management.security.enabled=true

endpoints.health.enabled=false

security.basic.enabled=true
security.user.name=admin
security.user.password=admin

endpoints.health.id=health
endpoints.health.sensitive=true
endpoints.health.enabled=true

endpoints.metrics.id=metrics
endpoints.metrics.sensitive=true
endpoints.metrics.enabled=true

endpoints.server.id=server
endpoints.server.sensitive=false
endpoints.server.enabled=true

endpoints.info.id=info
endpoints.info.sensitive=false
endpoints.info.enabled=true
info.app.name=Spring Actuator Example
info.app.description=Spring Actuator Working Examples
info.app.version=0.0.1-SNAPSHOT
management.security.enabled=true

The enter image description here

回答1:

The systemload.average returns what the JVM returns through the OperatingSystem MBean (Available in the java.lang tree node). Use JConsole or the VisualVM-Beans plugin in VisualVM to view what is returned there.

If the value of the SystemLoadAverage attribute is the same, it is no bug in Spring Boot or your usage of Spring Boot.