【发布时间】:2016-09-23 06:32:22
【问题描述】:
我是 Spring Boot Actuator Metrics 的新用户,我需要确定系统的 CPU 利用率。 /metrics url 确实为我提供了其他详细信息,但是 systemload.average 返回 -1(如果负载平均值不可用,则返回 -1)。你能让我知道我哪里出错了,我该如何纠正? 我正在使用 Maven 和 Eclipse IDE (Mars)。我正在访问本地主机本身的指标详细信息。 url 是http://localhost:8080/details/metrics(用于上下文路径的详细信息)
这是我的代码: 应用程序.java 文件 包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 文件 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
【问题讨论】:
-
code 正在使用 JMX。您可以尝试使用 VisualVM 查看那里返回的内容吗?
-
@WimDeblauwe 感谢您的建议,它让我更清楚地了解了 JMX。我现在(第一次)使用 VisualVM,它显示一个线程为 JMX Server Connection Timeout 221 处于等待状态,而 JMX Cient Heartbeat 10 线程处于睡眠状态。
-
您需要安装“VisualVM-MBeans”插件。之后,将出现一个新选项卡“MBeans”。在那里,打开“java.lang”文件夹并在树中选择“OperatingSystem”。在右侧,您将在表格中看到“SystemLoadAverage”。
-
@WimDeblauwe 我尝试了这些步骤,VisualVm 中的 Systemload.Average 为 -1
标签: java spring spring-boot spring-boot-actuator