Add a metric to a monitored machine

        :param metric_id: Metric_id (provided by self.available_metrics)
339637
def add_metric(self, metric_id):
        
        payload = {
            'metric_id': metric_id
        }
        data = json.dumps(payload)
        req = self.request(self.mist_client.uri+"/clouds/"+self.cloud.id+"/machines/"+self.id+"/metrics", data=data)
        req.put()
451400
def query_metric_definition(self, metric_type, metric_id):
        
        return self._get(self._get_metrics_single_url(metric_type, metric_id))
31116
protected void updateMetricCounters(String metricName, Map<String, Integer> metricNameCounters) {
        if (metricNameCounters.containsKey(metricName)) {
            metricNameCounters.put(metricName, metricNameCounters.get(metricName) + 1);
        } else {
            metricNameCounters.put(metricName, 1);
        }
    }
806325
def metric(self, measurement_name, values, tags=None, timestamp=None):
        
        if not measurement_name or values in (None, {}):
            # Don't try to send empty data
            return

        tags = tags or {}

        # Do a shallow merge of the metric tags and global tags
        all_tags = dict(self.tags, **tags)

        # Create a metric line from the input and then send it to socket
        line = Line(measurement_name, values, all_tags, timestamp)
        self.send(line.to_line_protocol())
612331
def get(self, metric_id=None, **kwargs):
        
        if metric_id is None:
            raise AttributeError('metric_id is required to get metric points.')

        return self._get('metrics/%s/points' % metric_id, data=kwargs)
291499
def register_metric_descriptor(self, oc_md):
        """"""
        metric_type = self.get_metric_type(oc_md)
        with self._md_lock:
            if metric_type in self._md_cache:
                return self._md_cache[metric_type]

        descriptor = self.get_metric_descriptor(oc_md)
        project_name = self.client.project_path(self.options.project_id)
        sd_md = self.client.create_metric_descriptor(project_name, descriptor)
        with self._md_lock:
            self._md_cache[metric_type] = sd_md
        return sd_md
1155926
def log_metrics(self, metrics_by_name, info):
        
        if self.metrics is None:
            # If, for whatever reason, the metrics collection has not been set
            # do not try to save anything there.
            return
        for key in metrics_by_name:
            query = {"run_id": self.run_entry['_id'],
                     "name": key}
            push = {"steps": {"$each": metrics_by_name[key]["steps"]},
                    "values": {"$each": metrics_by_name[key]["values"]},
                    "timestamps": {"$each": metrics_by_name[key]["timestamps"]}
                    }
            update = {"$push": push}
            result = self.metrics.update_one(query, update, upsert=True)
            if result.upserted_id is not None:
                # This is the first time we are storing this metric
                info.setdefault("metrics", []) \
                    .append({"name": key, "id": str(result.upserted_id)})
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;
  }
709177
protected void addMetric(String name, Metric metric) {
		if (metric == null) {
			LOG.warn("Ignoring attempted registration of a metric due to being null for name {}.", name);
			return;
		}
		// add the metric only if the group is still open
		synchronized (this) {
			if (!closed) {
				// immediately put without a 'contains' check to optimize the common case (no collision)
				// collisions are resolved later
				Metric prior = metrics.put(name, metric);

				// check for collisions with other metric names
				if (prior == null) {
					// no other metric with this name yet

					if (groups.containsKey(name)) {
						// we warn here, rather than failing, because metrics are tools that should not fail the
						// program when used incorrectly
						LOG.warn("Name collision: Adding a metric with the same name as a metric subgroup: '" +
								name + "'. Metric might not get properly reported. " + Arrays.toString(scopeComponents));
					}

					registry.register(metric, name, this);
				}
				else {
					// we had a collision. put back the original value
					metrics.put(name, prior);

					// we warn here, rather than failing, because metrics are tools that should not fail the
					// program when used incorrectly
					LOG.warn("Name collision: Group already contains a Metric with the name '" +
							name + "'. Metric will not be reported." + Arrays.toString(scopeComponents));
				}
			}
		}
	}
1151859
def get(self, id=None, **kwargs):
        
        if id is not None:
            return self._get('metrics/%s' % id, data=kwargs)
        else:
            return self._get('metrics', data=kwargs)
416966
def accumulate_metric(cls, name, value):
        
        metrics_cache = cls._get_metrics_cache()
        metrics_cache.setdefault(name, 0)
        metrics_cache.set(name, value)
1015481
def add_metric(self, labels, value, created=None, timestamp=None):
        
        self.samples.append(Sample(self.name + '_total', dict(zip(self._labelnames, labels)), value, timestamp))
        if created is not None:
            self.samples.append(Sample(self.name + '_created', dict(zip(self._labelnames, labels)), created, timestamp))
324307
def new_tank_metric(self, _type, name, hostname=None, group=None, source=None, *kw):
        
        if not _type:
            raise ValueError('Metric type should be defined.')

        if _type in available_metrics:
            metric_obj = available_metrics[_type](None, self.routing_queue)  # create metric object
            metric_info = {'type': _type,
                           'source': source,
                           'name': name,
                           'hostname': hostname,
                           'group': group}
            if kw is not None:
                metric_info.update(kw)
            metric_meta = pd.DataFrame({metric_obj.local_id: metric_info}).T  # create metric meta
            self.metrics_meta = self.metrics_meta.append(metric_meta)  # register metric meta
            self.metrics[metric_obj.local_id] = metric_obj  # register metric object

            # find subscribers for this metric
            this_metric_subscribers = self.__reversed_filter(self.subscribers, metric_info)
            if this_metric_subscribers.empty:
                logger.debug('subscriber for metric %s not found', metric_obj.local_id)
            else:
                logger.debug('Found subscribers for this metric, subscribing...: %s', this_metric_subscribers)
                # attach this metric id to discovered subscribers and select id <-> callbacks
                this_metric_subscribers['id'] = metric_obj.local_id
                found_callbacks = this_metric_subscribers[['id', 'callback']].set_index('id')
                # add this metric callbacks to DataManager's callbacks
                self.callbacks = self.callbacks.append(found_callbacks)
            return metric_obj
        else:
            raise NotImplementedError('Unknown metric type: %s' % _type)
897246
def add_reporter(self, reporter):
        """"""
        with self._lock:
            reporter.init(list(self.metrics.values()))
            self._reporters.append(reporter)
1006317
public boolean updateMetric(Metric metric) {
        String metricName = metric.getName();
        checkMetricIsEmpty(metricName);
        QueryPart<Metric> queryPart = new Query<Metric>("metrics")
                .path(metricName, true);
        return httpClientManager.updateMetaData(queryPart, patch(metric));
    }
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");
    }
  }
172583
def ticket_metric_show(self, ticket_metric_id, **kwargs):
        ""
        api_path = "/api/v2/ticket_metrics/{ticket_metric_id}.json"
        api_path = api_path.format(ticket_metric_id=ticket_metric_id)
        return self.call(api_path, **kwargs)