/** 解析单次消息内容 */ public void parseMessage(ByteBuffer socketbuffer) { int versionInfo = socketbuffer.readByte(); bool encryption = ((versionInfo & 8) != 0); bool crc = ((versionInfo & 4) != 0); bool compress = ((versionInfo & 2) != 0); //if(!MiniConnectManager.IsRobot) //MonoBehaviour.print ("length=>" + length + " versionInfo=>" + versionInfo + " encryption=>" + encryption + " crc=>" + crc + " compress=>" + compress); ByteBuffer data = new ByteBuffer(length - 1); data.write(socketbuffer.toArray(), 0, length - 1); //为下次数据处理做判断 if (socket.Available >= 2) { byte[] b = new byte[2]; socket.Receive(b, SocketFlags.None); length = ByteKit.readUnsignedShort(b, 0); } else { length = 0; } if (encryption) { data = encryptionCode(data, _receiveChallengeCode); } if (compress) { byte[] bb = ZIPUtil.Decompress(data.toArray()); data = new ByteBuffer(bb); } if (crc) { int crcValue = data.readInt(); ByteBuffer data1 = new ByteBuffer(); data1.writeBytes(data.toArray(), 0, (data.top - data.position)); int nowCrc = (int)ChecksumUtil.Adler32(data1); if (crcValue != nowCrc) { MonoBehaviour.print("crc is err,crcValue" + crcValue + ",nowCrc=" + nowCrc); return; } } ErlKVMessage message = new ErlKVMessage(null); message.bytesRead(data); if (_portHandler != null) // _portHandler可以是DataAccess或者ErlTransmitPort,如果要保存funcUid就要设置为DataAccess { _portHandler.erlReceive(this, message); } }
/** 发送方法 * @param data 数据 * @param isEncryption 是否加密 * @param isCrc 是否crc * @param isCompress 是否压缩 * @param kv kv类型 为0表示消息为二进制数据,为1表示消息为KeyValue类型,key为字符串,Value为标准格式的数据 * */ public void sendErl(ByteBuffer data, int encryption, int crc, int compress, int kv) { //没有得到pk码,一般出现在连接有,但是接不到后台消息 if (_sendChallengeCode == null || _sendChallengeCode.Length < 0) { return; } _encryption = encryption; _crc = crc; _compress = compress; _kv = kv; int crcValue = 0; ByteBuffer data1 = new ByteBuffer(); if (_compress == COMPRESS && data.length() >= 64) // 根据参数和数据长度判断是否执行压缩 { byte[] bb = ZIPUtil.Compress(data.toArray()); data = new ByteBuffer(bb); } else { _compress = 0; } if (_crc == 1 && _compress == 0) { crcValue = (int)ChecksumUtil.Adler32(data); data1.writeInt(crcValue); } else { _crc = 0; } data1.writeBytes(data.toArray()); if (_encryption == 1) { data1 = encryptionCode(data1, _sendChallengeCode); // 执行加密 } send(data1); _encryption = ENCRYPTION; _crc = CRC; _compress = COMPRESS; _kv = KV; }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse contentRet = null; Int64 enterpriseId = 0; if ((Session["enterprise_data"]) != null && (Session["enterprise_data"] is EnterpriseData)) { enterpriseId = ((EnterpriseData)Session["enterprise_data"]).Id; } String area = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["area"])) { area = (String)RouteData.Values["area"]; } Int64 proxyId = 0; try { proxyId = Int64.Parse((String)RouteData.Values["id"]); if (proxyId < 0) { proxyId = 0; } } catch { } if (proxyId == 0) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("proxy_not_found"), 3000, true); area = ""; } String rData = ""; String jData = ""; ProxyGetResult retProxy = null; try { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "proxy.get", parameters = new { proxyid = proxyId }, id = 1 }); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } retProxy = JSON.Deserialize <ProxyGetResult>(jData); if (retProxy == null) { //error = MessageResource.GetMessage("proxy_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (retProxy.error != null) { //error = retProxy.error.data; retProxy = null; } else if (retProxy.result == null || retProxy.result.info == null) { //error = MessageResource.GetMessage("proxy_not_found"); retProxy = null; } else { //menu3.Name = retProxy.result.info.name; } } catch (Exception ex) { //error = MessageResource.GetMessage("api_error"); Tools.Tool.notifyException(ex, this); retProxy = null; //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } try { switch (area) { case "download": if (retProxy != null) { DirectoryInfo tempPath = null; DirectoryInfo proxyPath = null; try { //Cria o diretório temporário tempPath = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); proxyPath = new DirectoryInfo(Path.Combine(tempPath.FullName, "proxies\\" + enterpriseId + "_" + retProxy.result.info.name)); if (!proxyPath.Exists) { proxyPath.Create(); } //Realiza a leitura dos arquivos originais Byte[] multProxy = File.ReadAllBytes(Path.Combine(Request.PhysicalApplicationPath, "_data\\multproxy.zip")); Byte[] proxy = File.ReadAllBytes(Path.Combine(Request.PhysicalApplicationPath, "_data\\proxy.zip")); //Descompacta os zips em uma estrutura temporária ZIPUtil.DecompressData(multProxy, tempPath); ZIPUtil.DecompressData(proxy, proxyPath); //Cria o arquivo de configuração do proxy String config = ""; config += "server=" + Request.Url.Host + (Request.Url.Port != 80 && Request.Url.Port != 443 ? ":" + Request.Url.Port : "") + Environment.NewLine; config += "usehttps=" + (Tools.Tool.IsUsingHTTPS() ? "1" : "0") + Environment.NewLine; config += "hostname=" + retProxy.result.info.name + Environment.NewLine; //Resgata os dados de certificado using (ProxyConfig cfg = new ProxyConfig()) { cfg.GetDBConfig(IAMDatabase.GetWebConnection(), enterpriseId, retProxy.result.info.name); config += "c1=" + cfg.server_cert + Environment.NewLine; config += "c2=" + cfg.client_cert + Environment.NewLine; } File.WriteAllText(Path.Combine(proxyPath.FullName, "proxy.conf"), config, Encoding.UTF8); //Cria o arquivo zip com os dados e retorna Byte[] bRet = ZIPUtil.Compress(tempPath); Response.Clear(); Response.ContentType = "application/zip"; Response.AddHeader("Content-Disposition", "attachment; filename=IAMProxy.zip"); Response.AddHeader("Content-Length", bRet.Length.ToString()); Response.Status = "200 OK"; Response.StatusCode = 200; Response.OutputStream.Write(bRet, 0, bRet.Length); Response.OutputStream.Flush(); } catch (Exception ex) { Response.Status = "500 Internal Error"; Response.StatusCode = 500; } finally { try { if (tempPath != null) { tempPath.Delete(true); } } catch { } } contentRet = null; } break; } } catch (Exception ex) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
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); * }*/ }