我有一个使用千分尺 Elasticsearch 注册表(使用 Elasticsearch 7.2.0)的简单 spring boot 2.1.7.RELEASE项目。该项目在github 上可用。它只有两个类,看起来像这样
pom.xml具有以下依赖项:
<dependencies>
<dependency>
<artifactId>spring-boot-starter-web</artifactId>
<groupId>org.springframework.boot</groupId>
</dependency>
<dependency>
<artifactId>spring-boot-starter-actuator</artifactId>
<groupId>org.springframework.boot</groupId>
</dependency>
<dependency>
<artifactId>micrometer-registry-elastic</artifactId>
<groupId>io.micrometer</groupId>
</dependency>
</dependencies>
和两个类: MicrometerElasticApplication:
@SpringBootApplication
public class MicrometerElasticApplication {
public static void main(final String[] args) {
SpringApplication.run(MicrometerElasticApplication.class, args);
}
}
和测试控制器
@RestController
public class TestController {
@ResponseStatus(HttpStatus.OK)
@GetMapping("/test")
public void sendMessage() {
System.out.println("Received a test message");
}
}
启动应用程序后,我可以在日志中看到
i.m.elastic.ElasticMeterRegistry : publishing metrics to elastic every 1m
这意味着发送了指标,但是当我检查 Elasticsearch 中的索引时,我只能看到这样的文档
{
"_index": "metrics-2019-08",
"_type": "_doc",
"_id": "nWuMdWwBxBoi4XILEHVK",
"_score": 1.0
}
所以没有字段,只有文档元数据。即使在达到端点服务器时间之后,索引/test
也没有任何变化。metrics
通过阅读此处的官方文档并检查此处的常见属性,我的理解是Spring默认情况下将为 JVM、CPU ......甚至测量所有 MVC 请求的时间。现在,我没有得到任何这些,只是空文件。将该属性设置management.metrics.web.server.auto-time-requests
为true不会更改任何内容。
有人看到我在这里缺少什么吗?
更新
我在方法上设置了一个断点,ElasticMeterRegistry.publish
发送到 Elaticsearch /_bulk
API 的请求对我来说看起来不错
POST http://localhost:9200/metrics-2019-08/_bulk
{ "index" : {} }
{"@timestamp":"2019-08-09T10:49:18.826Z","name":"jvm_memory_max","type":"gauge","area":"heap","id":"PS Survivor Space","value":1.5204352E7}
{ "index" : {} }
{"@timestamp":"2019-08-09T10:49:18.826Z","name":"jvm_threads_states","type":"gauge","state":"terminated","value":0.0}
...
当我使用 Postman 发送此请求时,所有文档都保存为空文档,尽管 Elasticsearch 没有报告任何错误,但"errors": false
在响应中
{
"took": 8,
"errors": false,
"items": [
...
]
}