'No Token Found error in Prometheus
I want to monitor my .Net Core application with Prometheus.
In order to do that I am using a .Net Prometheus Library (AppMetrics).
And when I go to the link http://localhost:57057/metrics it returns me a JSON with data.
But when I go to prometheus and add this link as target it throws this error 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="no token found"
Is it a way that I can handle this?
Anyone having trouble with this one here's the solution.
Startup.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();
Program.cs
Metrics = AppMetrics.CreateDefaultBuilder()
.OutputMetrics.AsPrometheusPlainText()
.OutputMetrics.AsPrometheusProtobuf()
.Build();
return WebHost.CreateDefaultBuilder(args)
.ConfigureMetrics(Metrics)
.UseMetrics()
.UseStartup<Startup>()
.Build();
appsettings.json
"MetricsOptions": {
"DefaultContextLabel": "MyMvcApplication",
"Enabled": true
},
"MetricsWebTrackingOptions": {
"ApdexTrackingEnabled": true,
"ApdexTSeconds": 0.1,
"IgnoredHttpStatusCodes": [ 404 ],
"IgnoredRoutesRegexPatterns": [],
"OAuth2TrackingEnabled": true
},
"MetricEndpointsOptions": {
"MetricsEndpointEnabled": true,
"MetricsTextEndpointEnabled": true,
"EnvironmentInfoEndpointEnabled": true
}
And you can access it by /metrics-text path.
Also in your prometheus.yml file should add this one:
- job_name: 'nameOfJob'
metrics_path: '/metrics-text'
static_configs:
- targets: ['localhost:57057']
Solution 1:[1]
This usually means that the output is not valid Prometheus text format. Look for hyphens in metric or label names, or either of those starting with numbers - those are the most common errors.
Solution 2:[2]
Prom Tools can be used to inspect your metrics endpoints for errors.
sudo apt install prometheus
curl -L -s http://your-website.com:80/metrics | promtool check metrics
The problem for me was that the metrics endpoint was only available for logged in users.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | brian-brazil |
| Solution 2 | Helge Schneider |
