asp.net-core - Prometheus 中未找到令牌错误
问题描述
我想用 Prometheus 监控我的 .Net Core 应用程序。为了做到这一点,我使用了一个 .Net Prometheus Library (AppMetrics)。当我转到链接http://localhost:57057/metrics
时,它会返回一个带有数据的 JSON。
但是当我去普罗米修斯并将这个链接添加为目标时,它会抛出这个错误No Token Found
。
level=warn ts=2018-05-22T06:52:17.5781093Z caller=scrape.go:697 component="scrape manager" scrape_pool=actibook target= http://localhost:57057/metrics msg="append failed" err= “未找到令牌”
这是我可以处理的方法吗?
任何对此有问题的人都是解决方案。
启动.cs
//ConfigureServices
var metrics = new MetricsBuilder()
.OutputMetrics.AsPrometheusPlainText()
.OutputMetrics.AsPrometheusProtobuf().Build();
services.AddMetrics(metrics);
services.AddMetricsEndpoints(options =>
{
options.MetricsTextEndpointOutputFormatter = new MetricsPrometheusTextOutputFormatter();
options.MetricsEndpointOutputFormatter = new MetricsPrometheusProtobufOutputFormatter();
});
services.AddMvc().AddMetrics();
//Configure
app.UseMetricsAllMiddleware();
app.UseMetricsAllEndpoints();
程序.cs
Metrics = AppMetrics.CreateDefaultBuilder()
.OutputMetrics.AsPrometheusPlainText()
.OutputMetrics.AsPrometheusProtobuf()
.Build();
return WebHost.CreateDefaultBuilder(args)
.ConfigureMetrics(Metrics)
.UseMetrics()
.UseStartup<Startup>()
.Build();
应用设置.json
"MetricsOptions": {
"DefaultContextLabel": "MyMvcApplication",
"Enabled": true
},
"MetricsWebTrackingOptions": {
"ApdexTrackingEnabled": true,
"ApdexTSeconds": 0.1,
"IgnoredHttpStatusCodes": [ 404 ],
"IgnoredRoutesRegexPatterns": [],
"OAuth2TrackingEnabled": true
},
"MetricEndpointsOptions": {
"MetricsEndpointEnabled": true,
"MetricsTextEndpointEnabled": true,
"EnvironmentInfoEndpointEnabled": true
}
您可以通过/metrics-text
路径访问它。同样在你的prometheus.yml
文件中应该添加这个:
- job_name: 'nameOfJob'
metrics_path: '/metrics-text'
static_configs:
- targets: ['localhost:57057']
解决方案
这通常意味着输出不是有效的 Prometheus 文本格式。查找公制或标签名称中的连字符,或以数字开头的任何一个 - 这些是最常见的错误。
推荐阅读
- automapper - 如何将新的映射器添加到已经初始化的映射器?
- sql-server - ssas 中的部分多字节字符错误 - ORA 29275
- git - 为什么 git pull 不更新我的一些本地文件
- oracle - 如何使用 PL/SQL 存储多个数量的属性
- php - 我将如何阅读带有双引号的整个文件,并且我无法手动阅读电子邮件中的附件
- css - 在aspx页面中动态排列图像
- java - Guava 缓存数据加载问题
- war - ModuleNotFoundException:无法在 Jboss EAP 7 上部署战争
- batch-file - 有没有直接在浏览器的localhost上直接打开html文件?
- ag-grid - 是否可以在没有 ag-grid 企业版的情况下制作国家多选过滤器?