private WebServiceResult StatusTable() { DataRow cfgData, cpuIoData; TimeSpan sinceLastPoll; string strSinceLastPoll; string tableContent = "["; foreach (int targetId in Configuration.targets.Keys) { InMemoryCache.GetCurrentValues( targetId, Configuration.metricGroups["SQL Server Configuration"], new string[] { "Version", "Edition" }, out cfgData); InMemoryCache.GetCurrentValues( targetId, Configuration.metricGroups["SQL Server Activity"], new string[] { "CPU mils", "Physical Reads", "Physical Writes" }, out cpuIoData); sinceLastPoll = DateTime.Now - Configuration.timeTable.GetLastPoll(targetId); if (sinceLastPoll.Days > 0) { strSinceLastPoll = String.Format("{0} day(s)", sinceLastPoll.Days); } else if (sinceLastPoll.Hours > 0) { strSinceLastPoll = String.Format("{0} hr(s)", sinceLastPoll.Hours); } else if (sinceLastPoll.Minutes > 0) { strSinceLastPoll = String.Format("{0} min(s)", sinceLastPoll.Minutes); } else { strSinceLastPoll = String.Format("{0} sec(s)", sinceLastPoll.Seconds); } tableContent += @"{" + Environment.NewLine + @"""id"": """ + targetId + @"""," + Environment.NewLine + @"""serverName"": """ + Configuration.targets[targetId].name + @"""," + Environment.NewLine + @"""version"": """ + cfgData["Version"].ToString() + @"""," + Environment.NewLine + @"""edition"": """ + cfgData["Edition"].ToString() + @"""," + Environment.NewLine + @"""topWait"": """ + GetMaxValueMultiRowCumulative(targetId, Configuration.metricGroups["SQL Server Wait Stats"], "Wait Time ms", new string[1] { "Wait Type" }) + @"""," + Environment.NewLine + @"""topFileRead"": """ + GetMaxValueMultiRowCumulative(targetId, Configuration.metricGroups["SQL Server File Stats"], "Number of reads", new string[2] { "Database Name", "Logical File Name" }) + @"""," + Environment.NewLine + @"""topFileWrite"": """ + GetMaxValueMultiRowCumulative(targetId, Configuration.metricGroups["SQL Server File Stats"], "Number of writes", new string[2] { "Database Name", "Logical File Name" }) + @"""," + Environment.NewLine + @"""cpu"": """ + cpuIoData["CPU mils"].ToString() + @"""," + Environment.NewLine + @"""ioReads"": """ + cpuIoData["Physical Reads"].ToString() + @"""," + Environment.NewLine + @"""ioWrites"": """ + cpuIoData["Physical Writes"].ToString() + @"""," + Environment.NewLine + @"""lastPoll"": """ + strSinceLastPoll + @"""" + Environment.NewLine + @"},"; } if (Configuration.targets.Keys.Count > 0) { tableContent = tableContent.Remove(tableContent.Length - 1); // remove last comma } tableContent += "]"; return(WebServiceResult.ReturnSuccess(tableContent.Replace(@"\", @"\\"))); }