public ActionResult FrequencyData(string sort = "time", string format="html", bool clear = false) { if(clear) { QueryFrequencyLogger.ResetCache(); } //sorts: time (total time), average (avg time per call), calls (number of times called) var model = new SqlFrequencyModel { HoursAlive = (DateTime.Now - QueryFrequencyLogger.CollectionStart).TotalHours, Queries = QueryFrequencyLogger.GetTopQueries(sort) }; long TotalMilliseconds = 0; long TotalCalls = 0; foreach(var q in model.Queries) { //aggregate them by server TotalMilliseconds += q.TotalMilliseconds; TotalCalls += q.TotalCalls; } var serverTotal = new QueryFrequencyLogger.QueryLog { Stack = Environment.MachineName + " totals", TotalCalls = TotalCalls, TotalMilliseconds = TotalMilliseconds }; model.Total = serverTotal; if(format == "json") { model.Queries = model.Queries.Take(99).ToList();//limit return Json(model, JsonRequestBehavior.AllowGet); } return View(model); }
public ActionResult FrequencyAggregate(string sort = "time", bool clear = false) { var clr = clear ? "&clear=true" : ""; var remoteUrl = "/remote/infrastructure/Sql/FrequencyData?sort=" + sort + "&format=json" + clr; var data = ServerAggregate.HitAllServers(remoteUrl); var q = (from d in data let model = !d.Error ? Newtonsoft.Json.JsonConvert.DeserializeObject<SqlFrequencyModel>(d.Response) : null select new {d, model}) .ToList(); var ttl = q.Where(x => !x.d.Error).Select(x => x.model).ToList(); var ttlLog = new QueryFrequencyLogger.QueryLog{Stack = "grand totals all servers"}; double hoursAlive = 0; double percentageSum = 0; if(ttl.Count > 0) { ttlLog.TotalCalls = ttl.Sum(x => x.Total.TotalCalls); ttlLog.TotalMilliseconds = ttl.Sum(x => x.Total.TotalMilliseconds); hoursAlive = ttl.Sum(x => x.HoursAlive); percentageSum = ttl.Sum(x => x.Total.GetPercentTotalTime(x.HoursAlive)); } return View(new SqlAggregateModel { Servers = q.ToDictionary(x => x.d, x => x.model), Total = ttlLog, TotalHoursAlive = hoursAlive, SumOfPercentages = percentageSum }); //return Json(data, JsonRequestBehavior.AllowGet); }