【问题标题】:Java Spring Boot Actuator Metrics system load average returning -1Java Spring Boot Actuator Metrics 系统负载平均返回 -1
【发布时间】: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

enter image description here

【问题讨论】:

  • 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


【解决方案1】:

systemload.average 返回 JVM 通过 OperatingSystem MBean(在 java.lang 树节点中可用)返回的内容。使用 JConsole 或 VisualVM 中的 VisualVM-Beans 插件查看那里返回的内容。

如果SystemLoadAverage属性的值相同,则说明Spring Boot没有bug,也不是你使用Spring Boot。

【讨论】:

  • @WimDeblauve 是否有任何替代方法可以使用 Spring 引导执行器而不是获取 -1 来查找 systemload.average,因为我最初的目标是找到系统负载平均值?或者可以进行任何更改?
  • 你在什么操作系统上运行?
  • Windows 7 企业版
猜你喜欢
  • 2018-07-05
  • 2016-01-03
  • 1970-01-01
  • 1970-01-01
  • 2011-06-26
  • 2020-10-28
  • 2017-07-19
  • 2014-07-08
  • 2017-01-10
相关资源
最近更新 更多