/// <summary> /// This method must be called before using metrics, it accepts /// a full configured <see cref="MetricsBuilder"/> and is used /// to create an internal version of metrics to help you in /// creating metrics. /// </summary> /// <param name="builder"></param> public static void InitMetrics(IMetricsBuilder builder) { if (Metrics != null) { throw new JarvisFrameworkEngineException("Metrics already configured, cannot configure more than once"); } Metrics = builder.Build(); }
public static IMetricsRoot BuildAndAddTo( this IMetricsBuilder builder, IServiceCollection services) { var metrics = builder.Build(); services.AddMetrics(metrics); return(metrics); }
public static IServiceCollection AddMetrics(this IServiceCollection services, IMetricsBuilder builder) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } var metrics = builder.Build(); AddCoreServices(services, metrics); return(services); }
private static void Initialize(CLI root) { if (root == null) { throw new InvalidOperationException("root should not be null."); } string context = root.RunTag ?? nameof(EGBench); IMetricsBuilder builder = AppMetrics.CreateDefaultBuilder() .Filter.With(new MetricsFilter().WhereContext(context)) .Configuration.Configure(options => { options.DefaultContextLabel = context; options.GlobalTags.Clear(); options.Enabled = true; options.ReportingEnabled = true; }); if (root.AppInsightsKey.HasValue) { EGBenchLogger.WriteLine($"Reporting metrics to application insights with instrumentation key={root.AppInsightsKey.Value}"); builder.Report.ToApplicationInsights(root.AppInsightsKey.Value); } else { isConsole = true; EGBenchLogger.WriteLine("Reporting metrics to console since --app-insights-key was not specified."); builder.Report.ToConsole(options => { options.MetricsOutputFormatter = new MetricsInfluxDbLineProtocolOutputFormatter(); }); } metricsRoot = builder.Build(); _ = Task.Run(() => ReportingLoop(metricsRoot, root.MetricsIntervalSeconds));