public void CreatCollection() { LacCellBvciETL lcbs = new LacCellBvciETL(); var cellslook = lcbs.mongo_LacCellBvciETL.QueryMongo().ToLookup(e => e.lac_ci); int bvci_count = 0; TcpPortSessionStaging tts = new TcpPortSessionStaging(); foreach (var p in tts.mongo_TcpPortSessionStaging.QueryMongo()) { TcpPortSessionETLDocument trsd = new TcpPortSessionETLDocument(); trsd._id = p._id; trsd.DimIp.IpID = p._id; trsd.DimUdp.UdpID = p._id; trsd.DimNs.NsID = p._id; trsd.DimBssgp.BssgpID = p._id; trsd.DimLlcSndcp.LlcSndcpID = p._id; trsd.DimIp2.Ip2ID = p._id; trsd.DimTcp.TcpID = p._id; trsd.DimHttp.HttpID = p._id; trsd.DimMessage.MessageID = p._id; trsd.CalItem.CalculationItemID = p._id; trsd.FactTcp.FactID = p._id; trsd.FactTcp.IpID = p._id; trsd.FactTcp.UdpID = p._id; trsd.FactTcp.NsID = p._id; trsd.FactTcp.BssgpID = p._id; trsd.FactTcp.LlcSndcpID = p._id; trsd.FactTcp.Ip2ID = p._id; trsd.FactTcp.TcpID = p._id; trsd.FactTcp.HttpID = p._id; trsd.FactTcp.MessageID = p._id; trsd.FactTcp.CalculationItemID = p._id; trsd.DimIp.bsc_ip_distinct = p.direction == directiondown ? p.ip_dst_aggre : p.ip_src_aggre; trsd.DimIp.ip_flags_mf = p.ip_flags_mf; trsd.DimIp.sgsn_lost_bsc_ip = p.sgsn_lost_bsc_ip; trsd.DimNs.bvci_seq = p.bvci_seq_aggre; trsd.DimNs.bvci_distinct = p.bsc_bvci; trsd.DimNs.bvci_distinct_cnt = p.bsc_bvci.GetDistinctCount();//进行不重复计数 trsd.DimNs.lac_cell_from_bvci = p.lac_cell_from_bvci; trsd.DimNs.lac_cell_from_bvci_cnt = p.lac_cell_from_bvci.GetDistinctCount();//进行不重复计数 trsd.DimNs.multi_cell_per_bvci = p.multi_cell_per_bvci; trsd.DimNs.multibvci_cnt = trsd.DimNs.lac_cell_from_bvci_cnt - trsd.DimNs.bvci_distinct_cnt; trsd.DimNs.bvci_from_lac_cell = SplitLacCellStr(p.lac_cell, cellslook, out bvci_count); trsd.DimNs.bvci_from_lac_cell_cnt = bvci_count; trsd.DimNs.bvci_seq_cnt = p.bvci_seq_aggre.GetSequenceCount();//进行序列计数 trsd.DimNs.bvci_pp_cnt = trsd.DimNs.bvci_seq_cnt - trsd.DimNs.bvci_distinct_cnt; trsd.DimNs.nsip_control_bits_c = p.nsip_control_bits_c;//R-bit和C-bit不响应的问题,bsc_ip更新问题 trsd.DimNs.nsip_control_bits_r = p.nsip_control_bits_r; trsd.DimBssgp.lac_distinct = p.lac; trsd.DimBssgp.imsi = p.imsi; trsd.DimBssgp.direction = p.direction; trsd.DimBssgp.lac_cell_distinct = p.lac_cell; //mulit-bvci-percell的问题 trsd.DimBssgp.lac_cell_distinct_cnt = p.lac_cell.GetDistinctCount();//进行不重复计数 trsd.DimBssgp.cell_seq = p.cell_seq_aggre; trsd.DimNs.bvci_cell_error_cnt = trsd.DimNs.bvci_distinct_cnt - trsd.DimBssgp.lac_cell_distinct_cnt; trsd.DimLlcSndcp.sndcp_m = p.sndcp_m; trsd.DimLlcSndcp.sndcp_nsapi = p.sndcp_nsapi; trsd.DimLlcSndcp.llcgprs_sapi = p.llcgprs_sapi; trsd.DimIp2.ip2_flags_mf = p.ip2_flags_mf; trsd.DimIp2.ip2host_distinct = p.direction == directiondown ? p.ip2_src_aggre : p.ip2_dst_aggre; trsd.DimIp2.ip2ttl_distinct = p.direction == directiondown ? p.ip2_ttl_aggre : fillnull; trsd.DimTcp.tcp_port_distinct = p.direction == directiondown ? p.src_port_aggre : p.dst_port_aggre; trsd.DimTcp.tcp_need_segment = p.tcp_need_segment; #region TCP传输乱序的计算,ip2_id和tcp_nxtseq结合运算 trsd.DimIp2.ip2_id_lost_seq = p.ip2_id_aggre.LostSequenctCount(); trsd.DimTcp.tcp_nxtseq_lost_seq = p.tcp_nxt_aggre.LostSequenctCount(); trsd.DimIp2.lost_ipid_seq = trsd.DimIp2.ip2_id_lost_seq > 0 ? 1 : 0; trsd.DimTcp.lost_tcp_seq = trsd.DimTcp.tcp_nxtseq_lost_seq > 0 ? 1 : 0; #endregion trsd.DimHttp.http_method = p.http_method == null ? tcp_data : p.http_method; trsd.DimHttp.user_agent = p.user_agent == null ? fillnull : p.user_agent; trsd.DimHttp.absolute_uri = p.absolute_uri == null ? fillnull : p.absolute_uri; trsd.DimMessage.session_id = p.session_id; trsd.DimMessage.msg_distinct_aggre = p.msg_distinct_aggre; trsd.DimMessage.ip2ip1_header = p.ip2ip1_header; trsd.FactTcp.ip_total_aggre = p.ip_total_aggre; trsd.FactTcp.sndcp_m_count = p.sndcp_m_count; trsd.FactTcp.sndcp_m_total = p.sndcp_m_total; trsd.FactTcp.seq_total_aggre = p.seq_total_aggre; trsd.FactTcp.seqtotal_sndcp_aggre = p.seqtotal_sndcp_aggre; trsd.FactTcp.seq_total_reduce = p.seq_total_reduce; trsd.FactTcp.seq_total_count = p.seq_total_count; trsd.FactTcp.seq_distinct_count = p.seq_distinct_count; trsd.FactTcp.seq_repeat_cnt = p.seq_repeat_cnt; trsd.FactTcp.seq_total_lost = p.seq_total_lost > 0 ? p.seq_total_lost : 0; trsd.FactTcp.seq_total_repeat = p.seq_total_lost < 0 ? -1 * p.seq_total_lost : 0; trsd.FactTcp.duration = p.duration; trsd.CalItem.IP实传字节数 = trsd.FactTcp.ip_total_aggre; trsd.CalItem.TCP实传字节数 = trsd.FactTcp.seqtotal_sndcp_aggre; trsd.CalItem.TCP完整字节数 = trsd.FactTcp.seq_total_reduce; trsd.CalItem.TCP传输速率 = trsd.FactTcp.duration != 0 ? (double)trsd.FactTcp.seqtotal_sndcp_aggre / trsd.FactTcp.duration : EdgeMax; trsd.CalItem.TCP会话时长 = trsd.FactTcp.duration; trsd.CalItem.TCP传输次数 = trsd.FactTcp.seq_total_count; trsd.CalItem.TCP重发次数 = trsd.FactTcp.seq_repeat_cnt; trsd.CalItem.TCP重传次数占比 = 1.0 * p.seq_repeat_cnt / p.seq_total_count; trsd.CalItem.TCP重传字节数 = trsd.FactTcp.seq_total_repeat; trsd.CalItem.TCP重传字节占比 = trsd.FactTcp.seqtotal_sndcp_aggre != 0 ? (double)trsd.FactTcp.seq_total_repeat / (double)trsd.FactTcp.seqtotal_sndcp_aggre : 1.0; trsd.CalItem.TCP丢包字节数 = trsd.FactTcp.seq_total_lost; trsd.CalItem.TCP丢包字节占比 = trsd.FactTcp.seq_total_reduce != 0 ? (double)trsd.FactTcp.seq_total_lost / (double)trsd.FactTcp.seq_total_reduce : 1.0; mongo_TcpPortSessionETL.MongoCol.Insert(trsd); } Console.WriteLine("TcpPortSessionETLDocument->mongo->ok"); }
public void saveTcpPortSessionDocumentSet(string sqlconn) { TcpDbContext context = null; try { context = new TcpDbContext(sqlconn); context.Configuration.AutoDetectChangesEnabled = false; int count = 0; TcpPortSessionStaging tps = new TcpPortSessionStaging(); foreach (var tcp in tps.mongo_TcpPortSessionStaging.QueryMongo()) { ++count; context = context.AddToContext(context, tcp, count, bulksize, true, sqlconn); } context.SaveChanges(); } finally { if (context != null) context.Dispose(); } Console.WriteLine("TcpPortSessionDocument->TcpDbContext->ok"); }