|
|
@ -269,6 +269,8 @@ namespace Grpc.IntegrationTesting |
|
|
|
|
|
|
|
|
|
|
|
class MetricsServiceImpl : MetricsService.MetricsServiceBase |
|
|
|
class MetricsServiceImpl : MetricsService.MetricsServiceBase |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
const string GaugeName = "csharp_overall_qps"; |
|
|
|
|
|
|
|
|
|
|
|
readonly Histogram histogram; |
|
|
|
readonly Histogram histogram; |
|
|
|
readonly WallClockStopwatch wallClockStopwatch = new WallClockStopwatch(); |
|
|
|
readonly WallClockStopwatch wallClockStopwatch = new WallClockStopwatch(); |
|
|
|
|
|
|
|
|
|
|
@ -277,20 +279,40 @@ namespace Grpc.IntegrationTesting |
|
|
|
this.histogram = histogram; |
|
|
|
this.histogram = histogram; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override async Task GetAllGauges(EmptyMessage request, IServerStreamWriter<GaugeResponse> responseStream, ServerCallContext context) |
|
|
|
public override Task<GaugeResponse> GetGauge(GaugeRequest request, ServerCallContext context) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var snapshot = histogram.GetSnapshot(true); |
|
|
|
if (request.Name == GaugeName) |
|
|
|
var elapsedSnapshot = wallClockStopwatch.GetElapsedSnapshot(true); |
|
|
|
{ |
|
|
|
|
|
|
|
long qps = GetQpsAndReset(); |
|
|
|
|
|
|
|
|
|
|
|
double qps = snapshot.Count / elapsedSnapshot.Seconds; |
|
|
|
return Task.FromResult(new GaugeResponse |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Name = GaugeName, |
|
|
|
|
|
|
|
LongValue = qps |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
throw new RpcException(new Status(StatusCode.InvalidArgument, "Gauge does not exist")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override async Task GetAllGauges(EmptyMessage request, IServerStreamWriter<GaugeResponse> responseStream, ServerCallContext context) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
long qps = GetQpsAndReset(); |
|
|
|
|
|
|
|
|
|
|
|
var response = new GaugeResponse |
|
|
|
var response = new GaugeResponse |
|
|
|
{ |
|
|
|
{ |
|
|
|
Name = "csharp_overall_qps", |
|
|
|
Name = GaugeName, |
|
|
|
DoubleValue = qps |
|
|
|
LongValue = qps |
|
|
|
}; |
|
|
|
}; |
|
|
|
await responseStream.WriteAsync(response); |
|
|
|
await responseStream.WriteAsync(response); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long GetQpsAndReset() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var snapshot = histogram.GetSnapshot(true); |
|
|
|
|
|
|
|
var elapsedSnapshot = wallClockStopwatch.GetElapsedSnapshot(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (long) (snapshot.Count / elapsedSnapshot.Seconds); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|