public void Register(IXEvent evt) { DateTime?date = XTimeExtension.Instance.ExtractTimestamp((XEvent)evt); if (date != null) { Register((DateTime)date); } }
public string GetClassIdentity(IXEvent evt) { List <string> values = new List <string>(); foreach (string key in keys) { values.Add(evt.GetAttributes()[key].ToString()); } return(String.Join(CONCATENATION_SYMBOL, values)); }
private async Task HandleXEventFuncAsync(IXEvent xEvent, EtwWatcherInstanceConfiguration instanceConfig, EtwWatcherAzureConfiguration azureConfig) { foreach (var handler in handlers) { if (await handler.Handle(xEvent, instanceConfig, azureConfig)) { return; } } }
private static void ExportHtml(IXEvent xevent, StreamWriter outputStream) { outputStream.WriteLine($"<div><h3>{xevent.Timestamp.ToString()}</h3>"); foreach (var item in xevent.Fields) { var text = $"<span><strong>{item.Key}:</strong> {item.Value}</span>"; outputStream.WriteLine(text); outputStream.WriteLine("<br/>"); } outputStream.WriteLine("</div><br/>"); }
private static void ExportTxt(IXEvent xevent, StreamWriter outputStream) { outputStream.WriteLine($"---{xevent.Timestamp.ToString()}---"); foreach (var item in xevent.Fields) { var text = $"{item.Key}: {item.Value}"; outputStream.WriteLine(text); } outputStream.WriteLine("-------------------------------"); outputStream.WriteLine(""); }
/// <summary> /// First call made when visiting an event. /// </summary> /// <param name="evt">The event to visit.</param> /// <param name="trace">The trace containing the event.</param> public abstract void VisitEventPost(IXEvent evt, XTrace trace);
public bool SameEventClass(IXEvent event1, IXEvent event2) { return(this.GetClassIdentity(event1).Equals(this.GetClassIdentity(event2))); }
public XEventData(string fileName, long eventNumber, IXEvent EventData) { _fileName = fileName; _eventNumber = eventNumber; _eventData = EventData; }
public OnReadEventArgs(IXEvent rowData, ExtendedEventsPosition position, long eventNumber) { EventData = rowData; EventNumber = eventNumber; Position = position; }
/// <summary> /// For any given event, returns the corresponding event class as determined by this set. /// </summary> /// <returns>The event class of this event, as found in this set of event /// classes. If no matching event class is found, this method may return /// <code>null</code>.</returns> /// <param name="evt">The event of which the event class should be determined.</param> public XEventClass GetClassOf(IXEvent evt) { return(this.classMap[this.classifier.GetClassIdentity(evt)]); }
/// <summary> /// Registers an event with this set of event classes. This will potentially /// add a new event class to this set of event classes.An event class will /// be incremented in size, if the given event is found to be a member of it. /// </summary> /// <param name="evt">The event to be analyzed.</param> public void Register(IXEvent evt) { Register(this.classifier.GetClassIdentity(evt)); }
abstract public Task <bool> Handle(IXEvent xEvent, EtwWatcherInstanceConfiguration instanceConfig, EtwWatcherAzureConfiguration azureConfig);
public override async Task <bool> Handle(IXEvent xEvent, EtwWatcherInstanceConfiguration instanceConfig, EtwWatcherAzureConfiguration azureConfig) { if (xEvent.Name != "xml_deadlock_report") { return(false); } //Get Current time for Azure Signature var utcTime = DateTime.UtcNow; //Load Report and Server objects from xEvent xEvent.Fields.TryGetValue("xml_report", out object report); //Generate Deadlock object from xml_report var deadlock = XDocument .Parse(Regex.Replace(report.ToString().Trim(), @"[^\u0000-\u007F]+", string.Empty)) .Elements("deadlock") .Select(a => new { Victim = a.Elements("victim-list") .Elements("victimProcess") .Select(i => (string)i.Attribute("id")).ToList(), ProcessList = a.Elements("process-list") .Elements("process") .Select(async i => new { id = (string)i.Attribute("id"), taskpriority = (string)i.Attribute("taskpriority"), logused = (string)i.Attribute("logused"), waitresource = (string)i.Attribute("waitresource"), waittime = (string)i.Attribute("waittime"), ownerId = (string)i.Attribute("ownerId"), transactionname = (string)i.Attribute("transactionname"), lasttranstarted = ((DateTime)i.Attribute("lasttranstarted")).ToUniversalTime(), XDES = (string)i.Attribute("XDES"), lockMode = (string)i.Attribute("lockMode"), schedulerid = (string)i.Attribute("schedulerid"), kpid = (string)i.Attribute("kpid"), status = (string)i.Attribute("status"), spid = (string)i.Attribute("spid"), sbid = (string)i.Attribute("sbid"), ecid = (string)i.Attribute("ecid"), priority = (string)i.Attribute("priority"), trancount = (string)i.Attribute("trancount"), lastbatchstarted = ((DateTime)i.Attribute("lastbatchstarted")).ToUniversalTime(), lastbatchcompleted = ((DateTime)i.Attribute("lastbatchcompleted")).ToUniversalTime(), lastattention = ((DateTime)i.Attribute("lastattention")).ToUniversalTime(), clientapp = (string)i.Attribute("clientapp"), hostname = (string)i.Attribute("hostname"), hostpid = (string)i.Attribute("hostpid"), loginname = (string)i.Attribute("loginname"), isolationlevel = (string)i.Attribute("isolationlevel"), xactid = (string)i.Attribute("xactid"), currentdb = (int)i.Attribute("currentdb"), currentdbName = await instanceConfig.DatabaseCache.GetOrAdd((int)i.Attribute("currentdb"), AddValue((int)i.Attribute("currentdb"), instanceConfig.ConnectionString)), lockTimeout = (string)i.Attribute("lockTimeout"), clientoption1 = (string)i.Attribute("clientoption1"), clientoption2 = (string)i.Attribute("clientoption2"), executionStack = i.Elements("executionStack").Elements("frame").Select(j => new { procname = (string)j.Attribute("procname"), line = (string)j.Attribute("line"), stmtstart = (string)j.Attribute("stmtstart"), stmtend = (string)j.Attribute("stmtend"), sqlhandle = (string)j.Attribute("sqlhandle"), }).ToList(), inputbuf = ((string)i.Element("inputbuf")).Trim(), }) .Select(t => t.Result) .ToList(), ResourceList = a.Elements("resource-list") .Elements("keylock") .Select(i => new { hobtid = (string)i.Attribute("hobtid"), dbid = (string)i.Attribute("dbid"), objectname = (string)i.Attribute("objectname"), indexname = (string)i.Attribute("indexname"), id = (string)i.Attribute("id"), mode = (string)i.Attribute("mode"), associatedObjectId = (string)i.Attribute("associatedObjectId"), ownerLlist = i.Elements("owner-list").Elements("owner").Select(j => new { id = (string)j.Attribute("id"), mode = (string)j.Attribute("mode") }).ToList(), waiterList = i.Elements("waiter").Select(j => new { id = (string)j.Attribute("id"), mode = (string)j.Attribute("mode"), requestType = (string)j.Attribute("requestType") }).ToList() }).ToList() }).First(); //New Object List to Message var deadlockXmlDiagnosticsMessage = new DeadlockXmlDiagnosticsMessage { TimeGenerated = xEvent.Timestamp.UtcDateTime, BlockType = DiagnosticsMessageType.DeadlockXmlMessage, Server = Environment.MachineName, Process1_Id = deadlock.ProcessList[0].id, Process1_EventTime = deadlock.ProcessList[0].lasttranstarted, Process1_IsVictim = deadlock.Victim.First() == deadlock.ProcessList[0].id ? "True" : "False", Process1_LockMode = deadlock.ProcessList[0].lockMode, Process1_Spid = deadlock.ProcessList[0].spid, Process1_ClientApp = deadlock.ProcessList[0].clientapp, Process1_HostName = deadlock.ProcessList[0].hostname, Process1_LoginName = deadlock.ProcessList[0].loginname, Process1_Database = deadlock.ProcessList[0].currentdbName, Process1_Query = deadlock.ProcessList[0].inputbuf.Trim(), Process1_Table = deadlock.ResourceList.Where(i => i.ownerLlist[0].id == deadlock.ProcessList[0].id).Select(a => a.objectname).First(), Process1_Index = deadlock.ResourceList.Where(i => i.ownerLlist[0].id == deadlock.ProcessList[0].id).Select(a => a.indexname).First(), Process2_Id = deadlock.ProcessList[1].id, Process2_EventTime = deadlock.ProcessList[1].lasttranstarted, Process2_IsVictim = deadlock.Victim.First() == deadlock.ProcessList[1].id ? "True" : "False", Process2_LockMode = deadlock.ProcessList[1].lockMode, Process2_Spid = deadlock.ProcessList[1].spid, Process2_ClientApp = deadlock.ProcessList[1].clientapp, Process2_HostName = deadlock.ProcessList[1].hostname, Process2_LoginName = deadlock.ProcessList[1].loginname, Process2_Database = deadlock.ProcessList[1].currentdbName, Process2_Query = deadlock.ProcessList[1].inputbuf.Trim(), Process2_Table = deadlock.ResourceList.Where(i => i.ownerLlist[0].id == deadlock.ProcessList[1].id).Select(a => a.objectname).First(), Process2_Index = deadlock.ResourceList.Where(i => i.ownerLlist[0].id == deadlock.ProcessList[1].id).Select(a => a.indexname).First() }; //await logAnalyticsSink.Send(deadlockXmlDiagnosticsMessage); var signature = AzureUtil.BuildSignature(JsonConvert.SerializeObject(deadlockXmlDiagnosticsMessage), azureConfig.LogAnalyticsSharedKey, Guid.Parse(azureConfig.LogAnalyticsCustomerId), utcTime.ToString("r")); logger.Information("Result from Azure: " + await AzureUtil.PostData(signature, utcTime.ToString("r"), JsonConvert.SerializeObject(deadlockXmlDiagnosticsMessage), Guid.Parse(azureConfig.LogAnalyticsCustomerId))); return(true); }
private static void ExportJson(IXEvent xevent, StreamWriter outputStream) { var buffer = JsonSerializer.Serialize(xevent.Fields); outputStream.Write(buffer + ","); }
public override IXLog Parse(Stream stream) { Stack <IXAttributable> attributableStack = new Stack <IXAttributable>(); Stack <XAttribute> attributeStack = new Stack <XAttribute>(); IXEvent evt = null; IXLog log = null; IXTrace trace = null; List <XAttribute> globals = null; using (XmlReader reader = XmlReader.Create(stream)) { List <string> ATTR_TYPE_TAGS = new List <string>(new string[] { "string", "date", "int", "float", "boolean", "id", "list", "container" }); ATTR_TYPE_TAGS.Sort(); while (reader.Read()) { if (reader.IsStartElement()) { // start tag found string tagName = reader.LocalName.Trim(); if (tagName.Length == 0) { tagName = reader.Name.Trim(); // <= qualified name } if (ATTR_TYPE_TAGS.Contains(tagName.ToLower())) { // The tag is an attribute string key = reader.GetAttribute("key") ?? ""; string val = reader.GetAttribute("value") ?? ""; XExtension ext = null; int colonindex = key.IndexOf(":", StringComparison.InvariantCultureIgnoreCase); if (colonindex > 0) { string prefix = key.Substring(0, colonindex); ext = XExtensionManager.Instance.GetByPrefix(prefix); } XAttribute attr = null; switch (tagName) { case "string": attr = factory.CreateAttributeLiteral(key, val, ext); break; case "int": attr = factory.CreateAttributeDiscrete(key, long.Parse(val), ext); break; case "boolean": attr = factory.CreateAttributeBoolean(key, bool.Parse(val), ext); break; case "date": DateTime d = XAttributeTimestamp.Parse(val); attr = factory.CreateAttributeTimestamp(key, d, ext); break; case "float": attr = factory.CreateAttributeContinuous(key, double.Parse(val), ext); break; case "id": attr = factory.CreateAttributeID(key, XID.Parse(val), ext); break; case "list": attr = factory.CreateAttributeList(key, ext); break; case "container": attr = factory.CreateAttributeContainer(key, ext); break; default: XLogging.Log("Unknown tag '" + tagName + "'", XLogging.Importance.WARNING); break; } if (reader.IsEmptyElement) { // No child nodes, we can directly store it if (globals != null) { // attribute is global globals.Add(attr); } else { attributableStack.Peek().GetAttributes().Add(attr.Key, attr); if ((!(attributeStack.Count == 0)) && (attributeStack.Peek() is XAttributeCollection)) { ((XAttributeCollection)attributeStack.Peek()).AddToCollection(attr); } } } else if (attr != null) { attributeStack.Push(attr); attributableStack.Push((IXAttributable)attr); } } else if ("event".Equals(tagName.ToLower())) { // Parse an event evt = factory.CreateEvent(); attributableStack.Push(evt); } else if ("trace".Equals(tagName.ToLower())) { trace = factory.CreateTrace(); attributableStack.Push(trace); } else if ("log".Equals(tagName.ToLower())) { log = factory.CreateLog(); ((XLog)log).Version = reader.GetAttribute("xes.version") ?? "2.0"; ((XLog)log).Features = reader.GetAttribute("xes.features") ?? ""; attributableStack.Push(log); } else if ("extension".Equals(tagName.ToLower())) { XExtension extension = null; String uriString = reader.GetAttribute("uri"); if (uriString != null) { extension = XExtensionManager.Instance.GetByUri(new UriBuilder(uriString).Uri); } else { string prefixString = reader.GetAttribute("prefix"); if (prefixString != null) { extension = XExtensionManager.Instance.GetByPrefix(prefixString); } } if (extension != null) { log.Extensions.Add(extension); } else { XLogging.Log("Unknown extension: " + uriString, XLogging.Importance.ERROR); } } else if ("global".Equals(tagName.ToLower())) { string scope = reader.GetAttribute("scope"); if (scope.Equals("trace")) { globals = log.GlobalTraceAttributes; } else if (scope.Equals("event")) { globals = log.GlobalEventAttributes; } } else if ("classifier".Equals(tagName.ToLower())) { string name = reader.GetAttribute("name"); string keys = reader.GetAttribute("keys"); if ((name == null) || (keys == null) || (name.Length <= 0) || (keys.Length <= 0)) { continue; } IList <string> keysList = FixKeys(log, XTokenHelper.ExtractTokens(keys)); string[] keysArray = new string[keysList.Count]; int i = 0; foreach (string key in keysList) { keysArray[(i++)] = key; } IXEventClassifier classifier = new XEventAttributeClassifier(name, keysArray); log.Classifiers.Add(classifier); } } else { // end tag found string tagName = reader.LocalName.Trim().ToLower(); if (tagName.Length == 0) { tagName = reader.Name.Trim().ToLower(); // <= qualified name } if ("global".Equals(tagName)) { globals = null; } else if (ATTR_TYPE_TAGS.Contains(tagName)) { XAttribute attribute = attributeStack.Pop(); attributableStack.Pop(); if (globals != null) { globals.Add(attribute); } else { attributableStack.Peek().GetAttributes().Add(attribute.Key, attribute); if ((!(attributeStack.Count == 0)) && (attributeStack.Peek() is XAttributeCollection)) { ((XAttributeCollection)attributeStack.Peek()).AddToCollection(attribute); } } } else if ("event".Equals(tagName)) { trace.Add(evt); evt = null; attributableStack.Pop(); } else if ("trace".Equals(tagName)) { log.Add(trace); trace = null; attributableStack.Pop(); } else if ("log".Equals(tagName)) { attributableStack.Pop(); } } } } return(log); }