Put the metrics from a worker with a hostname. If all the old metrics associated with this
instance will be removed and then replaced by the latest.

@param hostname the hostname of the instance
@param metrics the new worker metrics
763228
public void putWorkerMetrics(String hostname, List<Metric> metrics) {
    if (metrics.isEmpty()) {
      return;
    }
    synchronized (mWorkerMetrics) {
      mWorkerMetrics.removeByField(ID_INDEX, getFullInstanceId(hostname, null));
      for (Metric metric : metrics) {
        if (metric.getHostname() == null) {
          continue; // ignore metrics whose hostname is null
        }
        mWorkerMetrics.add(metric);
      }
    }
  }
1287743
public void setMetricData(java.util.Collection<MetricDatum> metricData) {
        if (metricData == null) {
            this.metricData = null;
            return;
        }

        this.metricData = new com.amazonaws.internal.SdkInternalList<MetricDatum>(metricData);
    }
588538
public boolean remove(MetricName name) {
		final Metric metric = metrics.remove(name);
		if (metric != null) {
			// We have to unregister the Metric with the legacy Dropwizard Metric registry as
			// well to support existing reports and listeners
			metricRegistry.remove(name.toGraphiteName());
			return true;
		}
		return false;
	}
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*/}
		}
	}
416966
def accumulate_metric(cls, name, value):
        
        metrics_cache = cls._get_metrics_cache()
        metrics_cache.setdefault(name, 0)
        metrics_cache.set(name, value)
1080354
@Override
    protected void collectMetrics(final Metrics metrics) {
        for (final JvmMetricsCollector collector : _collectorsEnabled) {
            collector.collect(metrics, _managementFactory);
        }
    }
717798
public Group withMetrics(java.util.Map<String, MetricValue> metrics) {
        setMetrics(metrics);
        return this;
    }
983065
protected void setMetric(String metric) {
        requireArgument(metric != null && !metric.isEmpty(), "Metric name cannot be null or empty.");
        _metric = metric;
    }
1102871
private void updateClusterMetrics(String topologyId, TopologyMetric tpMetric) {
        if (tpMetric.get_topologyMetric().get_metrics_size() == 0) {
            return;
        }

        MetricInfo topologyMetrics = tpMetric.get_topologyMetric();
        // make a new MetricInfo to save the topologyId's metric
        MetricInfo clusterMetrics = MetricUtils.mkMetricInfo();
        Set<String> metricNames = new HashSet<>();

        for (Map.Entry<String, Map<Integer, MetricSnapshot>> entry : topologyMetrics.get_metrics().entrySet()) {
            String metricName = MetricUtils.topo2clusterName(entry.getKey());
            MetricType metricType = MetricUtils.metricType(metricName);
            Map<Integer, MetricSnapshot> winData = new HashMap<>();

            for (Map.Entry<Integer, MetricSnapshot> entryData : entry.getValue().entrySet()) {
                MetricSnapshot snapshot = entryData.getValue().deepCopy();
                winData.put(entryData.getKey(), snapshot);
                if (metricType == MetricType.HISTOGRAM) {
                    // reset topology metric points
                    entryData.getValue().set_points(new byte[0]);
                    entryData.getValue().set_pointSize(0);
                }
            }
            clusterMetrics.put_to_metrics(metricName, winData);
            metricNames.add(metricName);
        }

        // save to local cache, waiting for merging
        TopologyMetricContext clusterTpMetricContext = context.getClusterTopologyMetricContext();
        clusterTpMetricContext.addToMemCache(topologyId, clusterMetrics);
        context.registerMetrics(JStormMetrics.CLUSTER_METRIC_KEY, metricNames);

    }
813073
@Override
	public void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group) {
		final String domain = generateJmxDomain(metricName, group);
		final Hashtable<String, String> table = generateJmxTable(group.getAllVariables());

		AbstractBean jmxMetric;
		ObjectName jmxName;
		try {
			jmxName = new ObjectName(domain, table);
		} catch (MalformedObjectNameException e) {
			/**
			 * There is an implementation error on our side if this occurs. Either the domain was modified and no longer
			 * conforms to the JMX domain rules or the table wasn't properly generated.
			 */
			LOG.debug("Implementation error. The domain or table does not conform to JMX rules." , e);
			return;
		}

		if (metric instanceof Gauge) {
			jmxMetric = new JmxGauge((Gauge<?>) metric);
		} else if (metric instanceof Counter) {
			jmxMetric = new JmxCounter((Counter) metric);
		} else if (metric instanceof Histogram) {
			jmxMetric = new JmxHistogram((Histogram) metric);
		} else if (metric instanceof Meter) {
			jmxMetric = new JmxMeter((Meter) metric);
		} else {
			LOG.error("Cannot add unknown metric type: {}. This indicates that the metric type " +
				"is not supported by this reporter.", metric.getClass().getName());
			return;
		}

		try {
			synchronized (this) {
				mBeanServer.registerMBean(jmxMetric, jmxName);
				registeredMetrics.put(metric, jmxName);
			}
		} catch (NotCompliantMBeanException e) {
			// implementation error on our side
			LOG.debug("Metric did not comply with JMX MBean rules.", e);
		} catch (InstanceAlreadyExistsException e) {
			LOG.warn("A metric with the name " + jmxName + " was already registered.", e);
		} catch (Throwable t) {
			LOG.warn("Failed to register metric", t);
		}
	}
907671
synchronized public void performHostDiscovery(MetricRegistry metricRegistry) {
        // Host discovery is not idempotent; only take action if it hasn't been performed.
        if (_hostDiscoveryPerformed) {
            return;
        }

        Iterable<String> hosts = null;

        // Statically configured list of seeds.
        if (_seeds != null) {
            hosts = Splitter.on(',').trimResults().split(_seeds);
        }

        // Perform ZooKeeper discovery to find the seeds.
        if (_zooKeeperServiceName != null) {
            checkState(hosts == null, "Too many host discovery mechanisms configured.");
            checkState(_curator != null,
                    "ZooKeeper host discovery is configured but withZooKeeperHostDiscovery() was not called.");

            try (HostDiscovery hostDiscovery = new ZooKeeperHostDiscovery(_curator, _zooKeeperServiceName, metricRegistry)) {
                List<String> hostList = Lists.newArrayList();
                for (ServiceEndPoint endPoint : hostDiscovery.getHosts()) {
                    // The host:port is in the end point ID
                    hostList.add(endPoint.getId());

                    // The partitioner class name is in the json-encoded end point payload
                    if (_partitioner == null && endPoint.getPayload() != null) {
                        JsonNode payload = JsonHelper.fromJson(endPoint.getPayload(), JsonNode.class);
                        String partitioner = payload.path("partitioner").textValue();
                        if (partitioner != null) {
                            _partitioner = CassandraPartitioner.fromClass(partitioner);
                        }
                    }
                }
                hosts = hostList;
            } catch (IOException ex) {
                // suppress any IOExceptions that might result from closing our ZooKeeperHostDiscovery
            }
        }

        checkState(hosts != null, "No Cassandra host discovery mechanisms are configured.");
        //noinspection ConstantConditions
        checkState(!Iterables.isEmpty(hosts), "Unable to discover any Cassandra seed instances.");
        checkState(_partitioner != null, "Cassandra partitioner not configured or discoverable.");
        _seeds = Joiner.on(',').join(hosts);
        _hostDiscoveryPerformed = true;
    }
1202537
public void registerMetrics(MetricRegistry metricRegistry, String pipelineId, String stageId) {
        if (id() == null) {
            LOG.debug("Not registering metrics for unsaved rule {}", name());
            return;
        }
        if (id() != null) {
            globalExecuted = registerGlobalMeter(metricRegistry, "executed");
            localExecuted = registerLocalMeter(metricRegistry, pipelineId, stageId, "executed");

            globalFailed = registerGlobalMeter(metricRegistry, "failed");
            localFailed = registerLocalMeter(metricRegistry, pipelineId, stageId, "failed");

            globalMatched = registerGlobalMeter(metricRegistry, "matched");
            localMatched = registerLocalMeter(metricRegistry, pipelineId, stageId, "matched");

            globalNotMatched = registerGlobalMeter(metricRegistry, "not-matched");
            localNotMatched = registerLocalMeter(metricRegistry, pipelineId, stageId, "not-matched");

        }
    }
745304
public static synchronized <T> void registerGaugeIfAbsent(String name, Gauge<T> metric) {
    if (!METRIC_REGISTRY.getGauges().containsKey(name)) {
      METRIC_REGISTRY.register(name, metric);
    }
  }
698850
synchronized void decommissionNodes(Set<String> hosts)
  throws IOException {
    LOG.info("Decommissioning " + hosts.size() + " nodes");
    // create a list of tracker hostnames
    synchronized (taskTrackers) {
      synchronized (trackerExpiryQueue) {
        int trackersDecommissioned = 0;
        for (String host : hosts) {
          LOG.info("Decommissioning host " + host);
          Set<TaskTracker> trackers = hostnameToTaskTracker.remove(host);
          if (trackers != null) {
            for (TaskTracker tracker : trackers) {
              LOG.info("Decommission: Losing tracker " + tracker.getTrackerName() +
                       " on host " + host);
              removeTracker(tracker);
            }
            trackersDecommissioned += trackers.size();
          }
          LOG.info("Host " + host + " is ready for decommissioning");
        }
      }
    }
  }
120905
public void registerMetrics() {
        if (metricsAreRegistered) {
            return;
        }
        getMetricRegistry().register("jvm.attribute", new JvmAttributeGaugeSet());
        getMetricRegistry().register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory
                                                                               .getPlatformMBeanServer()));
        getMetricRegistry().register("jvm.classloader", new ClassLoadingGaugeSet());
        getMetricRegistry().register("jvm.filedescriptor", new FileDescriptorRatioGauge());
        getMetricRegistry().register("jvm.gc", new GarbageCollectorMetricSet());
        getMetricRegistry().register("jvm.memory", new MemoryUsageGaugeSet());
        getMetricRegistry().register("jvm.threads", new ThreadStatesGaugeSet());

        JmxReporter.forRegistry(metricRegistry).build().start();
        metricsAreRegistered = true;
    }
77693
public boolean deleteMetric(Metric metric) {
        String metricName = metric.getName();
        checkMetricIsEmpty(metricName);
        QueryPart<Metric> queryPart = new Query<Metric>("metrics")
                .path(metricName, true);
        return httpClientManager.updateMetaData(queryPart, delete());
    }
472152
public void setMetricData(java.util.Collection<MetricDatapoint> metricData) {
        if (metricData == null) {
            this.metricData = null;
            return;
        }

        this.metricData = new java.util.ArrayList<MetricDatapoint>(metricData);
    }