in grpc-gcp/src/main/java/com/google/cloud/grpc/GcpManagedChannel.java [319:530]
private void initMetrics() {
final GcpMetricsOptions metricsOptions = options.getMetricsOptions();
if (metricsOptions == null) {
logger.info(log("Metrics options are empty. Metrics disabled."));
initLogMetrics();
return;
}
logMetricsOptions();
if (metricsOptions.getMetricRegistry() == null) {
logger.info(log("Metric registry is null. Metrics disabled."));
initLogMetrics();
return;
}
logger.info(log("Metrics enabled."));
metricRegistry = metricsOptions.getMetricRegistry();
labelKeys.addAll(metricsOptions.getLabelKeys());
labelKeysWithResult.addAll(metricsOptions.getLabelKeys());
labelValues.addAll(metricsOptions.getLabelValues());
labelValuesSuccess.addAll(metricsOptions.getLabelValues());
labelValuesError.addAll(metricsOptions.getLabelValues());
final LabelKey poolKey =
LabelKey.create(GcpMetricsConstants.POOL_INDEX_LABEL, GcpMetricsConstants.POOL_INDEX_DESC);
labelKeys.add(poolKey);
labelKeysWithResult.add(poolKey);
final LabelValue poolIndex = LabelValue.create(metricPoolIndex);
labelValues.add(poolIndex);
labelValuesSuccess.add(poolIndex);
labelValuesError.add(poolIndex);
metricPrefix = metricsOptions.getNamePrefix();
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MIN_READY_CHANNELS,
"The minimum number of channels simultaneously in the READY state.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportMinReadyChannels);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MAX_READY_CHANNELS,
"The maximum number of channels simultaneously in the READY state.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportMaxReadyChannels);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MAX_CHANNELS,
"The maximum number of channels in the pool.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportMaxChannels);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MAX_ALLOWED_CHANNELS,
"The maximum number of channels allowed in the pool. (The poll max size)",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportMaxAllowedChannels);
createDerivedLongCumulativeTimeSeries(
GcpMetricsConstants.METRIC_NUM_CHANNEL_DISCONNECT,
"The number of disconnections (occurrences when a channel deviates from the READY state)",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportNumChannelDisconnect);
createDerivedLongCumulativeTimeSeries(
GcpMetricsConstants.METRIC_NUM_CHANNEL_CONNECT,
"The number of times when a channel reached the READY state.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportNumChannelConnect);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MIN_CHANNEL_READINESS_TIME,
"The minimum time it took to transition a channel to the READY state.",
GcpMetricsConstants.MICROSECOND,
this,
GcpManagedChannel::reportMinReadinessTime);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_AVG_CHANNEL_READINESS_TIME,
"The average time it took to transition a channel to the READY state.",
GcpMetricsConstants.MICROSECOND,
this,
GcpManagedChannel::reportAvgReadinessTime);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MAX_CHANNEL_READINESS_TIME,
"The maximum time it took to transition a channel to the READY state.",
GcpMetricsConstants.MICROSECOND,
this,
GcpManagedChannel::reportMaxReadinessTime);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MIN_ACTIVE_STREAMS,
"The minimum number of active streams on any channel.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportMinActiveStreams);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MAX_ACTIVE_STREAMS,
"The maximum number of active streams on any channel.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportMaxActiveStreams);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MIN_TOTAL_ACTIVE_STREAMS,
"The minimum total number of active streams across all channels.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportMinTotalActiveStreams);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MAX_TOTAL_ACTIVE_STREAMS,
"The maximum total number of active streams across all channels.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportMaxTotalActiveStreams);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MIN_AFFINITY,
"The minimum number of affinity count on any channel.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportMinAffinity);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MAX_AFFINITY,
"The maximum number of affinity count on any channel.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportMaxAffinity);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_NUM_AFFINITY,
"The total number of affinity count across all channels.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportNumAffinity);
createDerivedLongGaugeTimeSeriesWithResult(
GcpMetricsConstants.METRIC_MIN_CALLS,
"The minimum number of completed calls on any channel.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportMinOkCalls,
GcpManagedChannel::reportMinErrCalls);
createDerivedLongGaugeTimeSeriesWithResult(
GcpMetricsConstants.METRIC_MAX_CALLS,
"The maximum number of completed calls on any channel.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportMaxOkCalls,
GcpManagedChannel::reportMaxErrCalls);
createDerivedLongCumulativeTimeSeriesWithResult(
GcpMetricsConstants.METRIC_NUM_CALLS_COMPLETED,
"The number of calls completed across all channels.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportTotalOkCalls,
GcpManagedChannel::reportTotalErrCalls);
createDerivedLongCumulativeTimeSeriesWithResult(
GcpMetricsConstants.METRIC_NUM_FALLBACKS,
"The number of calls that had fallback to another channel.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportSucceededFallbacks,
GcpManagedChannel::reportFailedFallbacks);
createDerivedLongCumulativeTimeSeries(
GcpMetricsConstants.METRIC_NUM_UNRESPONSIVE_DETECTIONS,
"The number of unresponsive connections detected.",
GcpMetricsConstants.COUNT,
this,
GcpManagedChannel::reportUnresponsiveDetectionCount);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MIN_UNRESPONSIVE_DETECTION_TIME,
"The minimum time it took to detect an unresponsive connection.",
GcpMetricsConstants.MILLISECOND,
this,
GcpManagedChannel::reportMinUnresponsiveMs);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MAX_UNRESPONSIVE_DETECTION_TIME,
"The maximum time it took to detect an unresponsive connection.",
GcpMetricsConstants.MILLISECOND,
this,
GcpManagedChannel::reportMaxUnresponsiveMs);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MIN_UNRESPONSIVE_DROPPED_CALLS,
"The minimum calls dropped before detection of an unresponsive connection.",
GcpMetricsConstants.MILLISECOND,
this,
GcpManagedChannel::reportMinUnresponsiveDrops);
createDerivedLongGaugeTimeSeries(
GcpMetricsConstants.METRIC_MAX_UNRESPONSIVE_DROPPED_CALLS,
"The maximum calls dropped before detection of an unresponsive connection.",
GcpMetricsConstants.MILLISECOND,
this,
GcpManagedChannel::reportMaxUnresponsiveDrops);
}