可以弄清楚如何更改Prometheus内容类型标头
因此,我的指标全部出现在我的端点上的一行中,而不是按照每个度量的新行。 我使用千分尺,春季,普罗米修斯和斯卡拉。
我的控制器:
@RequestMapping(Array(""))
class MetricsController @Inject() (prometheusRegistry: PrometheusMeterRegistry) {
@RequestMapping(value = Array("/metrics"), method = Array(RequestMethod.GET))
def metricses(): String = {
prometheusRegistry.scrape()
}
}
改变我编写自己的指标的方式是否足够?
我尝试添加scrape(textformat.content_type_004)
,但这并没有改变。 它与HTTP响应标头有关吗? 是否可以补充:
.putHeader(HttpHeaders.CONTENT_TYPE, TextFormat.CONTENT_TYPE_004)
.end(registry.scrape());
如果是这样,我该怎么办?
谢谢
So my metrics all appear in one line at my end-point, not in new line per metric.
I use micrometer, spring, prometheus and scala.
My controller:
@RequestMapping(Array(""))
class MetricsController @Inject() (prometheusRegistry: PrometheusMeterRegistry) {
@RequestMapping(value = Array("/metrics"), method = Array(RequestMethod.GET))
def metricses(): String = {
prometheusRegistry.scrape()
}
}
Should it be enough to change the way I write the metrics them selves?
I have tried to add scrape(TextFormat.CONTENT_TYPE_004)
but that changed nothing.
Does it have to do with the HTTP response header?
Would it work to add:
.putHeader(HttpHeaders.CONTENT_TYPE, TextFormat.CONTENT_TYPE_004)
.end(registry.scrape());
If so how would I do that in my case?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Prometheus(或其他兼容的后端)会向您发送
Accept
您不应该忽略的标题(请阅读有关内容谈判的有关),但是如果您想忽略它:如果您不想忽略它,
textformat
具有choosecontenttype
您可以使用Accept
标题来获取内容类型的方法:或者您还可以设置内容谈判: https://www.baeldung.com/spring-mvc-content -nogotiation-json-xml
Prometheus (or other compatible backends) will send you an
Accept
header that you should not ignore (please read about content negotiation) but if you want to ignore it:If you don't want to ignore it,
TextFormat
has achooseContentType
method that you can utilize to get the content type based on theAccept
header:Or you can also set-up content negotiation: https://www.baeldung.com/spring-mvc-content-negotiation-json-xml