@@ -22,7 +22,7 @@ namespace NewRelic.Agent.Core.AgentHealth
22
22
{
23
23
public class AgentHealthReporter : ConfigurationBasedService , IAgentHealthReporter
24
24
{
25
- private static readonly TimeSpan _timeBetweenExecutions = TimeSpan . FromMinutes ( 1 ) ;
25
+ private static readonly TimeSpan _timeBetweenExecutions = TimeSpan . FromMinutes ( 2 ) ;
26
26
27
27
private readonly IMetricBuilder _metricBuilder ;
28
28
private readonly IScheduler _scheduler ;
@@ -42,7 +42,7 @@ public AgentHealthReporter(IMetricBuilder metricBuilder, IScheduler scheduler)
42
42
{
43
43
_metricBuilder = metricBuilder ;
44
44
_scheduler = scheduler ;
45
- _scheduler . ExecuteEvery ( LogRecurringLogs , _timeBetweenExecutions ) ;
45
+ _scheduler . ExecuteEvery ( LogPeriodicReport , _timeBetweenExecutions ) ;
46
46
var agentHealthEvents = Enum . GetValues ( typeof ( AgentHealthEvent ) ) as AgentHealthEvent [ ] ;
47
47
foreach ( var agentHealthEvent in agentHealthEvents )
48
48
{
@@ -58,25 +58,28 @@ public AgentHealthReporter(IMetricBuilder metricBuilder, IScheduler scheduler)
58
58
public override void Dispose ( )
59
59
{
60
60
base . Dispose ( ) ;
61
- _scheduler . StopExecuting ( LogRecurringLogs ) ;
61
+ _scheduler . StopExecuting ( LogPeriodicReport ) ;
62
62
}
63
63
64
- private void LogRecurringLogs ( )
64
+ private void LogPeriodicReport ( )
65
65
{
66
66
foreach ( var data in _recurringLogDatas )
67
67
{
68
68
data ? . LogAction ( data . Message ) ;
69
69
}
70
-
70
+
71
+ List < string > events = new List < string > ( ) ;
71
72
foreach ( var counter in _agentHealthEventCounters )
72
73
{
73
74
if ( counter . Value != null && counter . Value . Value > 0 )
74
75
{
75
76
var agentHealthEvent = counter . Key ;
76
77
var timesOccured = counter . Value . Exchange ( 0 ) ;
77
- Log . Info ( $ "Event { agentHealthEvent } has occurred { timesOccured } times in the last { _timeBetweenExecutions . TotalSeconds } seconds" ) ;
78
+ events . Add ( string . Format ( "{0} {1} {2}" , timesOccured , agentHealthEvent , ( timesOccured == 1 ) ? "event" : "events" ) ) ;
78
79
}
79
80
}
81
+ var message = events . Count > 0 ? string . Join ( ", " , events ) : "No events" ;
82
+ Log . Info ( $ "In the last { _timeBetweenExecutions . TotalMinutes } minutes: { message } ") ;
80
83
}
81
84
82
85
public void ReportSupportabilityCountMetric ( string metricName , long count = 1 )
@@ -142,7 +145,11 @@ public void ReportTransactionEventCollected()
142
145
143
146
public void ReportTransactionEventsRecollected ( int count ) => TrySend ( _metricBuilder . TryBuildTransactionEventsRecollectedMetric ( count ) ) ;
144
147
145
- public void ReportTransactionEventsSent ( int count ) => TrySend ( _metricBuilder . TryBuildTransactionEventsSentMetric ( count ) ) ;
148
+ public void ReportTransactionEventsSent ( int count )
149
+ {
150
+ TrySend ( _metricBuilder . TryBuildTransactionEventsSentMetric ( count ) ) ;
151
+ _agentHealthEventCounters [ AgentHealthEvent . Transaction ] ? . Add ( count ) ;
152
+ }
146
153
147
154
#endregion TransactionEvents
148
155
@@ -165,7 +172,12 @@ public void ReportCustomEventCollected()
165
172
public void ReportCustomEventsRecollected ( int count ) => TrySend ( _metricBuilder . TryBuildCustomEventsRecollectedMetric ( count ) ) ;
166
173
167
174
// Note: Though not required by APM like the transaction event supportability metrics, this metric should still be created to maintain consistency
168
- public void ReportCustomEventsSent ( int count ) => TrySend ( _metricBuilder . TryBuildCustomEventsSentMetric ( count ) ) ;
175
+ public void ReportCustomEventsSent ( int count )
176
+ {
177
+ TrySend ( _metricBuilder . TryBuildCustomEventsSentMetric ( count ) ) ;
178
+ _agentHealthEventCounters [ AgentHealthEvent . Custom ] ? . Add ( count ) ;
179
+
180
+ }
169
181
170
182
#endregion CustomEvents
171
183
@@ -183,7 +195,11 @@ public void ReportCustomEventCollected()
183
195
184
196
public void ReportErrorEventSeen ( ) => TrySend ( _metricBuilder . TryBuildErrorEventsSeenMetric ( ) ) ;
185
197
186
- public void ReportErrorEventsSent ( int count ) => TrySend ( _metricBuilder . TryBuildErrorEventsSentMetric ( count ) ) ;
198
+ public void ReportErrorEventsSent ( int count )
199
+ {
200
+ TrySend ( _metricBuilder . TryBuildErrorEventsSentMetric ( count ) ) ;
201
+ _agentHealthEventCounters [ AgentHealthEvent . Error ] ? . Add ( count ) ;
202
+ }
187
203
188
204
#endregion ErrorEvents
189
205
@@ -381,7 +397,11 @@ public void CollectTraceContextSuccessMetrics()
381
397
382
398
public void ReportSpanEventCollected ( int count ) => TrySend ( _metricBuilder . TryBuildSpanEventsSeenMetric ( count ) ) ;
383
399
384
- public void ReportSpanEventsSent ( int count ) => TrySend ( _metricBuilder . TryBuildSpanEventsSentMetric ( count ) ) ;
400
+ public void ReportSpanEventsSent ( int count )
401
+ {
402
+ TrySend ( _metricBuilder . TryBuildSpanEventsSentMetric ( count ) ) ;
403
+ _agentHealthEventCounters [ AgentHealthEvent . Span ] ? . Add ( count ) ;
404
+ }
385
405
386
406
#endregion Span
387
407
@@ -429,6 +449,7 @@ public void ReportInfiniteTracingSpanEventsSent(long countSpans)
429
449
_infiniteTracingSpanBatchSizeMin = Math . Min ( _infiniteTracingSpanBatchSizeMin , countSpans ) ;
430
450
_infiniteTracingSpanBatchSizeMax = Math . Max ( _infiniteTracingSpanBatchSizeMax , countSpans ) ;
431
451
}
452
+ _agentHealthEventCounters [ AgentHealthEvent . InfiniteTracingSpan ] ? . Add ( ( int ) countSpans ) ;
432
453
433
454
}
434
455
@@ -616,7 +637,11 @@ public void IncrementLogDeniedCount(string level)
616
637
617
638
public void ReportLoggingEventCollected ( ) => TrySend ( _metricBuilder . TryBuildSupportabilityLoggingEventsCollectedMetric ( ) ) ;
618
639
619
- public void ReportLoggingEventsSent ( int count ) => TrySend ( _metricBuilder . TryBuildSupportabilityLoggingEventsSentMetric ( count ) ) ;
640
+ public void ReportLoggingEventsSent ( int count )
641
+ {
642
+ TrySend ( _metricBuilder . TryBuildSupportabilityLoggingEventsSentMetric ( count ) ) ;
643
+ _agentHealthEventCounters [ AgentHealthEvent . Log ] ? . Add ( count ) ;
644
+ }
620
645
621
646
public void ReportLoggingEventsDropped ( int droppedCount ) => TrySend ( _metricBuilder . TryBuildSupportabilityLoggingEventsDroppedMetric ( droppedCount ) ) ;
622
647
0 commit comments