Register the exposed metrics.

@param metricGroup Metric group to use for the metrics.
353619
private void registerMetrics(MetricGroup metricGroup) {
		metricGroup.gauge(NUMBER_OF_CHECKPOINTS_METRIC, new CheckpointsCounter());
		metricGroup.gauge(NUMBER_OF_IN_PROGRESS_CHECKPOINTS_METRIC, new InProgressCheckpointsCounter());
		metricGroup.gauge(NUMBER_OF_COMPLETED_CHECKPOINTS_METRIC, new CompletedCheckpointsCounter());
		metricGroup.gauge(NUMBER_OF_FAILED_CHECKPOINTS_METRIC, new FailedCheckpointsCounter());
		metricGroup.gauge(LATEST_RESTORED_CHECKPOINT_TIMESTAMP_METRIC, new LatestRestoredCheckpointTimestampGauge());
		metricGroup.gauge(LATEST_COMPLETED_CHECKPOINT_SIZE_METRIC, new LatestCompletedCheckpointSizeGauge());
		metricGroup.gauge(LATEST_COMPLETED_CHECKPOINT_DURATION_METRIC, new LatestCompletedCheckpointDurationGauge());
		metricGroup.gauge(LATEST_COMPLETED_CHECKPOINT_ALIGNMENT_BUFFERED_METRIC, new LatestCompletedCheckpointAlignmentBufferedGauge());
		metricGroup.gauge(LATEST_COMPLETED_CHECKPOINT_EXTERNAL_PATH_METRIC, new LatestCompletedCheckpointExternalPathGauge());
	}
1080354
@Override
    protected void collectMetrics(final Metrics metrics) {
        for (final JvmMetricsCollector collector : _collectorsEnabled) {
            collector.collect(metrics, _managementFactory);
        }
    }
1155721
@PostConstruct
    public void init() {
        this.metricRegistry.register(name("gc"), new GarbageCollectorMetricSet());
        this.metricRegistry.register(name("memory"), new MemoryUsageGaugeSet());
        this.metricRegistry.register(name("thread-states"), new ThreadStatesGaugeSet());
        this.metricRegistry.register(name("fd-usage"), new FileDescriptorRatioGauge());
    }
985795
public void processMetricAggregation() {
        if (!isEmpty(metricAggregation)) {
            String[] aggregations = metricAggregation.split(";");
            for (int i = 0; i < aggregations.length; i++) {
                String definition = aggregations[i].trim();
                int index0 = definition.indexOf("=");
                int index1 = definition.indexOf("(");
                int index2 = definition.indexOf(")");
                String aggregatedName = definition.substring(0, index0);
                String operation = definition.substring(index0 + 1, index1);
                String parameters = definition.substring(index1 + 1, index2);
                List<String> metricNames = new ArrayList<>();
                metricNames.add(operation);
                // Case a list of metricNames
                if (parameters.contains(",")) {
                    String[] listMetricNames = parameters.split(",");
                    for (int j = 0; j < listMetricNames.length; j++) {
                        metricNames.add(listMetricNames[j].trim());
                    }
                } else {
                    Pattern pattern = Pattern.compile(parameters);
                    for (String metricName : nameIdMetrics.keySet()) {
                        if (pattern.matcher(metricName).matches()) {
                            metricNames.add(metricName);
                        }
                    }
                }
                aggregatedMetrics.put(aggregatedName, metricNames);
            }
            log.debugf("Gnocchi Aggregated Metrics from %s -> %s", metricAggregation, aggregatedMetrics);
        }
    }
387953
public void setManagerGroup(String managerGroup) {

        CmsGroup group = checkGroup(managerGroup);
        if (group != null) {
            m_project.setManagerGroupId(group.getId());
        }
    }
1158739
public static void registerQueueLengthMetrics(MetricGroup group, SingleInputGate gate) {
		InputGateMetrics metrics = new InputGateMetrics(gate);

		group.gauge("totalQueueLen", metrics.getTotalQueueLenGauge());
		group.gauge("minQueueLen", metrics.getMinQueueLenGauge());
		group.gauge("maxQueueLen", metrics.getMaxQueueLenGauge());
		group.gauge("avgQueueLen", metrics.getAvgQueueLenGauge());
	}
836608
private boolean register(String name, Metric metric)
    { 
        boolean ret = allColumnFamilyMetrics.putIfAbsent(name,  new HashSet<Metric>()) == null;
        allColumnFamilyMetrics.get(name).add(metric);
        all.add(name);
        return ret;
    }
486408
def _setup_metric_group_definitions(self):
        
        # Dictionary of MetricGroupDefinition objects, by metric group name
        metric_group_definitions = dict()
        for mg_info in self.properties['metric-group-infos']:
            mg_name = mg_info['group-name']
            mg_def = MetricGroupDefinition(
                name=mg_name,
                resource_class=_resource_class_from_group(mg_name),
                metric_definitions=dict())
            for i, m_info in enumerate(mg_info['metric-infos']):
                m_name = m_info['metric-name']
                m_def = MetricDefinition(
                    index=i,
                    name=m_name,
                    type=_metric_type(m_info['metric-type']),
                    unit=_metric_unit_from_name(m_name))
                mg_def.metric_definitions[m_name] = m_def
            metric_group_definitions[mg_name] = mg_def
        return metric_group_definitions
1092951
public void setMetricsTrackerFactory(MetricsTrackerFactory metricsTrackerFactory)
   {
      if (metricsTrackerFactory != null) {
         this.metricsTracker = new MetricsTrackerDelegate(metricsTrackerFactory.create(config.getPoolName(), getPoolStats()));
      }
      else {
         this.metricsTracker = new NopMetricsTrackerDelegate();
      }
   }
1126183
private boolean registerMetricDescriptor(
      io.opencensus.metrics.export.MetricDescriptor metricDescriptor) {
    String metricName = metricDescriptor.getName();
    io.opencensus.metrics.export.MetricDescriptor existingMetricDescriptor =
        registeredMetricDescriptors.get(metricName);
    if (existingMetricDescriptor != null) {
      if (existingMetricDescriptor.equals(metricDescriptor)) {
        // Ignore metricDescriptor that are already registered.
        return true;
      } else {
        logger.log(
            Level.WARNING,
            "A different metric with the same name is already registered: "
                + existingMetricDescriptor);
        return false;
      }
    }
    registeredMetricDescriptors.put(metricName, metricDescriptor);
    if (isBuiltInMetric(metricName)) {
      return true; // skip creating metric descriptor for stackdriver built-in metrics.
    }

    Span span = tracer.getCurrentSpan();
    span.addAnnotation("Create Stackdriver Metric.");
    MetricDescriptor stackDriverMetricDescriptor =
        StackdriverExportUtils.createMetricDescriptor(
            metricDescriptor, projectId, domain, displayNamePrefix, constantLabels);

    CreateMetricDescriptorRequest request =
        CreateMetricDescriptorRequest.newBuilder()
            .setName(projectName.toString())
            .setMetricDescriptor(stackDriverMetricDescriptor)
            .build();
    try {
      metricServiceClient.createMetricDescriptor(request);
      span.addAnnotation("Finish creating MetricDescriptor.");
      return true;
    } catch (ApiException e) {
      logger.log(Level.WARNING, "ApiException thrown when creating MetricDescriptor.", e);
      span.setStatus(
          Status.CanonicalCode.valueOf(e.getStatusCode().getCode().name())
              .toStatus()
              .withDescription(
                  "ApiException thrown when creating MetricDescriptor: "
                      + StackdriverExportUtils.exceptionMessage(e)));
      return false;
    } catch (Throwable e) {
      logger.log(Level.WARNING, "Exception thrown when creating MetricDescriptor.", e);
      span.setStatus(
          Status.UNKNOWN.withDescription(
              "Exception thrown when creating MetricDescriptor: "
                  + StackdriverExportUtils.exceptionMessage(e)));
      return false;
    }
  }
577177
static void flushMetricsLogger(final MetricsLogger metricsLogger) {
        metricsLogger.flushToString(MetricsManager::queue);
        MetricsManager.rootMetricsLogger.flushToString(MetricsManager::queue);
    }
964203
public void registerAny(Metric2Set metrics) {
		for (Map.Entry<MetricName, Metric> entry : metrics.getMetrics().entrySet()) {
			registerNewMetrics(entry.getKey(), entry.getValue());
		}
	}
705433
public void setMetricDataResults(java.util.Collection<MetricDataResult> metricDataResults) {
        if (metricDataResults == null) {
            this.metricDataResults = null;
            return;
        }

        this.metricDataResults = new com.amazonaws.internal.SdkInternalList<MetricDataResult>(metricDataResults);
    }
1095311
public static void collectMetric(
    MetricsRecordBuilder metricsRecordBuilder, String name, Metric metric) {

    if (metric instanceof Timer) {
      Timer t = (Timer) metric;
      metricsRecordBuilder
        .addCounter(new ShuffleServiceMetricsInfo(name + "_count", "Count of timer " + name),
          t.getCount())
        .addGauge(
          new ShuffleServiceMetricsInfo(name + "_rate15", "15 minute rate of timer " + name),
          t.getFifteenMinuteRate())
        .addGauge(
          new ShuffleServiceMetricsInfo(name + "_rate5", "5 minute rate of timer " + name),
          t.getFiveMinuteRate())
        .addGauge(
          new ShuffleServiceMetricsInfo(name + "_rate1", "1 minute rate of timer " + name),
          t.getOneMinuteRate())
        .addGauge(new ShuffleServiceMetricsInfo(name + "_rateMean", "Mean rate of timer " + name),
          t.getMeanRate());
    } else if (metric instanceof Meter) {
      Meter m = (Meter) metric;
      metricsRecordBuilder
        .addCounter(new ShuffleServiceMetricsInfo(name + "_count", "Count of meter " + name),
          m.getCount())
        .addGauge(
          new ShuffleServiceMetricsInfo(name + "_rate15", "15 minute rate of meter " + name),
          m.getFifteenMinuteRate())
        .addGauge(
          new ShuffleServiceMetricsInfo(name + "_rate5", "5 minute rate of meter " + name),
          m.getFiveMinuteRate())
        .addGauge(
          new ShuffleServiceMetricsInfo(name + "_rate1", "1 minute rate of meter " + name),
          m.getOneMinuteRate())
        .addGauge(new ShuffleServiceMetricsInfo(name + "_rateMean", "Mean rate of meter " + name),
          m.getMeanRate());
    } else if (metric instanceof Gauge) {
      final Object gaugeValue = ((Gauge) metric).getValue();
      if (gaugeValue instanceof Integer) {
        metricsRecordBuilder.addGauge(getShuffleServiceMetricsInfo(name), (Integer) gaugeValue);
      } else if (gaugeValue instanceof Long) {
        metricsRecordBuilder.addGauge(getShuffleServiceMetricsInfo(name), (Long) gaugeValue);
      } else if (gaugeValue instanceof Float) {
        metricsRecordBuilder.addGauge(getShuffleServiceMetricsInfo(name), (Float) gaugeValue);
      } else if (gaugeValue instanceof Double) {
        metricsRecordBuilder.addGauge(getShuffleServiceMetricsInfo(name), (Double) gaugeValue);
      } else {
        throw new IllegalStateException(
                "Not supported class type of metric[" + name + "] for value " + gaugeValue);
      }
    } else if (metric instanceof Counter) {
      Counter c = (Counter) metric;
      long counterValue = c.getCount();
      metricsRecordBuilder.addGauge(new ShuffleServiceMetricsInfo(name, "Number of " +
          "connections to shuffle service " + name), counterValue);
    }
  }
875180
private void addAttributes(PublisherRegistration publisherRegistration, String group) {
        // if group == null; group = "DEFAULT_GROUP"
        if (StringUtils.isNotEmpty(group)) {
            publisherRegistration.setGroup(group);
        }

    }
848317
public void add(final Metric metric) {
		Preconditions.checkNotNull(metric);
		
		// get the aggregate for this minute
		
		MetricAggregate aggregate = getAggregate(metric.getIdentity());
		
		// add the current metric into the aggregate
		
		switch (metric.getIdentity().getType()) {
			case COUNTER: 
			case TIMER: 
			case AVERAGE:
				aggregate.setCount(aggregate.getCount() + 1);
				aggregate.setValue(aggregate.getValue() + metric.getValue());
			    break;
			case GAUGE:
				aggregate.setCount(1);
				if (metric.isIncrement()) {
					aggregate.setValue(aggregate.getValue() + metric.getValue());
				} else {
					aggregate.setValue(metric.getValue());
				}
			    break;	
			default:
				LOGGER.info("Unable to aggregate {} metric type", metric.getIdentity().getType());
				break;
		}
	}
1273142
public static TraceComponent register(Class<?> aClass, String group) {
        return register(aClass, group, null);
    }