public void Build() { LoadTestDatabase db = new LoadTestDatabase(this.enviroment.ConnectionString); //SQLDB db = new SQLDB(this.enviroment.SQLConfig.Server, this.enviroment.SQLConfig.Database, this.enviroment.SQLConfig.Username, this.enviroment.SQLConfig.Password); //db.openDB(); //tempDir = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); tempDir = reportDir; if (tempDir.Exists) { tempDir.Create(); } ZIPUtil.DecompressData(FileResources.ReportZIPData(), tempDir); String errorFile = Path.Combine(tempDir.FullName, "error.log"); Int64 VU = 0; Int64 connections = 0; Int64 throughput = 0; Int64 bytesReceived = 0; Int64 requests = 0; Int64 rps = 0; StringBuilder js = new StringBuilder(); js.AppendLine("jQuery(document).ready(function ($) {"); String html = ""; List <String> labels = new List <String>(); List <String> values = new List <String>(); List <String> values2 = new List <String>(); DateTime date = enviroment.dStart; Int64 value = 0; DataTable dtTmp = db.selectGeneral(enviroment.TestName, enviroment.dStart, enviroment.dEnd); if (dtTmp.Rows.Count > 0) { VU = (Int64)dtTmp.Rows[0]["vu"]; connections = (Int64)dtTmp.Rows[0]["connections"]; throughput = (Int64)dtTmp.Rows[0]["throughput"]; bytesReceived = (Int64)dtTmp.Rows[0]["bytesReceived"]; requests = (Int64)dtTmp.Rows[0]["requests"]; rps = (Int64)dtTmp.Rows[0]["rps"]; } //Graficos de monitoramento Zabbix StringBuilder extra = new StringBuilder(); DataTable dtZabbix = db.selectMonitoredZabbix(enviroment.TestName, enviroment.dStart, enviroment.dEnd); Dictionary <String, String> zbxHosts = new Dictionary <string, string>(); if (dtZabbix != null) { foreach (DataRow dr in dtZabbix.Rows) { String name = dr["host"].ToString(); try { foreach (SafeTrend.Data.ZabbixConfig cfg in enviroment.ZabbixMonitors) { if (cfg.Host == name) { name = cfg.Name; } } } catch { } zbxHosts.Add(dr["host"].ToString(), name); } } //Ordena pelo nome do host zbxHosts = zbxHosts.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value); foreach (String host in zbxHosts.Keys) { try { String key = Guid.NewGuid().ToString().Trim(" {}".ToCharArray()).Replace("-", ""); String name = zbxHosts[host].ToString(); extra.AppendLine("<div class=\"full-line topspace\">"); extra.AppendLine("<h2>" + name + " - CPU (%)</h2>"); extra.AppendLine("</div>"); extra.AppendLine("<div class=\"data1 data2 full-line\">"); extra.AppendLine("<div class=\"chartcontent\"><canvas id=\"" + key + "_cpu\" width=\"921\" height=\"150\"></canvas></div>"); extra.AppendLine("<div class=\"clearfix\"></div>"); extra.AppendLine("</div>"); extra.AppendLine(""); extra.AppendLine("<div class=\"full-line topspace\">"); extra.AppendLine("<h2>" + name + " - CPU (Load Average - 1 min)</h2>"); extra.AppendLine("</div>"); extra.AppendLine("<div class=\"data1 data2 full-line\">"); extra.AppendLine("<div class=\"chartcontent\"><canvas id=\"" + key + "_cpuload\" width=\"921\" height=\"150\"></canvas></div>"); extra.AppendLine("<div class=\"clearfix\"></div>"); extra.AppendLine("</div>"); extra.AppendLine(""); extra.AppendLine("<div class=\"full-line topspace\">"); extra.AppendLine("<h2>" + name + " - Memoria (Gb)</h2>"); extra.AppendLine("</div>"); extra.AppendLine("<div class=\"data1 data2 full-line\">"); extra.AppendLine("<div class=\"chartcontent\"><canvas id=\"" + key + "_memory\" width=\"921\" height=\"150\"></canvas></div>"); extra.AppendLine("<div class=\"clearfix\"></div>"); extra.AppendLine("</div>"); extra.AppendLine(""); dtTmp = db.selectZabbixNetIfs(enviroment.TestName, host, enviroment.dStart, enviroment.dEnd); foreach (DataRow drNN in dtTmp.Rows) { String kName = GetMd5Hash(key + drNN["name"].ToString().Replace(" ", "")); extra.AppendLine("<div class=\"full-line topspace\">"); extra.AppendLine("<h2>" + name + " - " + drNN["name"] + " (mbps)</h2>"); extra.AppendLine("</div>"); extra.AppendLine("<div class=\"data1 data2 full-line\">"); extra.AppendLine("<div class=\"chartcontent\"><canvas id=\"" + kName + "_if\" width=\"921\" height=\"150\"></canvas></div>"); extra.AppendLine("<div class=\"clearfix\"></div>"); extra.AppendLine("</div>"); extra.AppendLine(""); labels.Clear(); values.Clear(); values2.Clear(); labels.Add("Início"); values.Add("0"); values2.Add("0"); date = enviroment.dStart; value = 0; dtTmp = db.selectZabbixNetworkTraffic(enviroment.TestName, host, drNN["name"].ToString(), enviroment.dStart, enviroment.dEnd); foreach (DataRow drN in dtTmp.Rows) { date = DateTime.Parse(drN["dateg"].ToString()); labels.Add(date.ToString("HH:mm")); value = (Int64)drN["in_value"]; values.Add(((value * 8) / 1024 / 1024).ToString()); value = (Int64)drN["out_value"]; values2.Add(((value * 8) / 1024 / 1024).ToString()); } date.AddMinutes(1); labels.Add("Final"); values.Add("0"); values2.Add("0"); js.AppendLine("var data1 = {"); js.AppendLine(" labels: ['" + String.Join("','", labels) + "'],"); js.AppendLine(" datasets: ["); js.AppendLine(" {"); js.AppendLine(" label: \"Input\","); js.AppendLine(" fillColor: \"rgba(220,220,220,0.2)\","); js.AppendLine(" strokeColor: \"rgba(220,220,220,1)\","); js.AppendLine(" pointColor: \"rgba(220,220,220,1)\","); js.AppendLine(" pointStrokeColor: \"#fff\","); js.AppendLine(" pointHighlightFill: \"#fff\","); js.AppendLine(" pointHighlightStroke: \"rgba(220,220,220,1)\","); js.AppendLine(" data: [" + String.Join(",", values) + "]"); js.AppendLine(" },"); js.AppendLine(" {"); js.AppendLine(" label: \"Output\","); js.AppendLine(" fillColor: \"rgba(151,187,205,0.5)\","); js.AppendLine(" strokeColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointStrokeColor: \"#fff\","); js.AppendLine(" data: [" + String.Join(",", values2) + "]"); js.AppendLine(" }"); js.AppendLine(" ]"); js.AppendLine("}"); js.AppendLine("var theCanvas = $('#" + kName + "_if').get(0);"); js.AppendLine("var ctx = theCanvas.getContext(\"2d\");"); js.AppendLine("var myNewChart = new Chart(ctx).Line(data1, null);"); } labels.Clear(); values.Clear(); values2.Clear(); labels.Add("Início"); values.Add("0"); values2.Add("0"); date = enviroment.dStart; value = 0; dtTmp = db.selectZabbixCPU(enviroment.TestName, host, enviroment.dStart, enviroment.dEnd); foreach (DataRow drH in dtTmp.Rows) { date = DateTime.Parse(drH["dateg"].ToString()); value = (Int64)drH["cpu"]; labels.Add(date.ToString("HH:mm")); values.Add(value.ToString()); } date.AddMinutes(1); labels.Add("Final"); values.Add("0"); js.AppendLine("var data1 = {"); js.AppendLine(" labels: ['" + String.Join("','", labels) + "'],"); js.AppendLine(" datasets: ["); js.AppendLine(" {"); js.AppendLine(" fillColor: \"rgba(151,187,205,0.5)\","); js.AppendLine(" strokeColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointStrokeColor: \"#fff\","); js.AppendLine(" data: [" + String.Join(",", values) + "]"); js.AppendLine(" }"); js.AppendLine(" ]"); js.AppendLine("}"); js.AppendLine("var theCanvas = $('#" + key + "_cpu').get(0);"); js.AppendLine("var ctx = theCanvas.getContext(\"2d\");"); js.AppendLine("var myNewChart = new Chart(ctx).Line(data1, null);"); //Load AVG labels.Clear(); values.Clear(); labels.Add("Início"); values.Add("0"); values2.Add("0"); date = enviroment.dStart; value = 0; dtTmp = db.selectZabbixCPULoad(enviroment.TestName, host, enviroment.dStart, enviroment.dEnd); foreach (DataRow drH in dtTmp.Rows) { date = DateTime.Parse(drH["dateg"].ToString()); value = (Int64)drH["load"]; labels.Add(date.ToString("HH:mm")); values.Add(value.ToString()); } date.AddMinutes(1); labels.Add("Final"); values.Add("0"); js.AppendLine("var data1 = {"); js.AppendLine(" labels: ['" + String.Join("','", labels) + "'],"); js.AppendLine(" datasets: ["); js.AppendLine(" {"); js.AppendLine(" fillColor: \"rgba(151,187,205,0.5)\","); js.AppendLine(" strokeColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointStrokeColor: \"#fff\","); js.AppendLine(" data: [" + String.Join(",", values) + "]"); js.AppendLine(" }"); js.AppendLine(" ]"); js.AppendLine("}"); js.AppendLine("var theCanvas = $('#" + key + "_cpuload').get(0);"); js.AppendLine("var ctx = theCanvas.getContext(\"2d\");"); js.AppendLine("var myNewChart = new Chart(ctx).Line(data1, null);"); //Memoria labels.Clear(); values.Clear(); values2.Clear(); labels.Add("Início"); values.Add("0"); values2.Add("0"); date = enviroment.dStart; value = 0; dtTmp = db.selectZabbixMemory(enviroment.TestName, host, enviroment.dStart, enviroment.dEnd); foreach (DataRow drH in dtTmp.Rows) { date = DateTime.Parse(drH["dateg"].ToString()); labels.Add(date.ToString("HH:mm")); values.Add((((Int64)drH["total_memory"]) / 1024 / 1024 / 1024).ToString()); values2.Add((((Int64)drH["memory"]) / 1024 / 1024 / 1024).ToString()); } date.AddMinutes(1); labels.Add("Final"); values.Add("0"); values2.Add("0"); js.AppendLine("var data1 = {"); js.AppendLine(" labels: ['" + String.Join("','", labels) + "'],"); js.AppendLine(" datasets: ["); js.AppendLine(" {"); js.AppendLine(" label: \"Total\","); js.AppendLine(" fillColor: \"rgba(220,220,220,0.2)\","); js.AppendLine(" strokeColor: \"rgba(220,220,220,1)\","); js.AppendLine(" pointColor: \"rgba(220,220,220,1)\","); js.AppendLine(" pointStrokeColor: \"#fff\","); js.AppendLine(" pointHighlightFill: \"#fff\","); js.AppendLine(" pointHighlightStroke: \"rgba(220,220,220,1)\","); js.AppendLine(" data: [" + String.Join(",", values) + "]"); js.AppendLine(" },"); js.AppendLine(" {"); js.AppendLine(" label: \"Usada\","); js.AppendLine(" fillColor: \"rgba(151,187,205,0.5)\","); js.AppendLine(" strokeColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointStrokeColor: \"#fff\","); js.AppendLine(" data: [" + String.Join(",", values2) + "]"); js.AppendLine(" }"); js.AppendLine(" ]"); js.AppendLine("}"); js.AppendLine("var theCanvas = $('#" + key + "_memory').get(0);"); js.AppendLine("var ctx = theCanvas.getContext(\"2d\");"); js.AppendLine("var myNewChart = new Chart(ctx).Line(data1, null);"); } catch (Exception ex) { File.WriteAllBytes(errorFile, Encoding.UTF8.GetBytes(ex.Message + ex.StackTrace)); } } File.WriteAllBytes(Path.Combine(tempDir.FullName, "index.html"), Encoding.UTF8.GetBytes(FileResources.GetIndexText(this.enviroment.TestName, this.enviroment, VU, connections, throughput, bytesReceived, requests, rps, extra.ToString()))); DirectoryInfo jsDir = new DirectoryInfo(Path.Combine(tempDir.FullName, "js")); try { jsDir.Create(); } catch { } //Mensagens // dtTmp = db.selectMessages(enviroment.TestName, enviroment.dStart, enviroment.dEnd); if ((dtTmp == null) || (dtTmp.Rows.Count == 0)) { js.AppendLine("$('#message thead th').html('Nenhuma mensagem gerada pelo sistema');"); } else { foreach (DataRow dr in dtTmp.Rows) { html += "<div class=\"title\">" + dr["title"] + "</div><div class=\"message\">" + dr["text"].ToString().Replace("\r\n", "<br />") + "</div>"; } js.AppendLine("$('#message thead th').html('" + html + "');"); } //Tabela de otimização dtTmp = db.selectOptimization(enviroment.TestName, enviroment.dStart, enviroment.dEnd); if (dtTmp.Rows.Count > 0) { html = ""; Int64 tOriginalLength = 0; Int64 tOptimizedLength = 0; foreach (DataRow dr in dtTmp.Rows) { Int64 originalLength = (Int64)dr["originalLength"]; Int64 optimizedLength = (Int64)dr["optimizedLength"]; tOriginalLength += originalLength; tOptimizedLength += optimizedLength; double percent = 100F - (((double)optimizedLength / (double)originalLength) * 100F); html += "<tr><td>" + dr["uri"].ToString() + "</td><td>" + FileResources.formatData(originalLength, ChartDataType.Bytes) + "</td><td>" + FileResources.formatData(optimizedLength, ChartDataType.Bytes) + "</td><td>" + FileResources.formatData(percent, ChartDataType.Percent) + "</td></tr>"; } if (html != "") { double percent2 = 100F - (((double)tOptimizedLength / (double)tOriginalLength) * 100F); html += "<tr><td>Total de otimização a se realizar</td><td>" + FileResources.formatData(tOriginalLength, ChartDataType.Bytes) + "</td><td>" + FileResources.formatData(tOptimizedLength, ChartDataType.Bytes) + "</td><td>" + FileResources.formatData(percent2, ChartDataType.Percent) + "</td></tr>"; js.AppendLine("$('#optimization-table tbody').html('" + html + "');"); } else { js.AppendLine("$('#optimization-table').remove();"); } } else { js.AppendLine("$('#optimization-table').remove();"); } //Tabela de Não Otimização (Ou seja os objetos que ja estão otimizados) dtTmp = db.selectNonOptimization(enviroment.TestName, enviroment.dStart, enviroment.dEnd); if (dtTmp.Rows.Count > 0) { html = ""; Int64 tOriginalLength = 0; Int64 tNonOptimizedLength = 0; foreach (DataRow dr in dtTmp.Rows) { Int64 originalLength = (Int64)dr["originalLength"]; Int64 nonOptimizedLength = (Int64)dr["nonOptimizedLength"]; tOriginalLength += originalLength; tNonOptimizedLength += nonOptimizedLength; double percent = 100F - (((double)originalLength / (double)nonOptimizedLength) * 100F); html += "<tr><td>" + dr["uri"].ToString() + "</td><td>" + FileResources.formatData(originalLength, ChartDataType.Bytes) + "</td><td>" + FileResources.formatData(nonOptimizedLength, ChartDataType.Bytes) + "</td><td>" + FileResources.formatData(percent, ChartDataType.Percent) + "</td></tr>"; } if (html != "") { double percent2 = 100F - (((double)tOriginalLength / (double)tNonOptimizedLength) * 100F); html += "<tr><td>Total de otimização existente</td><td>" + FileResources.formatData(tOriginalLength, ChartDataType.Bytes) + "</td><td>" + FileResources.formatData(tNonOptimizedLength, ChartDataType.Bytes) + "</td><td>" + FileResources.formatData(percent2, ChartDataType.Percent) + "</td></tr>"; js.AppendLine("$('#nonoptimization-table tbody').html('" + html + "');"); } else { js.AppendLine("$('#nonoptimization-table').remove();"); } } else { js.AppendLine("$('#nonoptimization-table').remove();"); } //Tabela de otimização GZIP/Deflate dtTmp = db.selecGzipOptimization(enviroment.TestName, enviroment.dStart, enviroment.dEnd); if (dtTmp.Rows.Count > 0) { html = ""; Int64 tGzipLength = 0; Int64 tContentLength = 0; foreach (DataRow dr in dtTmp.Rows) { Int64 gzipLength = (Int64)dr["gzipLength"]; Int64 contentLength = (Int64)dr["contentLength"]; tGzipLength += gzipLength; tContentLength += contentLength; double percent = 100F - (((double)gzipLength / (double)contentLength) * 100F); html += "<tr><td>" + dr["uri"].ToString() + "</td><td>" + FileResources.formatData(contentLength, ChartDataType.Bytes) + "</td><td>" + FileResources.formatData(gzipLength, ChartDataType.Bytes) + "</td><td>" + FileResources.formatData(percent, ChartDataType.Percent) + "</td></tr>"; } if (html != "") { double percent2 = 100F - (((double)tGzipLength / (double)tContentLength) * 100F); html += "<tr><td>Total de compactação utilizada</td><td>" + FileResources.formatData(tContentLength, ChartDataType.Bytes) + "</td><td>" + FileResources.formatData(tGzipLength, ChartDataType.Bytes) + "</td><td>" + FileResources.formatData(percent2, ChartDataType.Percent) + "</td></tr>"; js.AppendLine("$('#gzip-table tbody').html('" + html + "');"); } else { js.AppendLine("$('#gzip-table').remove();"); } } else { js.AppendLine("$('#gzip-table').remove();"); } // //Chart 1 (Usuários virtuais (VU) ativos) labels.Clear(); values.Clear(); dtTmp = db.selectVUAndConnections(enviroment.TestName, enviroment.dStart, enviroment.dEnd); labels.Add("Início"); values.Add("0"); foreach (DataRow dr in dtTmp.Rows) { date = DateTime.Parse(dr["dateg"].ToString()); value = (Int64)dr["virtualusers"]; labels.Add(date.ToString("HH:mm")); values.Add(value.ToString()); } date.AddMinutes(1); labels.Add("Final"); values.Add("0"); js.AppendLine("var data1 = {"); js.AppendLine(" labels: ['" + String.Join("','", labels) + "'],"); js.AppendLine(" datasets: ["); js.AppendLine(" {"); js.AppendLine(" fillColor: \"rgba(151,187,205,0.5)\","); js.AppendLine(" strokeColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointStrokeColor: \"#fff\","); js.AppendLine(" data: [" + String.Join(",", values) + "]"); js.AppendLine(" }"); js.AppendLine(" ]"); js.AppendLine("}"); js.AppendLine("var theCanvas = $('#c1').get(0);"); js.AppendLine("var ctx = theCanvas.getContext(\"2d\");"); js.AppendLine("var myNewChart = new Chart(ctx).Line(data1, null);"); //Chart 2 (Conexões TCP ativas) labels.Clear(); values.Clear(); labels.Add("Início"); values.Add("0"); date = enviroment.dStart; value = 0; foreach (DataRow dr in dtTmp.Rows) { date = DateTime.Parse(dr["dateg"].ToString()); value = (Int64)dr["connections"]; labels.Add(date.ToString("HH:mm")); values.Add(value.ToString()); } date.AddMinutes(1); labels.Add("Final"); values.Add("0"); js.AppendLine("var data2 = {"); js.AppendLine(" labels: ['" + String.Join("','", labels) + "'],"); js.AppendLine(" datasets: ["); js.AppendLine(" {"); js.AppendLine(" fillColor: \"rgba(151,187,205,0.5)\","); js.AppendLine(" strokeColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointStrokeColor: \"#fff\","); js.AppendLine(" data: [" + String.Join(",", values) + "]"); js.AppendLine(" }"); js.AppendLine(" ]"); js.AppendLine("}"); js.AppendLine("var theCanvas = $('#c2').get(0);"); js.AppendLine("var ctx = theCanvas.getContext(\"2d\");"); js.AppendLine("var myNewChart = new Chart(ctx).Line(data2, null);"); //Chart 3 (Requisições) labels.Clear(); values.Clear(); dtTmp = db.selectRequests(enviroment.TestName, enviroment.dStart, enviroment.dEnd); labels.Add("Início"); values.Add("0"); Dictionary <String, Int64> dicErrors = new Dictionary <string, long>(); date = enviroment.dStart; value = 0; foreach (DataRow dr in dtTmp.Rows) { date = DateTime.Parse(dr["dateg"].ToString()); value = (Int64)dr["rps"]; labels.Add(date.ToString("HH:mm")); values.Add(value.ToString()); //Preenche o dicionario de erros para ficar alinhado com o de requisicoes if (!dicErrors.ContainsKey(date.ToString("HH:mm"))) { dicErrors.Add(date.ToString("HH:mm"), 0); } } date.AddMinutes(1); labels.Add("Final"); values.Add("0"); js.AppendLine("var data3 = {"); js.AppendLine(" labels: ['" + String.Join("','", labels) + "'],"); js.AppendLine(" datasets: ["); js.AppendLine(" {"); js.AppendLine(" fillColor: \"rgba(151,187,205,0.5)\","); js.AppendLine(" strokeColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointStrokeColor: \"#fff\","); js.AppendLine(" data: [" + String.Join(",", values) + "]"); js.AppendLine(" }"); js.AppendLine(" ]"); js.AppendLine("}"); js.AppendLine("var theCanvas = $('#c3').get(0);"); js.AppendLine("var ctx = theCanvas.getContext(\"2d\");"); js.AppendLine("var myNewChart = new Chart(ctx).Line(data3, null);"); //Chart 4 (Errors) labels.Clear(); values.Clear(); dtTmp = db.selectErrors(enviroment.TestName, enviroment.dStart, enviroment.dEnd); labels.Add("Início"); values.Add("0"); date = enviroment.dStart; value = 0; foreach (DataRow dr in dtTmp.Rows) { date = DateTime.Parse(dr["dateg"].ToString()); value = (Int64)dr["errors"]; if (dicErrors.ContainsKey(date.ToString("HH:mm"))) { dicErrors[date.ToString("HH:mm")] = value; } else { dicErrors.Add(date.ToString("HH:mm"), 0); } } foreach (String k in dicErrors.Keys) { labels.Add(k); values.Add(dicErrors[k].ToString()); } date.AddMinutes(1); labels.Add("Final"); values.Add("0"); js.AppendLine("var data4 = {"); js.AppendLine(" labels: ['" + String.Join("','", labels) + "'],"); js.AppendLine(" datasets: ["); js.AppendLine(" {"); js.AppendLine(" fillColor: \"rgba(151,187,205,0.5)\","); js.AppendLine(" strokeColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointStrokeColor: \"#fff\","); js.AppendLine(" data: [" + String.Join(",", values) + "]"); js.AppendLine(" }"); js.AppendLine(" ]"); js.AppendLine("}"); js.AppendLine("var theCanvas = $('#c4').get(0);"); js.AppendLine("var ctx = theCanvas.getContext(\"2d\");"); js.AppendLine("var myNewChart = new Chart(ctx).Line(data4, null);"); //Chart 5 (Bandwidth (Mbps)) labels.Clear(); values.Clear(); dtTmp = db.selectThroughput(enviroment.TestName, enviroment.dStart, enviroment.dEnd); labels.Add("Início"); values.Add("0"); date = enviroment.dStart; value = 0; foreach (DataRow dr in dtTmp.Rows) { date = DateTime.Parse(dr["dateg"].ToString()); value = (Int64)dr["mbps"]; labels.Add(date.ToString("HH:mm")); values.Add((value / 1024 / 1024).ToString()); //values.Add(value.ToString()); } date.AddMinutes(1); labels.Add("Final"); values.Add("0"); js.AppendLine("var data5 = {"); js.AppendLine(" labels: ['" + String.Join("','", labels) + "'],"); js.AppendLine(" datasets: ["); js.AppendLine(" {"); js.AppendLine(" fillColor: \"rgba(151,187,205,0.5)\","); js.AppendLine(" strokeColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointStrokeColor: \"#fff\","); js.AppendLine(" data: [" + String.Join(",", values) + "]"); js.AppendLine(" }"); js.AppendLine(" ]"); js.AppendLine("}"); js.AppendLine("var theCanvas = $('#c5').get(0);"); js.AppendLine("var ctx = theCanvas.getContext(\"2d\");"); js.AppendLine("var myNewChart = new Chart(ctx).Line(data5, null);"); //Chart 6 (Tempo de resposta geral) labels.Clear(); values.Clear(); dtTmp = db.selectResponseTime(enviroment.TestName, enviroment.dStart, enviroment.dEnd, null); labels.Add("Início"); values.Add("0"); date = enviroment.dStart; value = 0; foreach (DataRow dr in dtTmp.Rows) { date = DateTime.Parse(dr["dateg"].ToString()); value = (Int64)dr["time"]; labels.Add(date.ToString("HH:mm")); values.Add(value.ToString()); } date.AddMinutes(1); labels.Add("Final"); values.Add("0"); js.AppendLine("var data6 = {"); js.AppendLine(" labels: ['" + String.Join("','", labels) + "'],"); js.AppendLine(" datasets: ["); js.AppendLine(" {"); js.AppendLine(" fillColor: \"rgba(151,187,205,0.5)\","); js.AppendLine(" strokeColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointStrokeColor: \"#fff\","); js.AppendLine(" data: [" + String.Join(",", values) + "]"); js.AppendLine(" }"); js.AppendLine(" ]"); js.AppendLine("}"); js.AppendLine("var theCanvas = $('#rp1').get(0);"); js.AppendLine("var ctx = theCanvas.getContext(\"2d\");"); js.AppendLine("var myNewChart = new Chart(ctx).Line(data6, null);"); //Chart 7 (Tempo de resposta geral) labels.Clear(); values.Clear(); dtTmp = db.selectResponseTime(enviroment.TestName, enviroment.dStart, enviroment.dEnd, enviroment.BaseUri); labels.Add("Início"); values.Add("0"); date = enviroment.dStart; value = 0; foreach (DataRow dr in dtTmp.Rows) { date = DateTime.Parse(dr["dateg"].ToString()); value = (Int64)dr["time"]; labels.Add(date.ToString("HH:mm")); values.Add(value.ToString()); } date.AddMinutes(1); labels.Add("Final"); values.Add("0"); js.AppendLine("var data7 = {"); js.AppendLine(" labels: ['" + String.Join("','", labels) + "'],"); js.AppendLine(" datasets: ["); js.AppendLine(" {"); js.AppendLine(" fillColor: \"rgba(151,187,205,0.5)\","); js.AppendLine(" strokeColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointColor: \"rgba(151,187,205,1)\","); js.AppendLine(" pointStrokeColor: \"#fff\","); js.AppendLine(" data: [" + String.Join(",", values) + "]"); js.AppendLine(" }"); js.AppendLine(" ]"); js.AppendLine("}"); js.AppendLine("var theCanvas = $('#rp2').get(0);"); js.AppendLine("var ctx = theCanvas.getContext(\"2d\");"); js.AppendLine("var myNewChart = new Chart(ctx).Line(data7, null);"); //Chart 8 (Tempo de carga por conteúdo) labels.Clear(); values.Clear(); dtTmp = db.selectContentTypeDistribution(enviroment.TestName, enviroment.dStart, enviroment.dEnd); date = enviroment.dStart; value = 0; foreach (DataRow dr in dtTmp.Rows) { value = (Int64)dr["qty"]; Int64 total = (Int64)dr["total"]; labels.Add(dr["contentType"].ToString() + ": " + value + " (" + ((Int64)(((double)value / (double)total) * 100)) + "%)"); values.Add(value.ToString()); } js.AppendLine("var radar = new RGraph.Radar('ctd',[" + String.Join(",", values) + "])"); js.AppendLine(" .Set('strokestyle', 'black')"); js.AppendLine(" .Set('colors.alpha', 0.3)"); js.AppendLine(" .Set('colors', ['rgba(151,187,205,0.5)'])"); js.AppendLine(" .Set('labels', ['" + String.Join("','", labels) + "'])"); js.AppendLine(" .Set('labels.axes', '')"); js.AppendLine(" .Set('gutter.top', 35)"); js.AppendLine(" .Set('accumulative', true)"); js.AppendLine(" .Set('axes.color', 'rgba(0,0,0,0)')"); js.AppendLine(" .Set('background.circles.poly', true)"); js.AppendLine(" .Set('background.circles.spacing', 25)"); js.AppendLine(" .Draw();"); //Chart 9 (Tempo de carga por conteúdo) labels.Clear(); values.Clear(); dtTmp = db.selectContentTypeTimeDistribution(enviroment.TestName, enviroment.dStart, enviroment.dEnd); date = enviroment.dStart; value = 0; foreach (DataRow dr in dtTmp.Rows) { value = (Int64)dr["time"]; Int64 total = (Int64)dr["total"]; labels.Add(dr["contentType"].ToString() + ": " + value + "ms (" + ((Int64)(((double)value / (double)total) * 100)) + "%)"); values.Add(value.ToString()); } js.AppendLine("var radar = new RGraph.Radar('ctt',[" + String.Join(",", values) + "])"); js.AppendLine(" .Set('strokestyle', 'black')"); js.AppendLine(" .Set('colors.alpha', 0.3)"); js.AppendLine(" .Set('colors', ['rgba(151,187,205,0.5)'])"); js.AppendLine(" .Set('labels', ['" + String.Join("','", labels) + "'])"); js.AppendLine(" .Set('labels.axes', '')"); js.AppendLine(" .Set('gutter.top', 35)"); js.AppendLine(" .Set('accumulative', true)"); js.AppendLine(" .Set('axes.color', 'rgba(0,0,0,0)')"); js.AppendLine(" .Set('background.circles.poly', true)"); js.AppendLine(" .Set('background.circles.spacing', 25)"); js.AppendLine(" .Draw();"); //content-trafic labels.Clear(); values.Clear(); dtTmp = db.selectContentTypeBytes(enviroment.TestName, enviroment.dStart, enviroment.dEnd); date = enviroment.dStart; value = 0; foreach (DataRow dr in dtTmp.Rows) { value = (Int64)dr["bytesReceived"]; Int64 total = (Int64)dr["total"]; labels.Add(dr["contentType"].ToString() + ": " + FileResources.formatData(value, ChartDataType.Bytes) + " (" + ((Int64)(((double)value / (double)total) * 100)) + "%)"); values.Add(value.ToString()); } js.AppendLine("var radar = new RGraph.Radar('content-bytes',[" + String.Join(",", values) + "])"); js.AppendLine(" .Set('strokestyle', 'black')"); js.AppendLine(" .Set('colors.alpha', 0.3)"); js.AppendLine(" .Set('colors', ['rgba(151,187,205,0.5)'])"); js.AppendLine(" .Set('labels', ['" + String.Join("','", labels) + "'])"); js.AppendLine(" .Set('labels.axes', '')"); js.AppendLine(" .Set('gutter.top', 35)"); js.AppendLine(" .Set('accumulative', true)"); js.AppendLine(" .Set('axes.color', 'rgba(0,0,0,0)')"); js.AppendLine(" .Set('background.circles.poly', true)"); js.AppendLine(" .Set('background.circles.spacing', 25)"); js.AppendLine(" .Draw();"); //Table 1 dtTmp = db.selectTopHit(enviroment.TestName, enviroment.dStart, enviroment.dEnd); html = ""; foreach (DataRow dr in dtTmp.Rows) { html += "<tr><td>" + dr["uri"].ToString() + "</td><td>" + dr["success"].ToString() + "</td><td>" + dr["error"].ToString() + "</td></tr>"; } js.AppendLine("$('#dist-uri tbody').html('" + html + "');"); //Table 2 dtTmp = db.selectTopTime(enviroment.TestName, enviroment.dStart, enviroment.dEnd); html = ""; foreach (DataRow dr in dtTmp.Rows) { html += "<tr><td>" + dr["uri"].ToString() + "</td><td>" + dr["contentType"].ToString() + "</td><td>" + dr["time"].ToString() + "</td></tr>"; } js.AppendLine("$('#time-uri tbody').html('" + html + "');"); //Table 3 dtTmp = db.selectTopBytes(enviroment.TestName, enviroment.dStart, enviroment.dEnd); html = ""; foreach (DataRow dr in dtTmp.Rows) { html += "<tr><td>" + dr["uri"].ToString() + "</td><td>" + dr["qty"].ToString() + "</td><td>" + FileResources.formatData((Int64)(dr["bytesReceived"]), ChartDataType.Bytes) + "</td></tr>"; } js.AppendLine("$('#bytes-uri tbody').html('" + html + "');"); js.AppendLine("});"); File.WriteAllBytes(Path.Combine(jsDir.FullName, "loadtest.report.js"), Encoding.UTF8.GetBytes(js.ToString())); db.Dispose(); //Espera para liberar o arquivo //System.Threading.Thread.Sleep(5000); //Gera o final /* * try * { * ZIPUtil.CompressToFile(tempDir, Path.Combine(reportDir.FullName, DateTime.Now.ToString("yyyyMMddHHmm") + ".zip")); * } * catch (Exception ex) * { * Console.WriteLine("Falha ao gerar o ZIP " + ex.Message); * * foreach (FileInfo f in tempDir.GetFiles()) * { * try * { * f.CopyTo(Path.Combine(reportDir.FullName, f.Name), true); * } * catch (Exception ex1) * { * Console.WriteLine("Falha ao copiar o arquivo " + f.Name + ex1.Message); * } * } * * foreach (DirectoryInfo d in tempDir.GetDirectories()) * CopyTo(tempDir, d, reportDir); * }*/ }
private void AnalizeURI(LoadTestDatabase db, UriInfo u) { switch (GetExtension(u.Target)) { case ".txt": //Sai sem analizar return; break; } Console.WriteLine("ContentAnalizer> " + u.Target); Console.Write("\tBaixando: "); ResultData request = Request.GetRequest(u.Target, this.Proxy, false, HTTPHeaders); if (request.Error) { Console.WriteLine("Err " + request.ErrorMessage); db.insertMessages(this.TestName, "3. Erro na chamada de URL", "URL: <a href=\"" + u.Target.AbsoluteUri + "\" target=\"_blank\">" + u.Target.AbsoluteUri + "</a>" + Environment.NewLine + (u.Referer != null ? "Referer: <a href=\"" + u.Referer.AbsoluteUri + "\" target=\"_blank\">" + u.Referer.AbsoluteUri + "</a>" + Environment.NewLine : "") + Environment.NewLine + "Tempo de resposta: " + FileResources.formatData(request.Time.TotalMilliseconds, ChartDataType.Integer) + "ms " + Environment.NewLine + "Código de retorno HTTP: " + request.Code + Environment.NewLine + Environment.NewLine + (!String.IsNullOrEmpty(request.ErrorMessage) ? "Texto do erro: " + request.ErrorMessage : "")); } else { Console.WriteLine("OK " + request.DataLength); Console.Write("\tVerificando: "); //Tempo de resposta if (request.Time.TotalMilliseconds > 1500F) { db.insertMessages(this.TestName, "2. Alto tempo de resposta", "URL: <a href=\"" + u.Target.AbsoluteUri + "\" target=\"_blank\">" + u.Target.AbsoluteUri + "</a>" + Environment.NewLine + (u.Referer != null ? "Referer: <a href=\"" + u.Referer.AbsoluteUri + "\" target=\"_blank\">" + u.Referer.AbsoluteUri + "</a>" + Environment.NewLine : "") + Environment.NewLine + "Tempo de resposta: " + FileResources.formatData(request.Time.TotalMilliseconds, ChartDataType.Integer) + " ms"); } String extension = GetExtension(u.Target); if (!MIMECheck.CheckMime(request.ContentType.ToLower(), extension)) { db.insertMessages(this.TestName, "4. ContentType inválido", "URL: <a href=\"" + u.Target.AbsoluteUri + "\" target=\"_blank\">" + u.Target.AbsoluteUri + "</a>" + Environment.NewLine + (u.Referer != null ? "Referer: <a href=\"" + u.Referer.AbsoluteUri + "\" target=\"_blank\">" + u.Referer.AbsoluteUri + "</a>" + Environment.NewLine : "") + Environment.NewLine + "Extensão: " + extension + Environment.NewLine + "MIME Type: " + request.ContentType); } if ((request.OriginalDataLength > 0) && (request.OriginalDataLength < request.DataLength)) { db.insertGzipOptimization(this.TestName, request.RequestUri, request.OriginalDataLength, request.DataLength); } else if ((request.OriginalDataLength > 0) && (request.OriginalDataLength == request.DataLength)) { //Realiza a compactação Gzip para estimar a otimização Byte[] tmp = GzipCompress(request.Data); double percent = 100F - (((double)tmp.Length / (double)request.DataLength) * 100F); if (percent > 10) { db.insertMessages(this.TestName, "7. Otimização de rede (compactação gzip/deflate)", "URL: <a href=\"" + u.Target.AbsoluteUri + "\" target=\"_blank\">" + u.Target.AbsoluteUri + "</a>" + Environment.NewLine + (u.Referer != null ? "Referer: <a href=\"" + u.Referer.AbsoluteUri + "\" target=\"_blank\">" + u.Referer.AbsoluteUri + "</a>" + Environment.NewLine : "") + Environment.NewLine + "Redução estimada de: " + FileResources.formatData(percent, ChartDataType.Percent) + Environment.NewLine + "Tamanho original: " + FileResources.formatData(request.DataLength, ChartDataType.Bytes) + Environment.NewLine + "Tamanho reduzido: " + FileResources.formatData(tmp.Length, ChartDataType.Bytes)); } } //Consições específicas por conteúdo switch (request.ContentType.ToLower()) { case "application/x-pointplus": case "text/css": Check(db, CheckType.Css, u, request); break; case "application/x-javascript": case "application/javascript": case "application/ecmascript": case "text/javascript": case "text/ecmascript": Check(db, CheckType.JS, u, request); break; case "image/png": Check(db, CheckType.Image, u, request); break; default: //Verifica por extenção switch (extension) { case ".css": Check(db, CheckType.Css, u, request); break; case ".js": Check(db, CheckType.JS, u, request); break; case ".png": case ".jpg": case ".gif": Check(db, CheckType.Image, u, request); break; } break; } Console.WriteLine("OK"); } }
private void Check(LoadTestDatabase db, CheckType type, UriInfo info, ResultData request) { switch (type) { case CheckType.Css: case CheckType.JS: String value = request.ContentEncoding2.GetString(request.Data); String min = minify(value); String expanded = expand(value); double percentMin = 100F - (((double)min.Length / (double)value.Length) * 100F); double percentExp = 100F - (((double)value.Length / (double)expanded.Length) * 100F); if (percentMin > 10) { db.insertMessages(this.TestName, "5. Otimização de arquivos (minify *.js, *.css)", "URL: <a href=\"" + info.Target.AbsoluteUri + "\" target=\"_blank\">" + info.Target.AbsoluteUri + "</a>" + Environment.NewLine + (info.Referer != null ? "Referer: <a href=\"" + info.Referer.AbsoluteUri + "\" target=\"_blank\">" + info.Referer.AbsoluteUri + "</a>" + Environment.NewLine : "") + Environment.NewLine + "Redução estimada de: " + FileResources.formatData(percentMin, ChartDataType.Percent) + Environment.NewLine + "Tamanho original: " + FileResources.formatData(value.Length, ChartDataType.Bytes) + Environment.NewLine + "Tamanho reduzido: " + FileResources.formatData(min.Length, ChartDataType.Bytes)); db.insertOptimization(this.TestName, request.RequestUri, value.Length, min.Length); } if (percentExp > 3) { db.insertNonOptimization(this.TestName, request.RequestUri, value.Length, expanded.Length); } break; case CheckType.Image: String text = ""; String imageInfo = ""; imageInfo = "Tamanho: " + FileResources.formatData(request.DataLength, ChartDataType.Bytes) + Environment.NewLine; if (request.DataLength > (100 * 1024)) //100 Kb { text += "* Tamanho da imagem acima de 100Kb" + Environment.NewLine; } using (MemoryStream stm = new MemoryStream(request.Data)) using (Image bmp = Image.FromStream(stm)) { Boolean resolution = false; PixelFormat pxFormat = PixelFormat.Format24bppRgb; float saveRes = bmp.HorizontalResolution; try { imageInfo += "Resolução: " + bmp.Width + " x " + bmp.Height + "px" + Environment.NewLine; } catch { } try { if ((((Int32)bmp.HorizontalResolution) > 72) || (((Int32)bmp.VerticalResolution) > 72)) { text += "* Qualidade (DPI) da imagem acima de 72" + Environment.NewLine; } imageInfo += "DPI: " + bmp.HorizontalResolution + Environment.NewLine; resolution = true; saveRes = 72; } catch { } try { switch (bmp.PixelFormat) { case System.Drawing.Imaging.PixelFormat.Format32bppArgb: case System.Drawing.Imaging.PixelFormat.Format32bppPArgb: case System.Drawing.Imaging.PixelFormat.Format32bppRgb: case System.Drawing.Imaging.PixelFormat.Format48bppRgb: case System.Drawing.Imaging.PixelFormat.Format64bppArgb: case System.Drawing.Imaging.PixelFormat.Format64bppPArgb: text += "* Qualidade (Bit depth) da imagem acima de 24 bits" + Environment.NewLine; resolution = true; pxFormat = PixelFormat.Format24bppRgb; break; } switch (bmp.PixelFormat) { case System.Drawing.Imaging.PixelFormat.Format8bppIndexed: imageInfo += "Bit depth: 16 bits" + Environment.NewLine; pxFormat = bmp.PixelFormat; break; case System.Drawing.Imaging.PixelFormat.Format16bppArgb1555: case System.Drawing.Imaging.PixelFormat.Format16bppGrayScale: case System.Drawing.Imaging.PixelFormat.Format16bppRgb555: case System.Drawing.Imaging.PixelFormat.Format16bppRgb565: imageInfo += "Bit depth: 16 bits" + Environment.NewLine; pxFormat = bmp.PixelFormat; break; case System.Drawing.Imaging.PixelFormat.Format24bppRgb: imageInfo += "Bit depth: 24 bits" + Environment.NewLine; pxFormat = PixelFormat.Format24bppRgb; break; case System.Drawing.Imaging.PixelFormat.Format32bppArgb: case System.Drawing.Imaging.PixelFormat.Format32bppPArgb: case System.Drawing.Imaging.PixelFormat.Format32bppRgb: imageInfo += "Bit depth: 32 bits" + Environment.NewLine; pxFormat = PixelFormat.Format24bppRgb; break; case System.Drawing.Imaging.PixelFormat.Format48bppRgb: imageInfo += "Bit depth: 48 bits" + Environment.NewLine; pxFormat = PixelFormat.Format24bppRgb; break; case System.Drawing.Imaging.PixelFormat.Format64bppArgb: case System.Drawing.Imaging.PixelFormat.Format64bppPArgb: imageInfo += "Bit depth: 64 bits" + Environment.NewLine; pxFormat = PixelFormat.Format24bppRgb; break; default: imageInfo += "Bit depth: " + bmp.PixelFormat.ToString() + Environment.NewLine; break; } } catch { } try { using (ImageInfo imgInfo = new ImageInfo(bmp)) { if (imgInfo.HasExif) { text += "* Imagem com informações EXIF. A remoção desta informação reduz o tamanho da imagem" + Environment.NewLine; resolution = true; } } } catch { } //Realiza a Otimização sugerida e calcula o tamanho estimado a conseguir if (resolution) { try { ImageFormat saveFormat = ImageFormat.Jpeg; if (bmp.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg)) { saveFormat = System.Drawing.Imaging.ImageFormat.Jpeg; } if (bmp.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Bmp)) { saveFormat = System.Drawing.Imaging.ImageFormat.Bmp; } if (bmp.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Png)) { saveFormat = System.Drawing.Imaging.ImageFormat.Png; } if (bmp.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Emf)) { saveFormat = System.Drawing.Imaging.ImageFormat.Emf; } if (bmp.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Exif)) { saveFormat = System.Drawing.Imaging.ImageFormat.Exif; } if (bmp.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Gif)) { saveFormat = System.Drawing.Imaging.ImageFormat.Gif; } if (bmp.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Icon)) { saveFormat = System.Drawing.Imaging.ImageFormat.Icon; } if (bmp.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.MemoryBmp)) { saveFormat = System.Drawing.Imaging.ImageFormat.MemoryBmp; } if (bmp.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Tiff)) { saveFormat = System.Drawing.Imaging.ImageFormat.Tiff; } if (bmp.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Wmf)) { saveFormat = System.Drawing.Imaging.ImageFormat.Wmf; } Bitmap newImage = new Bitmap(bmp.Width, bmp.Height, pxFormat); newImage.SetResolution(saveRes, saveRes); Graphics g = Graphics.FromImage(newImage); g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.DrawImage(bmp, 0, 0); g.Dispose(); MemoryStream newStm = new MemoryStream(); newImage.Save(newStm, saveFormat); if (newStm.Length < request.DataLength) { db.insertOptimization(this.TestName, request.RequestUri, request.DataLength, newStm.Length); double percent2 = 100F - (((double)newStm.Length / (double)request.DataLength) * 100F); text += Environment.NewLine; text += "Tamanho estimado após redução: " + FileResources.formatData(newStm.Length, ChartDataType.Bytes) + Environment.NewLine; text += "Redução estimada de: " + FileResources.formatData(percent2, ChartDataType.Percent) + Environment.NewLine; } else { //Não há redução, a imagem está otimizada text = ""; } newImage.Dispose(); newImage = null; newStm.Dispose(); newStm = null; } catch (Exception ex) { #if DEBUG text += "Erro ao calcular a redução: " + ex.Message; #endif } } } if (text != "") { db.insertMessages(this.TestName, "6. Otimização de imagem", "Img URL: <a href=\"" + info.Target.AbsoluteUri + "\" target=\"_blank\">" + info.Target.AbsoluteUri + "</a>" + Environment.NewLine + (info.Referer != null ? "Referer: <a href=\"" + info.Referer.AbsoluteUri + "\" target=\"_blank\">" + info.Referer.AbsoluteUri + "</a>" + Environment.NewLine : "") + Environment.NewLine + imageInfo + Environment.NewLine + text); } break; } }
public void Start() { if (Uris.Count == 0) { throw new Exception("Listagem de URLs está vazia"); } LoadTestDatabase db = null; try { if (this.ConnectionString == null) { throw new Exception("ConnectionStrings is null"); } db = new LoadTestDatabase(this.ConnectionString); new AutomaticUpdater().Run(db, UpdateScriptRepository.GetScriptsBySqlProviderName(this.ConnectionString)); } catch (Exception ex) { throw new Exception("Erro on load/update database", ex); } try { this.TestName = DateTime.Now.ToString("yyyyMMddHHmmssffff"); db = new LoadTestDatabase(this.ConnectionString); //db.CreateDatabase(this.TestName); } catch (Exception ex) { throw new Exception("Falha ao conectar a base de dados: " + ex.Message); } dStart = DateTime.Now; //Verifica a limitação de utilização free if (this.VirtualUsers > 5000) { db.insertMessages(this.TestName, "0. Licenciamento safetrend.com.br", "A versão free deste aplicativo permite no máximo 5000 VU/SBU"); this.VirtualUsers = 5000; } JavaScriptSerializer ser = new JavaScriptSerializer(); if (this.ZabbixMonitors != null) { foreach (ZabbixConfig zbxHost in this.ZabbixMonitors) { //Realiza teste de conex'ao em cada um dos zabbix listados try { using (Zabbix zbx = new Zabbix(zbxHost.Host, zbxHost.Port)) { StringBuilder hostInfo = new StringBuilder(); String hostname = zbx.GetItem("system.hostname"); hostInfo.AppendLine("<strong>Config name:</strong> " + zbxHost.Name); hostInfo.AppendLine("<strong>Config ip:</strong> " + zbxHost.Host + ":" + zbxHost.Port); hostInfo.AppendLine("<strong>Hostname:</strong> " + hostname); String memory = zbx.GetItem("vm.memory.size[total]"); try { Double m = Double.Parse(memory); ; hostInfo.AppendLine("<strong>Memória total:</strong> " + FileResources.formatData(m, ChartDataType.Bytes)); } catch { } String cpus = zbx.GetItem("system.cpu.discovery"); try { Dictionary <String, Object[]> values = ser.Deserialize <Dictionary <String, Object[]> >(cpus); //List<Dictionary<String, String>> values = ser.Deserialize<List<Dictionary<String, String>>>(cpus); hostInfo.AppendLine("<strong>Quantidade de vCPU:</strong> " + values["data"].Length); } catch { } String disk = zbx.GetItem("vfs.fs.discovery"); try { Dictionary <String, Object[]> values = ser.Deserialize <Dictionary <String, Object[]> >(disk); //List<Dictionary<String, String>> values = ser.Deserialize<List<Dictionary<String, String>>>(cpus); Int32 cnt = 1; foreach (Object o in values["data"]) { String name = ""; String type = ""; if (o is Dictionary <String, Object> ) { Dictionary <String, Object> tO = (Dictionary <String, Object>)o; name = tO["{#FSNAME}"].ToString(); type = tO["{#FSTYPE}"].ToString(); if (!String.IsNullOrEmpty(name)) { switch (type.ToLower()) { case "rootfs": case "sysfs": case "proc": case "devtmpfs": case "devpts": case "tmpfs": case "fusectl": case "debugfs": case "securityfs": case "pstore": case "cgroup": case "rpc_pipefs": case "unknown": case "usbfs": case "binfmt_misc": case "autofs": break; default: hostInfo.AppendLine("<strong>Disco " + cnt + ":</strong> " + name + " --> " + type); cnt++; break; } } } } } catch { } String netIfs = zbx.GetItem("net.if.discovery"); try { List <String> exclusionList = new List <string>(); exclusionList.Add("Bluetooth"); exclusionList.Add("TAP-Windows"); exclusionList.Add("WFP"); exclusionList.Add("QoS"); exclusionList.Add("Diebold"); exclusionList.Add("Microsoft Kernel Debug"); exclusionList.Add("WAN Miniport"); exclusionList.Add("Loopback"); exclusionList.Add("Wi-Fi Direct Virtual"); exclusionList.Add("Filter Driver"); exclusionList.Add("Pseudo-Interface"); Dictionary <String, Object[]> values = ser.Deserialize <Dictionary <String, Object[]> >(netIfs); Int32 cnt = 1; foreach (Object o in values["data"]) { String ifName = ""; if (o is Dictionary <String, Object> ) { Dictionary <String, Object> tO = (Dictionary <String, Object>)o; ifName = tO["{#IFNAME}"].ToString(); if (!String.IsNullOrEmpty(ifName)) { Boolean insert = true; foreach (String e in exclusionList) { if (ifName.IndexOf(e, StringComparison.CurrentCultureIgnoreCase) >= 0) { insert = false; } } if (insert) { hostInfo.AppendLine("<strong>Interface de rede " + cnt + ":</strong> " + ifName); cnt++; } } } } } catch { } db.insertMessages(this.TestName, "1. Zabbix Monitor", hostInfo.ToString()); } } catch { db.insertMessages(this.TestName, "0. Zabbix Monitor", "Erro ao resgatar informação do Host Zabbix " + zbxHost.Name + " (" + zbxHost.Host + ":" + zbxHost.Port + ")"); } } } //Antes de iniciar o stress test realiza a análise de conteúdo this.ContentAnalizer(); if (this.SleepTime < 0) { this.SleepTime = 0; } Int16 factor = 300; if (this.Type == ClientType.VU) { factor = (Int16)(factor * 2); } if (this.VirtualUsers < 0) { this.VirtualUsers = 1; } //Inicia servi;co de monitoramento e SNMP Trap using (TestEnvironment tmp = (TestEnvironment)this.Clone()) { StartApplication("ZabbixGet.exe", tmp); StartApplication("snmptrapreceiver.exe", tmp); } using (TestEnvironment tmp = (TestEnvironment)this.Clone()) { Int16 r = this.VirtualUsers; if (r > factor) { r = factor; } tmp.VirtualUsers = r; FileInfo tFile = new FileInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); tmp.SaveToFile(tFile.FullName); Console.WriteLine("Para iniciar mais conexões utilize o comando abaixo, cada cliente iniciará {0} usuários virtuais", tmp.VirtualUsers); Console.WriteLine("\"{0}\\{1}\" \"{2}\"", Environment.CurrentDirectory, "client.exe", tFile.FullName); Console.WriteLine(""); } Int16 restConn = this.VirtualUsers; while (restConn > factor) { using (TestEnvironment tmp = (TestEnvironment)this.Clone()) { tmp.VirtualUsers = factor; StartApplication("client.exe", tmp); restConn -= factor; } } if (restConn > 0) { using (TestEnvironment tmp = (TestEnvironment)this.Clone()) { tmp.VirtualUsers = restConn; StartApplication("client.exe", tmp); } } }