From 6d3d03e2bcfcaf79b67ec2163daf7cd27935bbb7 Mon Sep 17 00:00:00 2001 From: Andrew Paine Date: Mon, 2 May 2016 09:23:50 +0100 Subject: [PATCH] PHX-4221 increase detail recorded in aggregated event --- .../ReadWindowsEventsPlugin.cs | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/CollectdWinService/ReadWindowsEventsPlugin.cs b/src/CollectdWinService/ReadWindowsEventsPlugin.cs index 7d8793b..bb13a02 100644 --- a/src/CollectdWinService/ReadWindowsEventsPlugin.cs +++ b/src/CollectdWinService/ReadWindowsEventsPlugin.cs @@ -7,6 +7,7 @@ using BloombergFLP.CollectdWin; using System.Text.RegularExpressions; + namespace Netuitive.CollectdWin { internal struct EventQuery @@ -114,11 +115,39 @@ public IList Read() } else { - // Too many events - reduce to summary using attributes of the first - EventRecord record = filteredRecords[0]; - string message = string.Format("Received {0} events", filteredRecords.Count); + // Too many events - summarise by counting events by application,level and code + Dictionary detailMap = new Dictionary(); + int minLevel = 999; // used to get the most severe event in the period for the summary level + filteredRecords.ForEach(delegate(EventRecord record) { + string key = string.Format("{0} in {1} ({2})", record.LevelDisplayName, record.ProviderName, record.Id); + + if (record.Level.Value < minLevel) + minLevel = record.Level.Value; + + if (detailMap.ContainsKey(key)) + { + detailMap[key] = detailMap[key] + 1; + } + else + { + detailMap.Add(key, 1); + } + }); + + List> detailList = new List>(); + foreach (string key in detailMap.Keys) { + detailList.Add(new KeyValuePair(key, detailMap[key])); + } + detailList.Sort(delegate(KeyValuePair pair1, KeyValuePair pair2){return -pair1.Value.CompareTo(pair2.Value);}); + + string[] messageLines = new string[detailList.Count]; + + int ix = 0; + foreach(KeyValuePair pair in detailList) { + messageLines[ix++] = pair.Value + " x " + pair.Key; + } string title = string.Format("{0} ({1} events)", eventQuery.title, filteredRecords.Count); - EventValue newevent = new EventValue(_hostName, collectionTime, record.Level.Value, title, message, 0); + EventValue newevent = new EventValue(_hostName, collectionTime, minLevel, title, String.Join(", ", messageLines), 0); collectableValues.Add(newevent); totalEvents += filteredRecords.Count; }