<pre>
The name of the metric this quota limit applies to. The quota limits with
the same metric will be checked together during runtime. The metric must be
defined within the service config.
</pre>

<code>string metric = 8;</code>
190468
public com.google.protobuf.ByteString
      getMetricBytes() {
    java.lang.Object ref = metric_;
    if (ref instanceof java.lang.String) {
      com.google.protobuf.ByteString b = 
          com.google.protobuf.ByteString.copyFromUtf8(
              (java.lang.String) ref);
      metric_ = b;
      return b;
    } else {
      return (com.google.protobuf.ByteString) ref;
    }
  }
758652
public Metric createMetricAsync(String metricName)
      throws ExecutionException, InterruptedException {
    // [START createMetricAsync]
    MetricInfo metricInfo = MetricInfo.of(metricName, "severity>=ERROR");
    Future<Metric> future = logging.createAsync(metricInfo);
    // ...
    Metric metric = future.get();
    // [END createMetricAsync]
    return metric;
  }
448332
public <S extends Number> Metric<S> set(S value) {
        return new Metric<>(this.getName(), value);
    }
759795
public java.lang.String getMetric() {
    java.lang.Object ref = metric_;
    if (ref instanceof java.lang.String) {
      return (java.lang.String) ref;
    } else {
      com.google.protobuf.ByteString bs = 
          (com.google.protobuf.ByteString) ref;
      java.lang.String s = bs.toStringUtf8();
      metric_ = s;
      return s;
    }
  }
1138881
@Override
	public void register(Metric metric, String metricName, AbstractMetricGroup group) {
		synchronized (lock) {
			if (isShutdown()) {
				LOG.warn("Cannot register metric, because the MetricRegistry has already been shut down.");
			} else {
				if (reporters != null) {
					for (int i = 0; i < reporters.size(); i++) {
						MetricReporter reporter = reporters.get(i);
						try {
							if (reporter != null) {
								FrontMetricGroup front = new FrontMetricGroup<AbstractMetricGroup<?>>(i, group);
								reporter.notifyOfAddedMetric(metric, metricName, front);
							}
						} catch (Exception e) {
							LOG.warn("Error while registering metric.", e);
						}
					}
				}
				try {
					if (queryService != null) {
						queryService.addMetric(metricName, metric, group);
					}
				} catch (Exception e) {
					LOG.warn("Error while registering metric.", e);
				}
				try {
					if (metric instanceof View) {
						if (viewUpdater == null) {
							viewUpdater = new ViewUpdater(executor);
						}
						viewUpdater.notifyOfAddedView((View) metric);
					}
				} catch (Exception e) {
					LOG.warn("Error while registering metric.", e);
				}
			}
		}
	}
606658
private Deferred<Object> resolveMetric() {
    if (metric == null || metric.isEmpty()) {
      throw new IllegalArgumentException("The metric cannot be empty");
    }
    if (tags == null) {
      throw new IllegalArgumentException("Tags cannot be null or empty "
          + "when getting a TSUID");
    }
    
    class TagsCB implements Callback<Object, ArrayList<byte[]>> {
      @Override
      public Object call(final ArrayList<byte[]> tag_list) throws Exception {
        setTagUIDs(tag_list);
        return null;
      }
      @Override
      public String toString() {
        return "Tag resolution callback";
      }
    }
    
    class MetricCB implements Callback<Deferred<Object>, byte[]> {
      @Override
      public Deferred<Object> call(final byte[] uid) 
          throws Exception {
        setMetricUID(uid);
        if (tags.isEmpty()) {
          setTagUIDs(new ArrayList<byte[]>(0));
          return null;
        }
        return Tags.resolveAllAsync(tsdb, tags).addCallback(new TagsCB());
      }
      @Override
      public String toString() {
        return "Metric resolution callback";
      }
    }
    
    return tsdb.getUIDAsync(UniqueIdType.METRIC, metric)
        .addCallbackDeferring(new MetricCB());
  }
33338
public final void updateMetric(MetricName name, Object value) {
        if (!started) {
            return;
        }
        PcpValueInfo info = metricData.get(name);
        if (info == null) {
            throw new IllegalArgumentException("Metric " + name
                    + " was not added before initialising the writer");
        }
        updateValue(info, value);
    }
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*/}
		}
	}
202714
public Metric updateMetricAsync(String metricName)
      throws ExecutionException, InterruptedException {
    // [START updateMetricAsync]
    MetricInfo metricInfo =
        MetricInfo.newBuilder(metricName, "severity>=ERROR")
            .setDescription("new description")
            .build();
    Future<Metric> future = logging.updateAsync(metricInfo);
    // ...
    Metric metric = future.get();
    // [END updateMetricAsync]
    return metric;
  }
648710
public ResourceMetadata getResourceMetadata() {
    if (poolInfo.getPoolName() == null ||
        !counters.containsKey(MetricName.MIN) ||
        !counters.containsKey(MetricName.MAX) ||
        !counters.containsKey(MetricName.GRANTED) ||
        !counters.containsKey(MetricName.REQUESTED)) {
      return null;
    }

    return new ResourceMetadata(
        PoolInfo.createStringFromPoolInfo(poolInfo),
        counters.get(MetricName.MIN).intValue(),
        counters.get(MetricName.MAX).intValue(),
        counters.get(MetricName.GRANTED).intValue(),
        counters.get(MetricName.REQUESTED).intValue());
  }
649972
private double getMetricSampleCountValue(final String metricName) {
        int min = 0;
        int max = 1;

        if (metricName.equals(Constants.CPU_UTILIZATION)) {
            min = Integer
                    .parseInt(
                            PropertiesUtils.getProperty(Constants.CPU_UTILIZATION_RANGE_SAMPLECOUNT)
                                    .split(",")[0]);
            max = Integer
                    .parseInt(
                            PropertiesUtils.getProperty(Constants.CPU_UTILIZATION_RANGE_SAMPLECOUNT)
                                    .split(",")[1]);
        } else if (metricName.equals(Constants.DISK_READ_BYTES)) {
            min = Integer
                    .parseInt(
                            PropertiesUtils.getProperty(Constants.DISK_READ_BYTES_RANGE_SAMPLECOUNT)
                                    .split(",")[0]);
            max = Integer
                    .parseInt(
                            PropertiesUtils.getProperty(Constants.DISK_READ_BYTES_RANGE_SAMPLECOUNT)
                                    .split(",")[1]);
        } else if (metricName.equals(Constants.DISK_READ_OPS)) {
            min = Integer
                    .parseInt(PropertiesUtils.getProperty(Constants.DISK_READ_OPS_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer
                    .parseInt(PropertiesUtils.getProperty(Constants.DISK_READ_OPS_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.DISK_WRITE_BYTES)) {
            min = Integer
                    .parseInt(PropertiesUtils
                            .getProperty(Constants.DISK_WRITE_BYTES_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer
                    .parseInt(PropertiesUtils
                            .getProperty(Constants.DISK_WRITE_BYTES_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.DISK_WRITE_OPS)) {
            min = Integer
                    .parseInt(PropertiesUtils
                            .getProperty(Constants.DISK_WRITE_OPS_RANGE_SAMPLECOUNT).split(",")[0]);
            max = Integer
                    .parseInt(PropertiesUtils
                            .getProperty(Constants.DISK_WRITE_OPS_RANGE_SAMPLECOUNT).split(",")[1]);
        } else if (metricName.equals(Constants.NETWORK_IN)) {
            min = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.NETWORK_IN_RANGE_SAMPLECOUNT).split(",")[0]);
            max = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.NETWORK_IN_RANGE_SAMPLECOUNT).split(",")[1]);
        } else if (metricName.equals(Constants.NETWORK_OUT)) {
            min = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.NETWORK_OUT_RANGE_SAMPLECOUNT).split(",")[0]);
            max = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.NETWORK_OUT_RANGE_SAMPLECOUNT).split(",")[1]);
        } else if (metricName.equals(Constants.NETWORK_PACKETS_IN)) {
            min = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.NETWORK_PACKETS_IN_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.NETWORK_PACKETS_IN_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.NETWORK_PACKETS_OUT)) {
            min = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.NETWORK_PACKETS_OUT_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.NETWORK_PACKETS_OUT_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.STATUS_CHECK_FAILED)) {
            min = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.STATUS_CHECK_FAILED_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.STATUS_CHECK_FAILED_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.STATUS_CHECK_FAILED_INSTANCE)) {
            min = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.STATUS_CHECK_FAILED_INSTANCE_RANGE_SAMPLECOUNT)
                    .split(",")[0]);
            max = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.STATUS_CHECK_FAILED_INSTANCE_RANGE_SAMPLECOUNT)
                    .split(",")[1]);
        } else if (metricName.equals(Constants.STATUS_CHECK_FAILED_SYSTEM)) {
            min = Integer.parseInt(
                    PropertiesUtils
                            .getProperty(Constants.STATUS_CHECK_FAILED_SYSTEM_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer.parseInt(
                    PropertiesUtils
                            .getProperty(Constants.STATUS_CHECK_FAILED_SYSTEM_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.CPU_CREDIT_USAGE)) {
            min = Integer
                    .parseInt(PropertiesUtils
                            .getProperty(Constants.CPU_CREDIT_USAGE_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer
                    .parseInt(PropertiesUtils
                            .getProperty(Constants.CPU_CREDIT_USAGE_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.ESTIMATED_CHARGES)) {
            min = Integer.parseInt(PropertiesUtils.getProperty(
                    Constants.ESTIMATED_CHARGES_RANGE_SAMPLECOUNT).split(",")[0]);
            max = Integer.parseInt(PropertiesUtils.getProperty(
                    Constants.ESTIMATED_CHARGES_RANGE_SAMPLECOUNT).split(",")[1]);
        } else if (metricName.equals(Constants.CPU_CREDIT_BALANCE)) {
            min = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.CPU_CREDIT_BALANCE_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.CPU_CREDIT_BALANCE_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        }

        return new Random().nextInt((max - min) + 1) + min;
    }
733018
@com.fasterxml.jackson.annotation.JsonProperty("Limit")
    public void setLimit(String limit) {
        this.limit = limit;
    }
1122880
public Metric createMetric(String metricName) {
    // [START createMetric]
    MetricInfo metricInfo = MetricInfo.of(metricName, "severity>=ERROR");
    Metric metric = logging.create(metricInfo);
    // [END createMetric]
    return metric;
  }
630267
@Override
    int guessApproxLength() {
        int total = super.guessApproxLength();
        int size = 0;
        List props;

        // Assume 40 bytes per property (string name + value)
        // Each property map may be cached in a transient, or in the base JMF (or both!)
        // If there are no properties, the names may be represented by the EMPTY
        // JMF List, in which case we do NOT want to actually get them.
        // The property will only be flattened 'once' so only count it once.
        if (jmsUserPropertyMap != null) {
            size += jmsUserPropertyMap.size();
        }
        else {
            if (getApi().isNotEMPTYlist(JsApiAccess.JMSPROPERTY_NAME)) {
                props = (List) getApi().getField(JsApiAccess.JMSPROPERTY_NAME);
                if (props != null) {
                    size += props.size();
                }
            }
        }

        if (otherUserPropertyMap != null) {
            size += otherUserPropertyMap.size();
        }
        else {
            if (getApi().isNotEMPTYlist(JsApiAccess.OTHERPROPERTY_NAME)) {
                props = (List) getApi().getField(JsApiAccess.OTHERPROPERTY_NAME);
                if (props != null) {
                    size += props.size();
                }
            }
        }

        if (jmsSystemPropertyMap != null) {
            size += jmsSystemPropertyMap.size();
        }
        else {
            if (getApi().isNotEMPTYlist(JsApiAccess.SYSTEMPROPERTY_NAME)) {
                props = (List) getApi().getField(JsApiAccess.SYSTEMPROPERTY_NAME);
                if (props != null) {
                    size += props.size();
                }
            }
        }

        if (systemContextMap != null) {
            size += systemContextMap.size();
        }
        else {
            if (getApi().isNotEMPTYlist(JsApiAccess.SYSTEMCONTEXT_NAME)) {
                props = (List) getApi().getField(JsApiAccess.SYSTEMCONTEXT_NAME);
                if (props != null) {
                    size += props.size();
                }
            }
        }

        if (mqMdSetPropertiesMap != null) {
            size += mqMdSetPropertiesMap.size();
        }
        else {
            // This field usually doesn't exist, so no need for the isNotEMPTY check
            props = (List) getHdr2().getField(JsHdr2Access.MQMDPROPERTIES_MAP_NAME);
            if (props != null) {
                size += props.size();
            }
        }

        total += size * 40;
        return total;
    }
777016
@VisibleForTesting
  static Metric createMetric(
      io.opencensus.metrics.export.MetricDescriptor metricDescriptor,
      List<LabelValue> labelValues,
      String domain,
      Map<LabelKey, LabelValue> constantLabels) {
    Metric.Builder builder = Metric.newBuilder();
    builder.setType(generateType(metricDescriptor.getName(), domain));
    Map<String, String> stringTagMap = Maps.newHashMap();
    List<LabelKey> labelKeys = metricDescriptor.getLabelKeys();
    for (int i = 0; i < labelValues.size(); i++) {
      String value = labelValues.get(i).getValue();
      if (value == null) {
        continue;
      }
      stringTagMap.put(labelKeys.get(i).getKey(), value);
    }
    for (Map.Entry<LabelKey, LabelValue> constantLabel : constantLabels.entrySet()) {
      String constantLabelKey = constantLabel.getKey().getKey();
      String constantLabelValue = constantLabel.getValue().getValue();
      constantLabelValue = constantLabelValue == null ? "" : constantLabelValue;
      stringTagMap.put(constantLabelKey, constantLabelValue);
    }
    builder.putAllLabels(stringTagMap);
    return builder.build();
  }
472152
public void setMetricData(java.util.Collection<MetricDatapoint> metricData) {
        if (metricData == null) {
            this.metricData = null;
            return;
        }

        this.metricData = new java.util.ArrayList<MetricDatapoint>(metricData);
    }
985929
private String metricName(Executable executable, Class<? extends Annotation> type, String name, boolean absolute) {
        String metric = name.isEmpty() ? defaultName(executable, type) : metricName.of(name);
        return absolute ? metric : MetricRegistry.name(executable.getDeclaringClass(), metric);
    }