public void RetrieveRecordByID() { using (var db = new Database(new ConfigManager())) { db.InitializeDatabase(); var search = new LogQueryResults() { IncludeData = true }; search.LogIDs = new List<LogQueryResultDetail>(); search.LogIDs.Add(new LogQueryResultDetail() { ID = 1 }); db.RetrieveLogsBySearchResults(search); Assert.AreEqual(1, search.LogIDs[0].ID); Assert.That(search.LogIDs[0].Log, Is.Not.Null); } }
public LogQueryResults Search(LogQuery query) { if (query.DateTime_From == DateTime.MinValue || query.DateTime_To == DateTime.MinValue) { throw new ArgumentException("DateTime_From or DateTime_To Not Set"); } var qryHeader = new BooleanQuery(); if (!string.IsNullOrWhiteSpace(query.Text)) { var textBooleanQuery = new BooleanQuery(); for (int i = 0; i < textQueryFields.Length; i++) { var termQry = new TermQuery(new Term(textQueryFields[i], query.Text)); textBooleanQuery.Add(termQry, BooleanClause.Occur.SHOULD); } qryHeader.Add(textBooleanQuery, BooleanClause.Occur.MUST); } if (query.ClientIP != null) { var ipStr = NAppIndexUpdater.ConvertIPToString(query.ClientIP); var termQry = new TermQuery(new Term(FieldKeys.ClientIP, ipStr)); qryHeader.Add(termQry, BooleanClause.Occur.MUST); } if (query.ServerIP != null) { var ipStr = NAppIndexUpdater.ConvertIPToString(query.ServerIP); var termQry = new TermQuery(new Term(FieldKeys.ServerIP, ipStr)); qryHeader.Add(termQry, BooleanClause.Occur.MUST); } if (query.ShowExceptions == LogQueryExceptions.ExceptionsOnly) { var termQry = new TermQuery(new Term(FieldKeys.Exception, "1")); qryHeader.Add(termQry, BooleanClause.Occur.MUST); } else if (query.ShowExceptions == LogQueryExceptions.SuccessesOnly) { var termQry = new TermQuery(new Term(FieldKeys.Exception, "1")); qryHeader.Add(termQry, BooleanClause.Occur.MUST); } var elapsedQuery = AddFromToQueryString(FieldKeys.Elapsed, query.TotalElapsed_From.Ticks, query.TotalElapsed_To.Ticks, TimeSpan.Zero.Ticks); if (elapsedQuery != null) { qryHeader.Add(elapsedQuery, BooleanClause.Occur.MUST); } var dtlQry = AddFromToQueryString(FieldKeys.Detail_Elapsed, query.DetailElapsed_From.Ticks, query.DetailElapsed_To.Ticks, TimeSpan.Zero.Ticks); if (dtlQry != null) { qryHeader.Add(dtlQry, BooleanClause.Occur.MUST); } var ret = new LogQueryResults() { DateTime_From = query.DateTime_From, DateTime_To = query.DateTime_To, }; if (qryHeader.Clauses().Count > 0) { ret.LogIDs = new List<LogQueryResultDetail>(); GetLogIDsFromMain(qryHeader, ret.DateTime_From, ret.DateTime_To, ret.LogIDs); } return ret; }
private void ProcessResults(byte[] data) { var results = LogQueryResults.DeserializeLog(data); if (!results.IncludeData) { var idRequest = new LogQueryResults() { IncludeData = true }; if (results.LogIDs != null) { idRequest.LogIDs = results.LogIDs.Take(100).ToList(); NAppProfilerClient.SendLogRequest(idRequest, null); } } }
private void SendResult(LogQueryResults result) { var data = result.Serialize(); var msg = Message.CreateMessageByte(data, MessageTypes.Results, result.RequestID); result.ClientSocket.BeginSend(msg, 0, msg.Length, SocketFlags.None, new AsyncCallback(EndSend), result.ClientSocket); }
public void RetrieveRecordsByDate() { using (var db = new Database(new ConfigManager())) { db.InitializeDatabase(); var log = new LogEntity(new DateTime(2011, 11, 9, 0, 0, 0), TimeSpan.FromMilliseconds(300), false, new byte[] { 3, 30, 25 }); db.InsertLogs(new LogEntity[] { log }); var search = new LogQueryResults() { IncludeData = true }; search.DateTime_From = new DateTime(2011, 11, 5, 0, 0, 0, DateTimeKind.Utc); search.DateTime_To = new DateTime(2011, 11, 10, 0, 0, 0, DateTimeKind.Utc); search.IncludeData = true; db.RetrieveLogsBySearchResults(search); Assert.That(search.LogIDs, Is.Not.Null); Assert.That(search.LogIDs.Count, Is.GreaterThan(0)); } }
public void TestInsertPerformance() { using (var db = new Database(new ConfigManager())) { db.InitializeDatabase(); var size = db.Size(); var start = DateTime.UtcNow; DateTime stop; TimeSpan ts; var ts1 = TimeSpan.FromMilliseconds(300).Ticks; var insertStart = new DateTime(2011, 11, 1); var numOfRows = 50000; var interval = (long)((DateTime.Now - insertStart).Ticks / numOfRows); var rndElapsed = new Random(); for (int i = 0; i < numOfRows; i++) { var createdDT = insertStart.AddTicks(interval * i); var elapsed = TimeSpan.FromMilliseconds((long)rndElapsed.Next(1, 30000)).Ticks; var log = new NAppProfiler.Client.DTO.Log() { ClientIP = new byte[] { 10, 26, 10, 142 }, CreatedDateTime = createdDT, Details = new List<NAppProfiler.Client.DTO.LogDetail>(), Elapsed = elapsed, IsError = Convert.ToBoolean(rndElapsed.Next(0, 1)), Method = "Method", Service = "Service", }; log.Details.Add(new Client.DTO.LogDetail() { CreatedDateTime = createdDT, Description = "Description " + i.ToString(), Elapsed = 100, }); log.Details.Add(new Client.DTO.LogDetail() { CreatedDateTime = createdDT, Description = "Description2 " + i.ToString(), Elapsed = 100, }); var logEnt = new LogEntity(createdDT, new TimeSpan(elapsed), log.IsError, NAppProfiler.Client.DTO.Log.SerializeLog(log)); db.InsertLogs(new LogEntity[] { logEnt }); } stop = DateTime.UtcNow; ts = stop - start; Console.WriteLine("Total Milliseconds (Insert " + numOfRows.ToString() + " Rows): " + ts.TotalMilliseconds.ToString("#,##0")); start = DateTime.UtcNow; for (int i = 1; i < 200001; i++) { var search = new LogQueryResults(){IncludeData = true}; search.LogIDs = new List<LogQueryResultDetail>(); search.LogIDs.Add(new LogQueryResultDetail(){ID = i}); db.RetrieveLogsBySearchResults(search); var logDe = search.LogIDs[0].Log; } stop = DateTime.UtcNow; ts = stop - start; Console.WriteLine("Total Milliseconds (Retrieve 200,000 Logs)" + ts.TotalMilliseconds.ToString("#,##0")); start = DateTime.UtcNow; var count = db.Count(new DateTime(2011, 11, 24), new DateTime(2011, 11, 26)); stop = DateTime.UtcNow; ts = stop - start; Console.WriteLine("Total Milliseconds " + ts.TotalMilliseconds.ToString("#,##0")); Console.WriteLine("Total Date Range Count " + count.ToString("#,##0")); start = DateTime.UtcNow; count = db.Count(); stop = DateTime.UtcNow; ts = stop - start; Console.WriteLine("Total Milliseconds " + ts.TotalMilliseconds.ToString("#,##0")); Console.WriteLine("Total All Count " + count.ToString("#,##0")); } }
public long UpdateIndex() { long ret = 0; var logIds = currentDb.GetLogsToIndex(this.UpdateBatchSize); if (logIds.Count > 0) { var search = new LogQueryResults(){ IncludeData = true}; search.LogIDs = new List<LogQueryResultDetail>(logIds.Count); var idArray = new long[logIds.Count]; for (int i = 0; i < logIds.Count; i++) { idArray[i] = logIds[i].Item1; search.LogIDs.Add(new LogQueryResultDetail() { ID = logIds[i].Item2 }); } currentDb.RetrieveLogsBySearchResults(search); foreach (var log in search.LogIDs) { AddDocumentToIndex(log.ID, log.Log); if (nLogger.IsTraceEnabled) { nLogger.Trace("Index updated with log id {0}", log.ID); } ret++; } currentDb.DeleteIndexRows(idArray); writer.Commit(); } return ret; }
public static void SendLogRequest(LogQueryResults results, object messageBag) { CurrentSocket().Send(MessageTypes.GetLogs, results.Serialize(), messageBag); }