Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
EventStatisticsSink.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4
6{
11 {
12 private Dictionary<string, Statistic> perActor = new Dictionary<string, Statistic>();
13 private Dictionary<string, Statistic> perEventId = new Dictionary<string, Statistic>();
14 private Dictionary<string, Statistic> perFacility = new Dictionary<string, Statistic>();
15 private Dictionary<string, Statistic> perModule = new Dictionary<string, Statistic>();
16 private Dictionary<string, Statistic> perLevel = new Dictionary<string, Statistic>();
17 private Dictionary<string, Statistic> perType = new Dictionary<string, Statistic>();
18 private Dictionary<string, Statistic> perStackTrace = new Dictionary<string, Statistic>();
19 private DateTime lastStat = DateTime.MinValue;
20 private readonly object synchObj = new object();
21
27 : base(ObjectID)
28 {
29 this.lastStat = DateTime.Now;
30 }
31
37 {
38 EventStatistics Result;
39 DateTime TP = DateTime.Now;
40
41 lock (this.synchObj)
42 {
43 Result = new EventStatistics()
44 {
45 PerActor = this.perActor,
46 PerEventId = this.perEventId,
47 PerFacility = this.perFacility,
48 PerModule = this.perModule,
49 PerLevel = this.perLevel,
50 PerType = this.perType,
51 PerStackTrace = this.perStackTrace,
52 LastStat = this.lastStat,
53 CurrentStat = TP
54 };
55
56 this.perActor = new Dictionary<string, Statistic>();
57 this.perEventId = new Dictionary<string, Statistic>();
58 this.perFacility = new Dictionary<string, Statistic>();
59 this.perModule = new Dictionary<string, Statistic>();
60 this.perLevel = new Dictionary<string, Statistic>();
61 this.perType = new Dictionary<string, Statistic>();
62 this.perStackTrace = new Dictionary<string, Statistic>();
63 this.lastStat = TP;
64 }
65
66 return Result;
67 }
68
73 public override Task Queue(Event Event)
74 {
75 string s;
76
77 lock (this.synchObj)
78 {
79 this.IncLocked(Event.Type.ToString(), this.perType);
80 this.IncLocked(Event.Level.ToString(), this.perLevel);
81
82 if (!string.IsNullOrEmpty(s = Event.Actor))
83 this.IncLocked(s, this.perActor);
84
85 if (!string.IsNullOrEmpty(s = Event.EventId))
86 this.IncLocked(s, this.perEventId);
87
88 if (!string.IsNullOrEmpty(s = Event.Facility))
89 this.IncLocked(s, this.perFacility);
90
91 if (!string.IsNullOrEmpty(s = Event.Module))
92 this.IncLocked(s, this.perModule);
93
94 if ((Event.Type == EventType.Critical || Event.Type == EventType.Alert || Event.Type == EventType.Emergency) &&
95 !string.IsNullOrEmpty(Event.StackTrace))
96 {
97 this.IncLocked(Event.StackTrace, this.perStackTrace);
98 }
99 }
100
101 return Task.CompletedTask;
102 }
103
104 private void IncLocked(string Key, Dictionary<string, Statistic> PerKey)
105 {
106 if (PerKey.TryGetValue(Key, out Statistic Nr))
107 Nr.Inc();
108 else
109 PerKey[Key] = new Statistic(1);
110 }
111 }
112}
Class representing an event.
Definition: Event.cs:10
EventType Type
Type of event.
Definition: Event.cs:121
EventLevel Level
Event Level.
Definition: Event.cs:126
string Actor
Actor responsible for the action causing the event.
Definition: Event.cs:141
string Module
Module where the event is reported.
Definition: Event.cs:156
string EventId
Computer-readable Event ID identifying type of even.
Definition: Event.cs:146
string Facility
Facility can be either a facility in the network sense or in the system sense.
Definition: Event.cs:151
string StackTrace
Stack Trace of event.
Definition: Event.cs:161
Base class for event sinks.
Definition: EventSink.cs:9
virtual string ObjectID
Object ID, used when logging events.
Definition: LogObject.cs:25
Calculates statistics on incoming events.
override Task Queue(Event Event)
Queues an event to be output.
EventStatisticsSink(string ObjectID)
Calculates statistics on incoming events.
EventStatistics GetStatisticsSinceLast()
Gets statistics of events logged since last call to GetStatisticsSinceLast.
Contains statistical information about one item.
Definition: Statistic.cs:9
EventType
Type of event.
Definition: EventType.cs:7