public SummaryModelHolder GetRawDataFromXml(SummaryModelHolder stats, IEnumerable <XElement> itemsList) { var elementCount = 0; foreach (XElement item in itemsList) { elementCount++; var itemFieldList = from itemAttr in item.Elements() select itemAttr; //Console.WriteLine("* item.name " + item.Name); foreach (XElement itemField in itemFieldList) { //Console.WriteLine("* itemField.Name " + itemField.Name + " value " + itemField.Value); string key = ExtractKey(itemField.Name + " " + itemField.Attribute("channel")); string rawValue = itemField.Value; if (key != null && rawValue != null && rawValue != "") { //Console.WriteLine("Key found is " + key); //Console.WriteLine("rawValue " + rawValue); // get value float floatValue = ExtractFloatValue(rawValue); //Console.WriteLine("floatValue is " + floatValue); AddToRawData(stats, key, floatValue); } } } Console.WriteLine("elementCount is " + elementCount); Console.WriteLine("stat count is " + stats._rawDataHolder.Count()); return(stats); }
private string LoadSummary(SummaryModelHolder holder, IDictionary <string, string> requestParams) { //string title = "Report for ODM Production (i-0c240a85cce740b9e) [EC2] - PRTG Network Monitor"; //string timeRange = "01/01/2019 12:00:00 AM - 01/02/2019 12:00:00 AM"; //string metrics = "Amazon CloudWatch EC2 BETA (15 m Interval)"; string timeRange = requestParams["sdate"] + " - " + requestParams["edate"]; string result = "<h2>" + requestParams["title"] + "</h2>\n" + "<table class=\"table\">\n" + "\t<tbody>\n" + "\t\t<tr>\n" + "\t\t\t<th>Report Time Span:</th>\n" + "\t\t\t<td colspan=\"6\">" + timeRange + "</td>\n" + "\t\t</tr>\n" + "\t\t<tr>\n" + "\t\t\t<th>Sensor Type:</th>\n" + "\t\t\t<td colspan=\"6\">" + requestParams["subtitle"] + "</td>\n" + "\t\t</tr>\n" + "\t\t<tr>\n" + "\t\t\t<th class=\"title\">Uptime Stats:</th>\n" + "\t\t\t<td>Up:</td>\n<td class=\"rightalign\">100 %<div class=\"colorflag colorflag-ok\"> </div></td>\n" + "\t\t\t<td>Down:</td>\n<td class=\"rightalign\">0 %<div class=\"colorflag colorflag-ok\"> </div></td>\n" + "\t\t</tr>\n" + "\t</tbody>\n" + "</table>\n"; return(result); }
private void AddToRawData(SummaryModelHolder holder, string key, float value) { var stats = holder._rawDataHolder; List <float> categoryListOfValues = new List <float>(); bool exists = stats.TryGetValue(key, out categoryListOfValues); // removed && !sValue.Contains(value) if (exists) { // category list exists already so just add categoryListOfValues.Add(value); stats[key] = categoryListOfValues; } else if (!exists) { // category list does not exist yet so create and add categoryListOfValues = categoryListOfValues ?? new List <float>(); categoryListOfValues.Add(value); stats.Add(key, categoryListOfValues); } /* * if (key == "CPU Utilization") { * Console.WriteLine("CPU Utilization is " + value + " exists is " + exists); * } */ }
public SummaryModelHolder CalculateAllSummaryAverages(SummaryModelHolder holder) { // work out averages Console.WriteLine("Get Summary result"); List <string> summaryTitles = holder.GetListOfSummaryTitles(); foreach (string title in summaryTitles) { holder = CalculateSummaryAverageFromRaw(holder, title); } return(holder); }
public SummaryModelHolder CalculateSummaryAverageFromRaw(SummaryModelHolder holder, string key) { IDictionary <string, List <float> > stats = holder._rawDataHolder; IDictionary <string, string> summary = holder._dataSummary; List <float> results = stats[key]; float result = results.Average(); string averageValue = DoFormat((float)Math.Round(result, 2)); holder._dataSummary[key] = averageValue; return(holder); }
public void LoadTemplates(SummaryModelHolder holder, IDictionary <string, string> requestParams) { var result = "<div replace=\"prtg-summary\" class=\"table-responsive\">\n" + LoadSummary(holder, requestParams) + "</div>\n" + "<div replace=\"prtg-img\">\n" + LoadImage(requestParams) + "</div>\n" + "<div replace=\"prtg-stats\" class=\"table-responsive\">\n" + LoadAverages(holder) + "</div>"; formatedHTML = result; }
public string MakeReport(IEnumerable <XElement> itemsList, IDictionary <string, string> requestParams) { SummaryCalculator calculator = new SummaryCalculator(); SummaryHTMLFormatter formatter = new SummaryHTMLFormatter(); SummaryModelHolder model = new SummaryModelHolder(); // get stats from xml model = calculator.GetRawDataFromXml(model, itemsList); // do calculations and get averages etc model = calculator.CalculateAllSummaryAverages(model); // generate html formatter.LoadTemplates(model, requestParams); // return that formatted html return(formatter.GetFormattedHTML()); }
private string LoadAverages(SummaryModelHolder holder) { var result = "<table class=\"table\">\n" + "\t<tbody>\n" + "\t\t<tr>\n" + "\t\t\t<th>CPU Utilization</th>\n" + "\t\t\t<th>Network In</th>\n" + "\t\t\t<th>Network Out</th>\n" + "\t\t\t<th>Read Ops</th>\n" + "\t\t\t<th>Write Ops</th>\n" + "\t\t\t<th>Disk Read</th>\n" + "\t\t\t<th>Disk Write</th>\n" + "\t\t\t<th>CPU Credit Usage</th>\n" + "\t\t\t<th>CPU Credit Balance</th>\n" + "\t\t\t<th>Status (Ok)</th>\n" + "\t\t\t<th>Status (Instance) (Ok)</th>\n" + "\t\t\t<th>Status (System) (Ok)</th>\n" + "\t\t\t<th>Downtime</th>\n" + "\t\t</tr>\n" + "\t\t<tr>\n" + "\t\t\t<td>" + holder._dataSummary["CPU Utilization"] + " %</td>\n" + "\t\t\t<td>" + holder._dataSummary["Network In"] + " kbit/s</td>\n" + "\t\t\t<td>" + holder._dataSummary["Network Out"] + " kbit/s</td>\n" + "\t\t\t<td>" + holder._dataSummary["Read Ops"] + " #/s</td>\n" + "\t\t\t<td>" + holder._dataSummary["Write Ops"] + " #/s</td>\n" + "\t\t\t<td>" + holder._dataSummary["Disk Read"] + " Mbit/s</td>\n" + "\t\t\t<td>" + holder._dataSummary["Disk Write"] + " Mbit/s</td>\n" + "\t\t\t<td>" + holder._dataSummary["CPU Credit Usage"] + " #</td>\n" + "\t\t\t<td>" + holder._dataSummary["CPU Credit Balance"] + " #</td>\n" + "\t\t\t<td>" + holder._dataSummary["Status (Ok)"] + " %</td>\n" + "\t\t\t<td>" + holder._dataSummary["Status (Instance) (Ok)"] + " %</td>\n" + "\t\t\t<td>" + holder._dataSummary["Status (System) (Ok)"] + " %</td>\n" + "\t\t\t<td>" + holder._dataSummary["Downtime"] + " %</td>\n" + "\t\t</tr>\n" + "\t</tbody>\n" + "</table>\n"; return(result); }