public void ContextOnEndRequest(object sender, EventArgs e) { var endRequestWork = Stopwatch.GetTimestamp(); var application = sender as HttpApplication; if (application != null) { var context = GetContext(sender); var response = GetResponse(sender); if ("text/html".Equals(response.ContentType)) { var data = context.Items[METRIX_REQUEST_DATA] as MetrixRequestData; data.EndRequestWork = endRequestWork; data.ResponseStatus = response.Status; response.Flush(); data.OutputLength = CountingStream.Count; data.EndRequest = Stopwatch.GetTimestamp(); MetrixRequestData.AddFrame(data); SerializeData(application, data); } } }
private void SerializeData(HttpApplication application, MetrixRequestData data) { // Write to HTML footer (TODO: make configurable) GetResponse(application).Write(string.Format("<hr/><pre>{0}</pre><hr/>", data.Display.Replace("\n", "<br/>"))); // Write to console (TODO: make configurable) System.Diagnostics.Debug.WriteLine("-----------------"); System.Diagnostics.Debug.WriteLine(data.Display); System.Diagnostics.Debug.WriteLine("-----------------"); // TODO: Write to NLog (make configurable) // TODO: Write to EventLog (make configurable) // TODO: Write to Database (make configurable) // TODO: Write to WebAPI (make configurable) // ... }
public static void AddFrame(MetrixRequestData data) { if (skipFrame) { // skip the "first run" frame times, they're artificially high skipFrame = false; MinimumMillis = long.MaxValue; MaximumMillis = long.MinValue; } else { var elapsed = data.EndRequest - data.StartRequest; MetrixRequestData.TotalMillis += elapsed; MetrixRequestData.TotalFrames++; MetrixRequestData.MinimumMillis = Math.Min(MetrixRequestData.MinimumMillis, elapsed); MetrixRequestData.MaximumMillis = Math.Max(MetrixRequestData.MaximumMillis, elapsed); } }
public void ContextOnBeginRequest(object sender, EventArgs e) { var startRequest = Stopwatch.GetTimestamp(); var application = sender as HttpApplication; if (application != null) { var data = new MetrixRequestData(); var request = GetRequest(sender); var context = GetContext(sender); var response = GetResponse(sender); response.Filter = CountingStream = new CountingStream(response.Filter); data.RequestGuid = Guid.NewGuid(); data.StartRequest = startRequest; data.RawUrl = request.RawUrl; context.Items[METRIX_REQUEST_DATA] = data; data.StartRequestWork = Stopwatch.GetTimestamp(); } }