[英]Configure micrometer-registry-statsd in spring boot 2
[英]Spring boot with micrometer Elasticsearch registry indexes only empty documents
我有一个使用千分尺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);
}
}
和TestController
@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不会更改任何内容。
有人看到我在这里想念的吗?
UPDATE
我在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
响应中为"errors": false
{
"took": 8,
"errors": false,
"items": [
...
]
}
该指数metrics-2019-08
由create ElasticMeterRegistry
在其映射集合_source
到假
GET http://localhost:9200/metrics-2019-08/_mapping
回应为
"metrics-2019-08": {
"mappings": {
"_source": {
"enabled": false
}
...
}
}
从这里的Elasticserch文档中
_source字段本身未编制索引(因此不可搜索),但已存储该字段,以便在执行获取请求(如get或search)时可以将其返回。
因此,如果_source
为false,则每个获取文档的请求都将返回空源。 禁用此功能的原因是文档仅用于聚合(平均,最小,最大,总和...),对于这些聚合不需要_source
,因此为了节省磁盘空间,不存储_source
。
要禁用此行为,请将management.metrics.export.elastic.auto-create-index
为false 。 如果已经使用true运行它,则需要使用以下命令删除现有模板
DELETE http://localhost:9200/_template/metrics_template
然后,为指标索引创建模板,如下所示:
POST http://localhost:9200/_template/metrics_template
{
"index_patterns": [
"metrics*"
],
"mappings": {
"_source": {
"enabled": true
},
"properties": {
"name": {
"type": "keyword"
},
"count": {
"type": "double"
},
"value": {
"type": "double"
},
"sum": {
"type": "double"
},
"mean": {
"type": "double"
},
"duration": {
"type": "double"
},
"max": {
"type": "double"
},
"total": {
"type": "double"
},
"unknown": {
"type": "double"
},
"active": {
"type": "double"
}
}
}
}
除了_source
设置为true之外,此模板与千分尺使用的模板相同。 此后,文档将出现在获取请求中,例如get或search。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.