Calculate average as well as average rate.
This commit is contained in:
		
							parent
							
								
									0d6f2a51bb
								
							
						
					
					
						commit
						1548b2e0b7
					
				|  | @ -790,10 +790,13 @@ format_sample_details(Range, #stats{diffs = Diffs, base = Base}, Interval) -> | |||
|     Part1 = [{rate,     Rate}, | ||||
|              {interval, Interval}, | ||||
|              {samples,  Samples}], | ||||
|     Part2 = case length(Samples) > 1 of | ||||
|     Length = length(Samples), | ||||
|     Part2 = case Length > 1 of | ||||
|                 true  -> [{sample, S2}, {timestamp, T2}] = hd(Samples), | ||||
|                          [{sample, S1}, {timestamp, T1}] = lists:last(Samples), | ||||
|                          [{avg_rate, (S2 - S1) * 1000 / (T2 - T1)}]; | ||||
|                          Total = lists:sum([pget(sample, I) || I <- Samples]), | ||||
|                          [{avg_rate, (S2 - S1) * 1000 / (T2 - T1)}, | ||||
|                           {avg,      Total / Length}]; | ||||
|                 false -> [] | ||||
|             end, | ||||
|     {Part1 ++ Part2, Count}. | ||||
|  |  | |||
|  | @ -216,15 +216,17 @@ get_ch(Name, Range) -> rabbit_mgmt_db:get_channel(a2b(Name), Range). | |||
| get_overview(Range) -> rabbit_mgmt_db:get_overview(Range). | ||||
| get_overview_q(Range) -> pget(queue_totals, get_overview(Range)). | ||||
| 
 | ||||
| details(R, AR, L) -> | ||||
| details(R, AR, A, L) -> | ||||
|     [{rate,     R}, | ||||
|      {interval, 5000}, | ||||
|      {samples,  [[{sample, S}, {timestamp, T * 1000}] || {T, S} <- L]}, | ||||
|      {avg_rate, AR}]. | ||||
|      {avg_rate, AR}, | ||||
|      {avg,      A}]. | ||||
| 
 | ||||
| simple_details(Thing, N) -> | ||||
|     [{Thing, N}, | ||||
|      {atom_suffix(Thing, "_details"), details(0, 0.0, [{1, N}, {0, N}])}]. | ||||
|      {atom_suffix(Thing, "_details"), | ||||
|       details(0, 0.0, N * 1.0, [{1, N}, {0, N}])}]. | ||||
| 
 | ||||
| atom_suffix(Atom, Suffix) -> | ||||
|     list_to_atom(atom_to_list(Atom) ++ Suffix). | ||||
|  |  | |||
|  | @ -59,20 +59,20 @@ format_sample_details_test() -> | |||
|     %% Just three samples, all of which we format. Note the | ||||
|     %% instantaneous rate is taken from the penultimate sample. | ||||
|     T({10, 30, 10}, {[{10, 10}, {20, 20}, {30, 30}], 1}, | ||||
|       {[{30, 61}, {20, 31}, {10, 11}], 2.0, 10, 2.5, 61}), | ||||
|       {[{30, 61}, {20, 31}, {10, 11}], 2.0, 10, 2.5, 103/3, 61}), | ||||
| 
 | ||||
|     %% Skip over the second (and ditto). | ||||
|     T({10, 30, 20}, {[{10, 10}, {20, 20}, {30, 30}], 1}, | ||||
|       {[{30, 61}, {10, 11}], 2.0, 10, 2.5, 61}), | ||||
|       {[{30, 61}, {10, 11}], 2.0, 10, 2.5, 36.0, 61}), | ||||
| 
 | ||||
|     %% Skip over some and invent some. Note that the instantaneous | ||||
|     %% rate drops to 0 since the last event is now in the past. | ||||
|     T({0, 40, 20}, {[{10, 10}, {20, 20}, {30, 30}], 1}, | ||||
|       {[{40, 61}, {20, 31}, {0, 1}], 0, 10, 1.5, 61}), | ||||
|       {[{40, 61}, {20, 31}, {0, 1}], 0, 10, 1.5, 31.0, 61}), | ||||
| 
 | ||||
|     %% And a case where the range starts after the samples | ||||
|     T({20, 40, 10}, {[{10, 10}, {20, 20}, {30, 30}], 1}, | ||||
|       {[{40, 61}, {30, 61}, {20, 31}], 0, 10, 1.5, 61}), | ||||
|       {[{40, 61}, {30, 61}, {20, 31}], 0, 10, 1.5, 51.0, 61}), | ||||
| 
 | ||||
|     %% A single sample - which should lead to some bits not getting generated | ||||
|     T({10, 10, 10}, {[{10, 10}, {20, 20}, {30, 30}], 1}, | ||||
|  | @ -106,11 +106,12 @@ format({Samples, Rate, Interval, Count}) -> | |||
|       {samples,  format_samples(Samples)}], | ||||
|      Count}; | ||||
| 
 | ||||
| format({Samples, Rate, Interval, AvgRate, Count}) -> | ||||
| format({Samples, Rate, Interval, AvgRate, Avg, Count}) -> | ||||
|     {[{rate,     Rate}, | ||||
|       {interval, Interval * 1000}, | ||||
|       {samples,  format_samples(Samples)}, | ||||
|       {avg_rate, AvgRate}], | ||||
|       {avg_rate, AvgRate}, | ||||
|       {avg,      Avg}], | ||||
|      Count}. | ||||
| 
 | ||||
| format_samples(Samples) -> | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue