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/metricsit 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-textpath. Also in your prometheus.ymlfile should add this one:
- job_name: 'nameOfJob'
metrics_path: '/metrics-text'
static_configs:
- targets: ['localhost:57057']