Esempio n. 1
0
        public static ICollection <VizqlDesktopSession> GetAllDesktopSessions(IMongoCollection <BsonDocument> collection)
        {
            IList <VizqlDesktopSession> sessions = new List <VizqlDesktopSession>();

            foreach (var file in GetAllUniqueFiles(collection))
            {
                foreach (var pid in GetAllUniquePidsFromFile(file, collection))
                {
                    try
                    {
                        VizqlDesktopSession vizqlDesktopSession = GetDesktopSession(file, pid, collection);
                        if (vizqlDesktopSession != null)
                        {
                            sessions.Add(vizqlDesktopSession);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Exception constructing Desktop Session for pid " + pid + ":" + ex);
                    }
                }
            }

            return(sessions);
        }
Esempio n. 2
0
        public static VizqlDesktopSession GetDesktopSession(string file, int pid, IMongoCollection <BsonDocument> collection, Guid logsetHash)
        {
            var startupInfoQuery = Query.And(Query.Eq("pid", pid),
                                             Query.Eq("file", file),
                                             Query.Eq("k", "startup-info"));

            BsonDocument document = collection.Find(startupInfoQuery).ToList().First();

            VizqlDesktopSession session = new VizqlDesktopSession(document, logsetHash);

            return(session);
        }
Esempio n. 3
0
        public static VizqlSession AppendEventsForKeyType(VizqlSession session, string keyType, IMongoCollection <BsonDocument> collection)
        {
            IEnumerable <BsonDocument> documentList;

            if (session is VizqlServerSession)
            {
                if (!VizqlServerSupportedKeytypes.Contains(keyType))
                {
                    return(session);
                }
                else
                {
                    documentList = GetEventsForKeyBySession(session.VizqlSessionId, keyType, collection);
                }
            }
            else if (session is VizqlDesktopSession)
            {
                if (!VizqlDesktopSupportedKeytypes.Contains(keyType))
                {
                    return(session);
                }
                else
                {
                    VizqlDesktopSession desktopSession = session as VizqlDesktopSession;
                    documentList = GetEventsForKeyByPid(desktopSession.ProcessId, keyType, collection);
                }
            }
            else
            {
                throw new Exception("VizqlSession not of type Desktop or Server!");
            }

            foreach (var document in documentList)
            {
                try
                {
                    Object[]   args       = { document };
                    Type       t          = VizqlEventClassesByKeytype[keyType];
                    VizqlEvent vizqlEvent = (VizqlEvent)Activator.CreateInstance(t, args);
                    session.AppendEvent(vizqlEvent);
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Exception processing {0} events on session {1}: {2}", keyType, session.VizqlSessionId, ex);
                }
            }

            return(session);
        }
        public void ProcessEvent(NativeJsonLogsBaseEvent baseEvent, LogLine logLine)
        {
            if (baseEvent.EventType == "startup-info")
            {
                var @event = new VizqlDesktopSession(baseEvent);
                _sessionsWriter.AddLine(@event);
                _sessionTracker.RegisterSession(logLine.LogFileInfo.FilePath, @event.SessionId);
                return;
            }

            var sessionId = _sessionTracker.GetSessionId(logLine.LogFileInfo.FilePath);

            if (baseEvent.Severity == "error" || baseEvent.Severity == "fatal")
            {
                var @event = new VizqlDesktopErrorEvent(baseEvent, logLine, sessionId);
                _errorsWriter.AddLine(@event);
                return;
            }

            if (sessionId == null) // Only errors allowed to be captured without session
            {
                return;
            }

            if (baseEvent.EventType == "end-query")
            {
                var @event = new VizqlEndQueryEvent(baseEvent, logLine, sessionId, _maxQueryLength);
                _endQueryEventsWriter.AddLine(@event);
                // No return so we can output this event as a performance event as well. Workbook currently expects to see end-query in both data sources
            }

            var performanceEvent = TryParsePerformanceEvent(baseEvent, logLine, sessionId);

            if (performanceEvent != null)
            {
                _performanceEventsWriter.AddLine(performanceEvent);
                return;
            }
            ;
        }
Esempio n. 5
0
        private static IEnumerable <BsonDocument> GetSeveritiesforSession(VizqlSession session, string severity, IMongoCollection <BsonDocument> collection)
        {
            FilterDefinition <BsonDocument> severityQuery;

            if (session is VizqlServerSession)
            {
                severityQuery = Query.And(Query.Eq("sess", session.VizqlSessionId),
                                          Query.Eq("sev", severity));
            }
            else if (session is VizqlDesktopSession)
            {
                VizqlDesktopSession desktopSession = session as VizqlDesktopSession;
                severityQuery = Query.And(Query.Eq("pid", desktopSession.ProcessId),
                                          Query.Eq("sev", severity));
            }
            else
            {
                throw new Exception("VizqlSession not of type Server or Desktop");
            }

            return(collection.Find(severityQuery).ToList());
        }
Esempio n. 6
0
        public static VizqlSession AppendEtcEventsForSession(VizqlSession session, IMongoCollection <BsonDocument> collection)
        {
            var filter = Query.Nin("k", VizqlEventClassesByKeytype.Keys);
            var unsupportedKeyTypes = collection.Distinct <string>("k", filter).ToEnumerable();

            foreach (var keyType in unsupportedKeyTypes)
            {
                IEnumerable <BsonDocument> documents;
                if (session is VizqlServerSession)
                {
                    documents = GetEventsForKeyBySession(session.VizqlSessionId, keyType, collection);
                }
                else if (session is VizqlDesktopSession)
                {
                    VizqlDesktopSession desktopSession = session as VizqlDesktopSession;
                    documents = GetEventsForKeyByPid(desktopSession.ProcessId, keyType, collection);
                }
                else
                {
                    throw new Exception("VizqlSession must be of type Server or Desktop");
                }

                foreach (var document in documents)
                {
                    try
                    {
                        session.AppendEvent(new VizqlEtc(document));
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Unable to create VizqlEtc record for " + session.VizqlSessionId + " for keyType " + keyType + ":" + ex.Message);
                    }
                }
            }

            return(session);
        }
        public static InsertionResult PersistSession(IDbConnection database, VizqlDesktopSession currentSession)
        {
            try
            {
                database.Insert(currentSession);

                //Error
                database.InsertAll(currentSession.ErrorEvents);

                //Performance
                database.InsertAll(currentSession.PerformanceEvents);

                //Connection
                database.InsertAll(currentSession.ConstructProtocolEvents);
                database.InsertAll(currentSession.ConstructProtocolGroupEvents);
                database.InsertAll(currentSession.DsConnectEvents);

                //Compute
                database.InsertAll(currentSession.EndComputeQuickFilterStateEvents);

                //Render
                database.InsertAll(currentSession.EndUpdateSheetEvents);

                //Caching
                database.InsertAll(currentSession.EcDropEvents);
                database.InsertAll(currentSession.EcStoreEvents);
                database.InsertAll(currentSession.EcLoadEvents);
                database.InsertAll(currentSession.EqcStoreEvents);
                database.InsertAll(currentSession.EqcLoadEvents);

                //Message
                database.InsertAll(currentSession.MessageEvents);

                //Etc
                database.InsertAll(currentSession.EtcEvents);

                //Query
                database.InsertAll(currentSession.DsInterpretMetadataEvents);
                database.InsertAll(currentSession.EndQueryEvents);
                database.InsertAll(currentSession.QpQueryEndEvents);
                database.InsertAll(currentSession.EndPrepareQuickFilterQueriesEvents);
                database.InsertAll(currentSession.EndSqlTempTableTuplesCreateEvents);
                database.InsertAll(currentSession.SetCollationEvents);
                database.InsertAll(currentSession.ProcessQueryEvents);

                foreach (VizqlQpBatchSummary qpBatchSummaryEvent in currentSession.QpBatchSummaryEvents)
                {
                    database.Insert(qpBatchSummaryEvent);
                    database.InsertAll(qpBatchSummaryEvent.QpBatchSummaryJobs);
                }

                Log.DebugFormat("Persisted session {0}", currentSession.VizqlSessionId);
                return(new InsertionResult
                {
                    SuccessfulInserts = 1,
                    FailedInserts = 0
                });
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Failed to persist session '{0}': {1}", currentSession.VizqlSessionId, ex.Message);
                return(new InsertionResult
                {
                    SuccessfulInserts = 0,
                    FailedInserts = 1
                });
            }
        }