protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); Perfon.Mvc.PerfMonitorForMvc PerfMonitor = new Perfon.Mvc.PerfMonitorForMvc(); PerfMonitor.RegisterLiteDbStorage(AppDomain.CurrentDomain.BaseDirectory); PerfMonitor.OnError += (a, b) => { File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "\\errors.log", "\n" + DateTime.Now.ToString() + " " + b.Message); Console.WriteLine("PerfLibForMvc:" + b.Message); }; var thr1 = new ThresholdMaxNotification(500); thr1.OnThresholdViolated += (a, b) => Console.WriteLine(b.Message); thr1.OnThresholdViolationRecovered += (a, b) => Console.WriteLine(b.Message); PerfMonitor.PerfMonitorBase.RequestNum.AddThreshold(thr1); //Change some default settings if needed PerfMonitor.Configuration.DoNotStorePerfCountersIfReqLessOrEqThan = 0; PerfMonitor.Configuration.EnablePerfApi = true; PerfMonitor.Configuration.EnablePerfUIApi = true; PerfMonitor.Start(this, RouteTable.Routes, 5); }
protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); ///Create perf monitor engine PerfMonitor = new PerfMonitorForWebApi(); // Register storage var storageType = ConfigurationManager.AppSettings["StorageType"]; var storageConnString = ConfigurationManager.AppSettings["StorageConnectionString"]; if (storageType == null || storageType == null) { //PerfMonitor.RegisterCSVFileStorage(AppDomain.CurrentDomain.BaseDirectory + "\\" + ConfigurationManager.AppSettings["DB_Path"]); //PerfMonitor.RegisterInMemoryCacheStorage(60); PerfMonitor.RegisterLiteDbStorage(AppDomain.CurrentDomain.BaseDirectory + "\\" + ConfigurationManager.AppSettings["DB_Path"]); } else { Type type = Type.GetType(storageType, true); var storage = (Activator.CreateInstance(type, storageConnString)) as IPerfomanceCountersStorage; if (type == null || storage == null) { PerfMonitor_OnError(this, new Perfon.Core.Common.PerfonErrorEventArgs(type == null ? "null" : type.ToString() + ", " + storage == null ? "null" : storage.ToString())); } else { PerfMonitor.RegisterStorages(storage); } } //Suscribe on error events PerfMonitor.OnError += PerfMonitor_OnError; //Create and subscribe on perf counter value threshold violation events var thr1 = new ThresholdMaxNotification(500); thr1.OnThresholdViolated += (a, b) => Console.WriteLine(b.Message); thr1.OnThresholdViolationRecovered += (a, b) => Console.WriteLine(b.Message); PerfMonitor.PerfMonitorBase.RequestNum.AddThreshold(thr1); //Change some default settings if needed PerfMonitor.Configuration.DoNotStorePerfCountersIfReqLessOrEqThan = 0; //Do not store perf values if RequestsNum = 0 during poll period PerfMonitor.Configuration.EnablePerfApi = true; // Enable getting perf values by API GET addresses 'api/perfcounters' and 'api/perfcounters/{name}' PerfMonitor.Configuration.EnablePerfUIApi = true; // Enable getting UI html page with perf counters values by API GET 'api/perfcountersui' or 'api/perfcountersuipanel' //Register Windows Perf Counters if neede //PerfMonitor.PerfMonitorBase.AddWindowsPerfCounter("% Processor Time", "_Total"); // Start counters polling PerfMonitor.Start(GlobalConfiguration.Configuration, 5); }