public static void Main() { var cpuUsage = new CpuUsage(); cpuUsage.Start(); IServiceCollection serviceCollection = new ServiceCollection(); ConfigureServices(serviceCollection); ConfigureMetrics(serviceCollection); var process = Process.GetCurrentProcess(); var provider = serviceCollection.BuildServiceProvider(); var application = new Application(provider); var scheduler = new DefaultTaskScheduler(); var simpleMetrics = new SampleMetrics(application.Metrics); var setCounterSample = new SetCounterSample(application.Metrics); var setMeterSample = new SetMeterSample(application.Metrics); var userValueHistogramSample = new UserValueHistogramSample(application.Metrics); var userValueTimerSample = new UserValueTimerSample(application.Metrics); //var rnd = new Random(); //foreach (var index in Enumerable.Range(0, 30)) //{ // using (application.Metrics.Track(AppMetricsRegistry.ApdexScores.AppApdex)) // { // if (index % 4 == 0) // { // Thread.Sleep(rnd.Next(2100, 2200)); // } // else if (index % 2 == 0) // { // Thread.Sleep(rnd.Next(600, 700)); // } // else // { // Thread.Sleep(rnd.Next(0, 300)); // } // } //} var cancellationTokenSource = new CancellationTokenSource(); var task = scheduler.Interval( TimeSpan.FromMilliseconds(300), () => { using (application.Metrics.Track(AppMetricsRegistry.ApdexScores.AppApdex)) { setCounterSample.RunSomeRequests(); setMeterSample.RunSomeRequests(); userValueHistogramSample.RunSomeRequests(); //userValueTimerSample.RunSomeRequests(); //TODO: AH - why's this taking so long? simpleMetrics.RunSomeRequests(); } application.Metrics.Gauge(AppMetricsRegistry.Gauges.Errors, () => 1); application.Metrics.Gauge(AppMetricsRegistry.Gauges.PercentGauge, () => 1); application.Metrics.Gauge(AppMetricsRegistry.Gauges.ApmGauge, () => 1); application.Metrics.Gauge(AppMetricsRegistry.Gauges.ParenthesisGauge, () => 1); application.Metrics.Gauge(AppMetricsRegistry.Gauges.GaugeWithNoValue, () => double.NaN); application.Metrics.Gauge(AppMetricsRegistry.ProcessMetrics.CpuUsageTotal, () => { cpuUsage.CallCpu(); return(cpuUsage.CpuUsageTotal); }); application.Metrics.Gauge(AppMetricsRegistry.ProcessMetrics.ProcessPagedMemorySizeGauge, () => process.PagedMemorySize64); application.Metrics.Gauge(AppMetricsRegistry.ProcessMetrics.ProcessPeekPagedMemorySizeGauge, () => process.PeakPagedMemorySize64); application.Metrics.Gauge(AppMetricsRegistry.ProcessMetrics.ProcessPeekVirtualMemorySizeGauge, () => process.PeakVirtualMemorySize64); application.Metrics.Gauge(AppMetricsRegistry.ProcessMetrics.ProcessPeekWorkingSetSizeGauge, () => process.WorkingSet64); application.Metrics.Gauge(AppMetricsRegistry.ProcessMetrics.ProcessPrivateMemorySizeGauge, () => process.PrivateMemorySize64); application.Metrics.Gauge(AppMetricsRegistry.ProcessMetrics.ProcessVirtualMemorySizeGauge, () => process.VirtualMemorySize64); application.Metrics.Gauge(AppMetricsRegistry.ProcessMetrics.SystemNonPagedMemoryGauge, () => process.NonpagedSystemMemorySize64); application.Metrics.Gauge(AppMetricsRegistry.ProcessMetrics.SystemPagedMemorySizeGauge, () => process.PagedSystemMemorySize64); }, cancellationTokenSource.Token); application.Reporter.RunReportsAsync(application.Metrics, cancellationTokenSource.Token); Console.WriteLine("Setup Complete, waiting for report run..."); Console.ReadKey(); }
public static void Main() { var cpuUsage = new CpuUsage(); cpuUsage.Start(); IServiceCollection serviceCollection = new ServiceCollection(); ConfigureServices(serviceCollection); ConfigureMetrics(serviceCollection); var process = Process.GetCurrentProcess(); var provider = serviceCollection.BuildServiceProvider(); var application = new Application(provider); var scheduler = new DefaultTaskScheduler(); var simpleMetrics = new SampleMetrics(application.Metrics); var setCounterSample = new SetCounterSample(application.Metrics); var setMeterSample = new SetMeterSample(application.Metrics); var userValueHistogramSample = new UserValueHistogramSample(application.Metrics); var userValueTimerSample = new UserValueTimerSample(application.Metrics); var cancellationTokenSource = new CancellationTokenSource(); //cancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(10)); var task = scheduler.Interval( TimeSpan.FromMilliseconds(300), TaskCreationOptions.LongRunning, () => { using (application.Metrics.Measure.Apdex.Track(AppMetricsRegistry.ApdexScores.AppApdex)) { setCounterSample.RunSomeRequests(); setMeterSample.RunSomeRequests(); userValueHistogramSample.RunSomeRequests(); userValueTimerSample.RunSomeRequests(); simpleMetrics.RunSomeRequests(); } application.Metrics.Measure.Gauge.SetValue(AppMetricsRegistry.Gauges.Errors, () => 1); application.Metrics.Measure.Gauge.SetValue(AppMetricsRegistry.Gauges.PercentGauge, () => 1); application.Metrics.Measure.Gauge.SetValue(AppMetricsRegistry.Gauges.ApmGauge, () => 1); application.Metrics.Measure.Gauge.SetValue(AppMetricsRegistry.Gauges.ParenthesisGauge, () => 1); application.Metrics.Measure.Gauge.SetValue(AppMetricsRegistry.Gauges.GaugeWithNoValue, () => double.NaN); application.Metrics.Measure.Gauge.SetValue(AppMetricsRegistry.ProcessMetrics.CpuUsageTotal, () => { cpuUsage.CallCpu(); return(cpuUsage.CpuUsageTotal); }); application.Metrics.Measure.Gauge.SetValue(AppMetricsRegistry.ProcessMetrics.ProcessPagedMemorySizeGauge, () => process.PagedMemorySize64); application.Metrics.Measure.Gauge.SetValue(AppMetricsRegistry.ProcessMetrics.ProcessPeekPagedMemorySizeGauge, () => process.PeakPagedMemorySize64); application.Metrics.Measure.Gauge.SetValue(AppMetricsRegistry.ProcessMetrics.ProcessPeekVirtualMemorySizeGauge, () => process.PeakVirtualMemorySize64); application.Metrics.Measure.Gauge.SetValue(AppMetricsRegistry.ProcessMetrics.ProcessPeekWorkingSetSizeGauge, () => process.WorkingSet64); application.Metrics.Measure.Gauge.SetValue(AppMetricsRegistry.ProcessMetrics.ProcessPrivateMemorySizeGauge, () => process.PrivateMemorySize64); application.Metrics.Measure.Gauge.SetValue(AppMetricsRegistry.ProcessMetrics.ProcessVirtualMemorySizeGauge, () => process.VirtualMemorySize64); application.Metrics.Measure.Gauge.SetValue(AppMetricsRegistry.ProcessMetrics.SystemNonPagedMemoryGauge, () => process.NonpagedSystemMemorySize64); application.Metrics.Measure.Gauge.SetValue(AppMetricsRegistry.ProcessMetrics.SystemPagedMemorySizeGauge, () => process.PagedSystemMemorySize64); }, cancellationTokenSource.Token); application.Reporter.RunReports(application.Metrics, cancellationTokenSource.Token); Console.WriteLine("Report Cancelled..."); Console.ReadKey(); }