@@ -74,7 +74,7 @@ public static Command CreateCommand()
7474 string [ ] queueNames ;
7575
7676 public AzureServiceBusCommand ( SharedOptions shared , string resourceId , string serviceBusDomain , string region , string metricsDomain )
77- : base ( shared )
77+ : base ( shared )
7878 {
7979 azure = new AzureClient ( resourceId , serviceBusDomain , region , metricsDomain , Out . WriteLine ) ;
8080 RunInfo . Add ( "AzureServiceBusNamespace" , azure . FullyQualifiedNamespace ) ;
@@ -84,8 +84,8 @@ protected override async Task<QueueDetails> GetData(CancellationToken cancellati
8484 {
8585 try
8686 {
87- var endTime = DateOnly . FromDateTime ( DateTime . UtcNow ) . AddDays ( - 1 ) ;
88- var startTime = endTime . AddDays ( - 90 ) ;
87+ var endTime = DateOnly . FromDateTime ( DateTime . UtcNow ) ;
88+ var startTime = endTime . AddDays ( - 90 ) ; // Azure Monitor only gives a data for a month back, but we ask for more just in case
8989 var results = new List < QueueThroughput > ( ) ;
9090
9191 azure . ResetConnectionQueue ( ) ;
@@ -95,40 +95,51 @@ protected override async Task<QueueDetails> GetData(CancellationToken cancellati
9595 {
9696 var queueName = queueNames [ i ] ;
9797
98- Out . WriteLine ( $ "Gathering metrics for queue { i + 1 } /{ queueNames . Length } : { queueName } ") ;
98+ Out . Write ( $ "Gathering metrics for queue { i + 1 } /{ queueNames . Length } : { queueName } ") ;
9999
100100 var metricValues = ( await azure . GetMetrics ( queueName , startTime , endTime , cancellationToken ) ) . OrderBy ( m => m . TimeStamp ) . ToArray ( ) ;
101101
102- if ( metricValues is not null )
103- {
104- var maxThroughput = metricValues . Select ( timeEntry => timeEntry . Total ) . Max ( ) ;
102+ var maxThroughput = metricValues . Select ( timeEntry => timeEntry . Total ) . Max ( ) ;
103+ var start = DateOnly . FromDateTime ( metricValues . First ( ) . TimeStamp . UtcDateTime ) ;
104+ var end = DateOnly . FromDateTime ( metricValues . Last ( ) . TimeStamp . UtcDateTime ) ;
105105
106- // Since we get 90 days of data, if there's no throughput in that amount of time, hard to legitimately call it an endpoint
107- if ( maxThroughput is not null and not 0 )
106+ // If there's no throughput in that amount of time, hard to legitimately call it an endpoint
107+ if ( maxThroughput is not null and not 0 )
108+ {
109+ var currentDate = start ;
110+ var data = new Dictionary < DateOnly , DailyThroughput > ( ) ;
111+ while ( currentDate <= end )
108112 {
109- var start = DateOnly . FromDateTime ( metricValues . First ( ) . TimeStamp . UtcDateTime ) ;
110- var end = DateOnly . FromDateTime ( metricValues . Last ( ) . TimeStamp . UtcDateTime ) ;
111- var currentDate = start ;
112- var data = new Dictionary < DateOnly , DailyThroughput > ( ) ;
113- while ( currentDate <= end )
113+ data . Add ( currentDate , new DailyThroughput
114114 {
115- data . Add ( currentDate , new DailyThroughput { MessageCount = 0 , DateUTC = currentDate } ) ;
115+ MessageCount = 0 ,
116+ DateUTC = currentDate
117+ } ) ;
116118
117- currentDate = currentDate . AddDays ( 1 ) ;
118- }
119+ currentDate = currentDate . AddDays ( 1 ) ;
120+ }
119121
120- foreach ( var metricValue in metricValues )
122+ foreach ( var metricValue in metricValues )
123+ {
124+ currentDate = DateOnly . FromDateTime ( metricValue . TimeStamp . UtcDateTime ) ;
125+ data [ currentDate ] = new DailyThroughput
121126 {
122- currentDate = DateOnly . FromDateTime ( metricValue . TimeStamp . UtcDateTime ) ;
123- data [ currentDate ] = new DailyThroughput { MessageCount = ( long ) ( metricValue . Total ?? 0 ) , DateUTC = currentDate } ;
124- }
125-
126- results . Add ( new QueueThroughput { QueueName = queueName , Throughput = ( long ? ) maxThroughput , DailyThroughputFromBroker = [ .. data . Values ] } ) ;
127+ MessageCount = ( long ) ( metricValue . Total ?? 0 ) ,
128+ DateUTC = currentDate
129+ } ;
127130 }
128- else
131+
132+ results . Add ( new QueueThroughput
129133 {
130- Out . WriteLine ( " - No throughput detected in 90 days, ignoring" ) ;
131- }
134+ QueueName = queueName ,
135+ Throughput = ( long ? ) maxThroughput ,
136+ DailyThroughputFromBroker = [ .. data . Values ]
137+ } ) ;
138+ Out . WriteLine ( $ " - Max daily throughput: { maxThroughput } ({ start . ToShortDateString ( ) } - { end . ToShortDateString ( ) } )") ;
139+ }
140+ else
141+ {
142+ Out . WriteLine ( $ " - No throughput detected for the period { start . ToShortDateString ( ) } - { end . ToShortDateString ( ) } , ignoring") ;
132143 }
133144 }
134145
0 commit comments