我有这个简单的控制器
@RestController
@RequestMapping("/metrics")
public class MetricsController {
@GetMapping
@ApiOperation("Get metrics by source")
public ResponseEntity<List<Metric>> getMetricBySource(@RequestParam String source) {
if (source.equalsIgnoreCase("recordings")) {
return new ResponseEntity<>(MetricsConstants.RECORDINGS_METRICS, HttpStatus.OK);
} else if (source.equalsIgnoreCase("advertisers")) {
return new ResponseEntity<>(MetricsConstants.ADVERTISERS_METRICS, HttpStatus.OK);
} else if (source.equalsIgnoreCase("publishers")) {
return new ResponseEntity<>(MetricsConstants.PUBLISHERS_METRICS, HttpStatus.OK);
} else if (source.equalsIgnoreCase("partners")) {
return new ResponseEntity<>(MetricsConstants.PARTNERS_METRICS, HttpStatus.OK);
} else if (source.equalsIgnoreCase("products")) {
return new ResponseEntity<>(MetricsConstants.PRODUCTS_METRICS, HttpStatus.OK);
} else if (source.equalsIgnoreCase("regular-users")) {
return new ResponseEntity<>(MetricsConstants.REGULAR_USERS_METRICS, HttpStatus.OK);
}
return null;
}
}
现在,当我试图通过
访问端点时
localhost:8099/metrics?source=advertisers
我得到以下回复
{ &#34; mem&#34;:947258, &#34; mem.free&#34;:367038, &#34;处理器&#34;:4, &#34; instance.uptime&#34;:540532, &#34;正常运行时间&#34;:556754, &#34; systemload.average&#34;:-1, &#34; heap.committed&#34;:854016, &#34; heap.init&#34;:260096, &#34; heap.used&#34;:486977, &#34;堆&#34;:3699200, &#34; nonheap.committed&#34;:95312, &#34; nonheap.init&#34;:2496, &#34; nonheap.used&#34;:93242, &#34; nonheap&#34;:0, &#34; threads.peak&#34;:61, &#34; threads.daemon&#34;:37, &#34; threads.totalStarted&#34;:128, &#34;线程&#34;:53, &#34;班级&#34;:13916, &#34; classes.loaded&#34;:13916, &#34; classes.unloaded&#34;:0, &#34; gc.ps_scavenge.count&#34;:13, &#34; gc.ps_scavenge.time&#34;:150, &#34; gc.ps_marksweep.count&#34;:3, &#34; gc.ps_marksweep.time&#34;:341, &#34; counter.servo.eurekaclient.transport.request&#34;:0, &#34; counter.servo.eurekaclient.transport.connectionerrors&#34;:0, &#34; counter.servo.timeouts&#34;:0, &#34; counter.servo.rejectedexecutions&#34;:0, &#34; counter.servo.throwables&#34;:0, &#34; gauge.servo.threadpoolused&#34;:0, &#34; gauge.servo.response.metrics&#34;:6, &#34; normalized.servo.rest.totaltime&#34;:0, &#34; normalized.servo.rest.count&#34;:0, &#34; gauge.servo.rest.min&#34;:0, &#34; gauge.servo.rest.max&#34;:0, &#34; gauge.servo.eurekaclient.registration.lastheartbeatsec_00030&#34;:0, &#34; counter.servo.discoveryclient-httpclient_reuse&#34;:10, &#34; counter.servo.discoveryclient-httpclient_createnew&#34;:26, &#34; counter.servo.discoveryclient-httpclient_request&#34;:36, &#34; counter.servo.discoveryclient-httpclient_release&#34;:36, &#34; counter.servo.discoveryclient-httpclient_delete&#34;:24, &#34; normalized.servo.discoveryclient-httpclient_requestconnectiontimer.totaltime&#34 ;: 0.005046033333333333, &#34; normalized.servo.discoveryclient-httpclient_requestconnectiontimer.count&#34 ;: 0.06666666666666667, &#34; gauge.servo.discoveryclient-httpclient_requestconnectiontimer.min&#34 ;: 0.017749, &#34; gauge.servo.discoveryclient-httpclient_requestconnectiontimer.max&#34 ;: 0.12356299999999999, &#34; normalized.servo.discoveryclient-httpclient_createconnectiontimer.totaltime&#34 ;: 0.0012743166666666665, &#34; normalized.servo.discoveryclient-httpclient_createconnectiontimer.count&#34 ;: 0.05, &#34; gauge.servo.discoveryclient-httpclient_createconnectiontimer.min&#34 ;: 0.012288, &#34; gauge.servo.discoveryclient-httpclient_createconnectiontimer.max&#34 ;: 0.034475, &#34; gauge.servo.connectioncount&#34;:2, &#34; normalized.servo.eurekaclient.transport.latency.totaltime&#34;:0, &#34; normalized.servo.eurekaclient.transport.latency.count&#34;:0, &#34; gauge.servo.eurekaclient.transport.latency.min&#34;:0, &#34; gauge.servo.eurekaclient.transport.latency.max&#34;:0, &#34; gauge.servo.response.star-star.favicon.ico&#34;:42, &#34; gauge.servo.eurekaclient.registry.lastupdatesec_00240&#34;:0, &#34; gauge.servo.eurekaclient.registration.lastheartbeatsec_00015&#34;:1, &#34; gauge.servo.response.webjars.star-star&#34;:5, &#34; gauge.servo.eurekaclient.resolver.endpointssize&#34;:1, &#34; gauge.servo.eurekaclient.resolver.lastloadtimestamp&#34;:233376, &#34; gauge.servo.eurekaclient.registration.lastheartbeatsec_00240&#34;:0, &#34; gauge.servo.eurekaclient.transport.quarantinesize&#34;:0, &#34; gauge.servo.eurekaclient.registry.lastupdatesec_00030&#34;:0, &#34; gauge.servo.response.v2.api-docs&#34;:126, &#34; gauge.servo.eurekaclient.registration.lastheartbeatsec_00480&#34;:0, &#34; gauge.servo.eurekaclient.registry.lastupdatesec_00480&#34;:0, &#34; gauge.servo.response.star-star&#34;:13, &#34; gauge.servo.response.swagger-resources.configuration.ui&#34;:19, &#34; normalized.servo.eureka-connection-cleaner-time.totaltime&#34;:0.0009386666666666665, &#34; normalized.servo.eureka-connection-cleaner-time.count&#34;:0.03333333333333333, &#34; gauge.servo.eureka-connection-cleaner-time.min&#34;:0.021162, &#34; gauge.servo.eureka-connection-cleaner-time.max&#34;:0.035158, &#34; counter.servo.eureka-connection-cleaner-failure&#34;:0, &#34; gauge.servo.eurekaclient.transport.currentsessionduration&#34;:533378, &#34; gauge.servo.eurekaclient.registration.lastheartbeatsec_00120&#34;:0, &#34; gauge.servo.eurekaclient.registry.lastupdatesec_00015&#34;:1, &#34; gauge.servo.response.swagger-resources.configuration.security&#34;:4, &#34; gauge.servo.eurekaclient.registry.lastupdatesec_00120&#34;:0, &#34; gauge.servo.response.info&#34;:35, &#34; gauge.servo.eurekaclient.registration.lastheartbeatsec_00060&#34;:0, &#34; gauge.servo.eurekaclient.registry.lastupdatesec_00060&#34;:0, &#34; counter.servo.discoveryclient_reconcilehashcodemismatch&#34;:0, &#34; normalized.servo.discoveryclient_fetchregistry.totaltime&#34;:0.29706815000000003, &#34; normalized.servo.discoveryclient_fetchregistry.count&#34;:0.03333333333333333, &#34; gauge.servo.discoveryclient_fetchregistry.min&#34;:4.337664999999999, &#34; gauge.servo.discoveryclient_fetchregistry.max&#34;:13.486424, &#34; counter.servo.discoveryclient_reregister&#34;:0, &#34; gauge.servo.eurekaclient.registry.localregistrysize&#34;:5, &#34; gauge.servo.eurekaclient.registry.lastsuccessfulregistryfetchtimeperiod&#34 ;: 22920, &#34; gauge.servo.eurekaclient.registration.lastsuccessfulheartbeattimeperiod&#34 ;: 22926, &#34; gauge.servo.response.swagger-resources&#34;:5, &#34; integration.channel.errorChannel.errorRate.mean&#34;:0, &#34; integration.channel.errorChannel.errorRate.max&#34;:0, &#34; integration.channel.errorChannel.errorRate.min&#34;:0, &#34; integration.channel.errorChannel.errorRate.stdev&#34;:0, &#34; integration.channel.errorChannel.errorRate.count&#34;:0, &#34; integration.channel.errorChannel.sendCount&#34;:0, &#34; integration.channel.errorChannel.sendRate.mean&#34;:0, &#34; integration.channel.errorChannel.sendRate.max&#34;:0, &#34; integration.channel.errorChannel.sendRate.min&#34;:0, &#34; integration.channel.errorChannel.sendRate.stdev&#34;:0, &#34; integration.channel.errorChannel.sendRate.count&#34;:0, &#34; integration.channel.springCloudBusInput.errorRate.mean&#34;:0, &#34; integration.channel.springCloudBusInput.errorRate.max&#34;:0, &#34; integration.channel.springCloudBusInput.errorRate.min&#34;:0, &#34; integration.channel.springCloudBusInput.errorRate.stdev&#34;:0, &#34; integration.channel.springCloudBusInput.errorRate.count&#34;:0, &#34; integration.channel.springCloudBusInput.sendCount&#34;:0, &#34; integration.channel.springCloudBusInput.sendRate.mean&#34;:0, &#34; integration.channel.springCloudBusInput.sendRate.max&#34;:0, &#34; integration.channel.springCloudBusInput.sendRate.min&#34;:0, &#34; integration.channel.springCloudBusInput.sendRate.stdev&#34;:0, &#34; integration.channel.springCloudBusInput.sendRate.count&#34;:0, &#34; integration.channel.hystrixStreamOutput.errorRate.mean&#34;:0, &#34; integration.channel.hystrixStreamOutput.errorRate.max&#34;:0, &#34; integration.channel.hystrixStreamOutput.errorRate.min&#34;:0, &#34; integration.channel.hystrixStreamOutput.errorRate.stdev&#34;:0, &#34; integration.channel.hystrixStreamOutput.errorRate.count&#34;:0, &#34; integration.channel.hystrixStreamOutput.sendCount&#34;:0, &#34; integration.channel.hystrixStreamOutput.sendRate.mean&#34;:0, &#34; integration.channel.hystrixStreamOutput.sendRate.max&#34;:0, &#34; integration.channel.hystrixStreamOutput.sendRate.min&#34;:0, &#34; integration.channel.hystrixStreamOutput.sendRate.stdev&#34;:0, &#34; integration.channel.hystrixStreamOutput.sendRate.count&#34;:0, &#34; integration.channel.nullChannel.errorRate.mean&#34;:0, &#34; integration.channel.nullChannel.errorRate.max&#34;:0, &#34; integration.channel.nullChannel.errorRate.min&#34;:0, &#34; integration.channel.nullChannel.errorRate.stdev&#34;:0, &#34; integration.channel.nullChannel.errorRate.count&#34;:0, &#34; integration.channel.nullChannel.sendCount&#34;:0, &#34; integration.channel.nullChannel.sendRate.mean&#34;:0, &#34; integration.channel.nullChannel.sendRate.max&#34;:0, &#34; integration.channel.nullChannel.sendRate.min&#34;:0, &#34; integration.channel.nullChannel.sendRate.stdev&#34;:0, &#34; integration.channel.nullChannel.sendRate.count&#34;:0, &#34; integration.channel.springCloudBusOutput.errorRate.mean&#34;:0, &#34; integration.channel.springCloudBusOutput.errorRate.max&#34;:0, &#34; integration.channel.springCloudBusOutput.errorRate.min&#34;:0, &#34; integration.channel.springCloudBusOutput.errorRate.stdev&#34;:0, &#34; integration.channel.springCloudBusOutput.errorRate.count&#34;:0, &#34; integration.channel.springCloudBusOutput.sendCount&#34;:0, &#34; integration.channel.springCloudBusOutput.sendRate.mean&#34;:0, &#34; integration.channel.springCloudBusOutput.sendRate.max&#34;:0, &#34; integration.channel.springCloudBusOutput.sendRate.min&#34;:0, &#34; integration.channel.springCloudBusOutput.sendRate.stdev&#34;:0, &#34; integration.channel.springCloudBusOutput.sendRate.count&#34;:0, &#34; integration.handler._org.springframework.integration.errorLogger.handler.duration.mean&#34 ;: 0, &#34; integration.handler._org.springframework.integration.errorLogger.handler.duration.max&#34 ;: 0, &#34; integration.handler._org.springframework.integration.errorLogger.handler.duration.min&#34 ;: 0, &#34; integration.handler._org.springframework.integration.errorLogger.handler.duration.stdev&#34 ;: 0, &#34; integration.handler._org.springframework.integration.errorLogger.handler.duration.count&#34 ;: 0, &#34; integration.handler._org.springframework.integration.errorLogger.handler.activeCount&#34 ;: 0, &#34; integration.handlerCount&#34;:1, &#34; integration.channelCount&#34;:5, &#34; integration.sourceCount&#34;:0, &#34; httpsessions.max&#34;:-1, &#34; httpsessions.active&#34;:0, &#34; datasource.primary.active&#34;:0, &#34; datasource.primary.usage&#34;:0}
代码流甚至没有转到该方法(尝试使用调试器)。 仅有这个新创建的端点的问题。最后一个错误是
访问此资源需要完全身份验证
直到我写完配置文件:
management:
security:
enabled: false
我用
springBootVersion = '1.5.3.RELEASE'
springCloudVersion = 'Dalston.RELEASE'
答案 0 :(得分:0)
问题出在Spring Cloud MetricsInterceptorConfiguration上。
据我所知,在每个端点上,您可以添加后缀路径/指标,以查看Spring Cloud提供的此端点的指标。所以它只是拦截了我的映射:)
我通过将以下配置添加到 bootstrap.yml 来解决了这个问题:
endpoints:
metrics:
enabled: false