in csharp/rocketmq-client-csharp/ClientMeterManager.cs [55:110]
public void Reset(Metric metric)
{
lock (this)
{
var clientId = _client.GetClientId();
if (_clientMeter.Satisfy(metric))
{
Logger.Info(
$"Metric settings is satisfied by the current message meter, metric={metric}, clientId={clientId}");
return;
}
if (!metric.On)
{
Logger.Info($"Metric is off, clientId={clientId}");
_clientMeter.Shutdown();
_clientMeter = ClientMeter.DisabledInstance(clientId);
return;
}
var meterProvider = Sdk.CreateMeterProviderBuilder()
.SetResourceBuilder(ResourceBuilder.CreateEmpty())
.AddMeter(MeterName)
.AddOtlpExporter(delegate (OtlpExporterOptions options, MetricReaderOptions readerOptions)
{
options.Protocol = OtlpExportProtocol.Grpc;
options.Endpoint = new Uri(metric.Endpoints.GrpcTarget(_client.GetClientConfig().SslEnabled));
options.TimeoutMilliseconds = (int)_client.GetClientConfig().RequestTimeout.TotalMilliseconds;
options.HttpClientFactory = () => _httpClient;
readerOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds =
MetricExportPeriodInMillis;
})
.AddView(instrument =>
{
if (MeterName != instrument.Meter.Name)
{
return null;
}
return instrument.Name switch
{
MetricConstant.SendCostTimeMetricName => MetricConstant.Instance.SendCostTimeBucket,
MetricConstant.DeliveryLatencyMetricName => MetricConstant.Instance.DeliveryLatencyBucket,
MetricConstant.AwaitTimeMetricName => MetricConstant.Instance.AwaitTimeBucket,
MetricConstant.ProcessTimeMetricName => MetricConstant.Instance.ProcessTimeBucket,
_ => null
};
})
.Build();
var exist = _clientMeter;
_clientMeter = new ClientMeter(metric.Endpoints, meterProvider, clientId);
exist.Shutdown();
Logger.Info($"Metric is on, endpoints={metric.Endpoints}, clientId={clientId}");
}
}