Skip to content

Instantly share code, notes, and snippets.

@thiagoloureiro
Last active June 3, 2018 20:17
Show Gist options
  • Save thiagoloureiro/d439ffe13a24a35dc33ad2e97410cb03 to your computer and use it in GitHub Desktop.
Save thiagoloureiro/d439ffe13a24a35dc33ad2e97410cb03 to your computer and use it in GitHub Desktop.
public void ConfigureServices(IServiceCollection services)
{
var database = "appmetricsdemo";
var uri = new Uri("http://127.0.0.1:8086");
services.AddMetrics(options =>
{
options.WithGlobalTags((globalTags, info) =>
{
globalTags.Add("app", info.EntryAssemblyName);
globalTags.Add("env", "stage");
});
})
.AddHealthChecks()
.AddReporting(
factory =>
{
factory.AddInfluxDb(
new InfluxDBReporterSettings
{
InfluxDbSettings = new InfluxDBSettings(database, uri),
ReportInterval = TimeSpan.FromSeconds(5)
});
})
.AddMetricsMiddleware(options => options.IgnoredHttpStatusCodes = new[] { 404 });
services.AddMvc(options => options.AddMetricsResourceFilter());
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime lifetime)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
app.UseMetrics();
app.UseMetricsReporting(lifetime);
app.UseMvc();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment