Only registers the metric if it is not already registered
@param name   the name of the metric
@param metric the metric
547572
public void registerNewMetrics(MetricName name, Metric metric) {
		final Set<MetricName> registeredNames = getNames();
		if (!registeredNames.contains(name)) {
			try {
				register(name, metric);
			} catch (IllegalArgumentException e){/* exception due to race condition*/}
		}
	}
481272
public void setMetricAlarms(java.util.Collection<MetricAlarm> metricAlarms) {
        if (metricAlarms == null) {
            this.metricAlarms = null;
            return;
        }

        this.metricAlarms = new com.amazonaws.internal.SdkInternalList<MetricAlarm>(metricAlarms);
    }
235095
function (metric) {
      metric.workerId = workerId
      metric.pid = process.pid
      if (!metric.sct) {
        if (metric.name && /collectd/.test(metric.name)) {
          metric.sct = 'OS'
        } else {
          metric.sct = 'APP'
        }
      }
      if (!metric.ts) {
        metric.ts = new Date().getTime()
      }
      if (!metric.type) {
        metric.type = this.defaultType
      }
      if (!metric.filters && metric.type === 'njs') {
        metric.filters = this.defaultFilters()
      }
      metric.spmLine = this.formatLine(metric)
      this.emit('metric', metric)
      if (metric.name) {
        this.emit(metric.name, metric)
      }
    }
1035956
public <T> void addMetric(String name, MetricTimeslice<T> timeslice)
    {
        metrics.put(name, timeslice);
    }
561254
private void reportMetered(final String name, final Metered meter) {
      EnumSet<MetricField> fields = reportedMetrics.get(name);
      if(fields == null) {
         return;
      }

      String nrName = buildRate(name);

      if(fields.contains(MetricField.ONE_MINUTE_RATE)) {
         NewRelic.recordMetric(nrName, (float)meter.getOneMinuteRate());
      }

      if(fields.contains(MetricField.FIVE_MINUTE_RATE)) {
         NewRelic.recordMetric(nrName, (float)meter.getFiveMinuteRate());
      }

      if(fields.contains(MetricField.FIFTEEN_MINUTE_RATE)) {
         NewRelic.recordMetric(nrName, (float)meter.getOneMinuteRate());
      }

      if(fields.contains(MetricField.MEAN_RATE)) {
         NewRelic.recordMetric(nrName, (float)meter.getMeanRate());
      }

      if(fields.contains(MetricField.COUNT)) {
         NewRelic.recordMetric(nrName, (float)meter.getCount());
      }
   }
442496
public Metric updateMetric(String metricName) {
    // [START updateMetric]
    MetricInfo metricInfo =
        MetricInfo.newBuilder(metricName, "severity>=ERROR")
            .setDescription("new description")
            .build();
    Metric metric = logging.update(metricInfo);
    // [END updateMetric]
    return metric;
  }
1355249
def new_metric(name, class_, *args, **kwargs):
    

    with LOCK:
        try:
            item = REGISTRY[name]
        except KeyError:
            item = REGISTRY[name] = class_(*args, **kwargs)
            return item

    raise DuplicateMetricError("Metric {} already exists of type {}".format(name, type(item).__name__))
602489
public static void register(MetricsRegistry metricsRegistry) {
        checkNotNull(metricsRegistry, "metricsRegistry");

        ThreadMXBean mxBean = ManagementFactory.getThreadMXBean();
        metricsRegistry.register(mxBean, "thread.threadCount", MANDATORY, ThreadMXBean::getThreadCount);
        metricsRegistry.register(mxBean, "thread.peakThreadCount", MANDATORY, ThreadMXBean::getPeakThreadCount);
        metricsRegistry.register(mxBean, "thread.daemonThreadCount", MANDATORY, ThreadMXBean::getDaemonThreadCount);
        metricsRegistry.register(mxBean, "thread.totalStartedThreadCount", MANDATORY, ThreadMXBean::getTotalStartedThreadCount);
    }
47424
def register(metric_name)
      metric_name = metric_name.to_s
      metric_exists = self.for(metric_name).present?

      if metric_exists
        raise(
          MetricAlreadyRegistered,
          "There's a metric already registered with the name `:#{metric_name}`, must be unique"
        )
      end

      metric_manifest = MetricManifest.new(metric_name: metric_name)

      yield(metric_manifest)

      metric_manifest.validate!

      metrics_manifests << metric_manifest
    end
1202340
@Override
  public Timer timer(String name) {
    final com.codahale.metrics.Timer timer = registry.timer(name);
    return new Timer() {

      @Override
      public Timer.Context time() {
        final com.codahale.metrics.Timer.Context timerContext = timer.time();
        return new Context() {
          @Override
          public void close() {
            timerContext.close();
          }
        };
      }

      @Override
      public void update(long duration, TimeUnit unit) {
        timer.update(duration, unit);
      }
    };
  }
828908
public static void register(@NonNull String name, @NonNull Lexicon lexicon) {
      lexiconCache.put(name.toLowerCase(), lexicon);
   }
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;
    }
643581
@Override
	public void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group) {
		final String fullName = group.getMetricIdentifier(metricName, this);

		synchronized (this) {
			if (metric instanceof Counter) {
				counters.put((Counter) metric, fullName);
				registry.register(fullName, new FlinkCounterWrapper((Counter) metric));
			}
			else if (metric instanceof Gauge) {
				gauges.put((Gauge<?>) metric, fullName);
				registry.register(fullName, FlinkGaugeWrapper.fromGauge((Gauge<?>) metric));
			} else if (metric instanceof Histogram) {
				Histogram histogram = (Histogram) metric;
				histograms.put(histogram, fullName);

				if (histogram instanceof DropwizardHistogramWrapper) {
					registry.register(fullName, ((DropwizardHistogramWrapper) histogram).getDropwizardHistogram());
				} else {
					registry.register(fullName, new FlinkHistogramWrapper(histogram));
				}
			} else if (metric instanceof Meter) {
				Meter meter = (Meter) metric;
				meters.put(meter, fullName);

				if (meter instanceof DropwizardMeterWrapper) {
					registry.register(fullName, ((DropwizardMeterWrapper) meter).getDropwizardMeter());
				} else {
					registry.register(fullName, new FlinkMeterWrapper(meter));
				}
			} else {
				log.warn("Cannot add metric of type {}. This indicates that the reporter " +
					"does not support this metric type.", metric.getClass().getName());
			}
		}
	}
1025914
public static void setMetricContextName(State state, String name) {
    state.setProp(Instrumented.METRIC_CONTEXT_NAME_KEY, name);
  }
284607
public void addMetric(final IMetric<?> metric) {
    // metric null or already present
    if (metric == null) {
      throw new IllegalArgumentException("Cannot add a null metric");
    }

    if (getMetricFromName(metric.getName()) == null) {
      logger.debug(String.format("Adding %s metric in Metric Manager", metric.getName()));
      this.metrics.add(metric);
      metric.updateMetricManager(this);
    } else {
      logger.error("Failed to add metric");
    }
  }
504140
@SuppressWarnings("FutureReturnValueIgnored")
  public void reportMetric(final IMetric<?> metric) {
    if (metric != null && isAvailable()) {
      try {
        final IMetric<?> metricSnapshot;
        // take snapshot
        synchronized (metric) {
          metricSnapshot = metric.getSnapshot();
        }
        logger.debug(String
            .format("Submitting %s metric for metric emission pool", metricSnapshot.getName()));
        // report to all emitters
        for (final IMetricEmitter metricEmitter : this.metricEmitters) {
          this.executorService.submit(() -> {
            try {
              metricEmitter.reportMetric(metricSnapshot);
            } catch (final Exception ex) {
              logger.error(
                  String.format("Failed to report %s metric due to ", metricSnapshot.getName()),
                  ex);
            }
          });
        }
      } catch (final CloneNotSupportedException ex) {
        logger.error(
            String.format("Failed to take snapshot for %s metric", metric.getClass().getName()),
            ex);
      }
    }
  }
94772
@Override
    public boolean remove(String name) {
        final Metric metric = metrics.remove(name);
        metadata.remove(name);
        if (metric != null) {
            return true;
        }
        return false;
    }