// addLabeledIntMetric is a convenience method for adding the labeled metric and value to the metric set.
978345
func (this *summaryMetricsSource) addLabeledIntMetric(metrics *MetricSet, metric *Metric, labels map[string]string, value *uint64) {
	if value == nil {
		glog.V(9).Infof("skipping labeled metric %s (%v) because the value was nil", metric.Name, labels)
		return
	}

	val := LabeledMetric{
		Name:   metric.Name,
		Labels: labels,
		MetricValue: MetricValue{
			ValueType:  ValueInt64,
			MetricType: metric.Type,
			IntValue:   int64(*value),
		},
	}
	metrics.LabeledMetrics = append(metrics.LabeledMetrics, val)
}
1153591
func LabelsToSignature(labels map[string]string) uint64 {
	if len(labels) == 0 {
		return emptyLabelSignature
	}

	labelNames := make([]string, 0, len(labels))
	for labelName := range labels {
		labelNames = append(labelNames, labelName)
	}
	sort.Strings(labelNames)

	sum := hashNew()
	for _, labelName := range labelNames {
		sum = hashAdd(sum, labelName)
		sum = hashAddByte(sum, SeparatorByte)
		sum = hashAdd(sum, labels[labelName])
		sum = hashAddByte(sum, SeparatorByte)
	}
	return sum
}
87311
func (r *PCPRegistry) AddMetric(m Metric) error {
	if r.mapped {
		return errors.New("cannot add a metric when a mapping is active")
	}

	if r.HasMetric(m.Name()) {
		return errors.New("metric is already defined for the current registry")
	}

	pcpm := m.(PCPMetric)

	// if it is an indom metric
	if pcpm.Indom() != nil && !r.HasInstanceDomain(pcpm.Indom().Name()) {
		err := r.AddInstanceDomain(pcpm.Indom())
		if err != nil {
			return err
		}
	}

	r.metricslock.Lock()
	defer r.metricslock.Unlock()

	r.addMetric(pcpm)
	return nil
}
1293055
func (t *fileTracker) AddBytes(bytes uint64) {
	atomic.AddUint64(&t.diskBytes, bytes)

	labels := t.Labels()
	t.metrics.DiskSize.With(labels).Add(float64(bytes))
}
47671
func (i *Index) SetDefaultMetricLabels(labels prometheus.Labels) {
	i.defaultLabels = make(prometheus.Labels, len(labels))
	for k, v := range labels {
		i.defaultLabels[k] = v
	}
}
911016
func MustNewConstMetric(desc *Desc, valueType ValueType, value float64, labelValues ...string) Metric {
	m, err := NewConstMetric(desc, valueType, value, labelValues...)
	if err != nil {
		panic(err)
	}
	return m
}
153945
func Add(m types.Metric) {
	name := m.Info().Name

	lock.Lock()
	defer lock.Unlock()

	if _, ok := registry[name]; ok {
		panic(fmt.Sprintf("A metric with the name %q was already registered", name))
	}
	registry[name] = m
}
1201578
func AddIntGauge(name string, tgs Tags) uint32 {
	id := atomic.AddUint32(curIntGaugeID, 1) - 1

	if id >= maxNumGauges {
		panic("Too many int gauges")
	}

	intgnames[id] = name

	tgs = copyTags(tgs)
	tgs[TagMetricType] = MetricTypeGauge
	tgs[TagDataType] = DataTypeUint64
	intgtags[id] = tgs

	return id
}
307647
func (m *JSONMetricRecorder) AddMetric(
	key, value string, created time.Time, labels map[string]string) (err error) {
	defer func() {
		if err != nil {
			err = &errMetricsData{err}
		}
	}()
	err = m.validateMetric(key, value)
	if err != nil {
		return errors.Trace(err)
	}
	m.lock.Lock()
	defer m.lock.Unlock()
	return errors.Trace(m.enc.Encode(jujuc.Metric{
		Key:    key,
		Value:  value,
		Time:   created,
		Labels: labels,
	}))
}
957392
func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
	labels := []string{}
	for i := 0; i < len(labelsAndValues); i += 2 {
		labels = append(labels, labelsAndValues[i])
	}
	return &Metrics{
		Size: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: MetricsSubsystem,
			Name:      "size",
			Help:      "Size of the mempool (number of uncommitted transactions).",
		}, labels).With(labelsAndValues...),
		TxSizeBytes: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
			Namespace: namespace,
			Subsystem: MetricsSubsystem,
			Name:      "tx_size_bytes",
			Help:      "Transaction sizes in bytes.",
			Buckets:   stdprometheus.ExponentialBuckets(1, 3, 17),
		}, labels).With(labelsAndValues...),
		FailedTxs: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: MetricsSubsystem,
			Name:      "failed_txs",
			Help:      "Number of failed transactions.",
		}, labels).With(labelsAndValues...),
		RecheckTimes: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: MetricsSubsystem,
			Name:      "recheck_times",
			Help:      "Number of times transactions are rechecked in the mempool.",
		}, labels).With(labelsAndValues...),
	}
}
1147698
func (s *CirconusSink) IncrCounterWithLabels(key []string, val float32, labels []metrics.Label) {
	flatKey := s.flattenKeyLabels(key, labels)
	s.metrics.IncrementByValue(flatKey, uint64(val))
}
706722
func AddLabelToSelector(selector *metav1.LabelSelector, labelKey, labelValue string) *metav1.LabelSelector {
	if labelKey == "" {
		// Don't need to add a label.
		return selector
	}
	if selector.MatchLabels == nil {
		selector.MatchLabels = make(map[string]string)
	}
	selector.MatchLabels[labelKey] = labelValue
	return selector
}
715463
func (tms *TrustMetricStore) AddPeerTrustMetric(key string, tm *TrustMetric) {
	tms.mtx.Lock()
	defer tms.mtx.Unlock()

	if key == "" || tm == nil {
		return
	}
	tms.peerMetrics[key] = tm
}
203401
func (j *AuroraJob) AddLabel(key string, value string) Job {
	if _, ok := j.metadata[key]; ok {
		j.metadata[key].Value = value
	} else {
		j.metadata[key] = &aurora.Metadata{Key: key, Value: value}
		j.jobConfig.TaskConfig.Metadata = append(j.jobConfig.TaskConfig.Metadata, j.metadata[key])
	}
	return j
}
595416
func ReadMetric(m prometheus.Metric) *Metric {
	pb := &dto.Metric{}
	if err := m.Write(pb); err != nil {
		panic(err)
	}

	name, help := getNameAndHelp(m.Desc())
	labels := make(prometheus.Labels, len(pb.Label))
	for _, v := range pb.Label {
		labels[v.GetName()] = v.GetValue()
	}
	if pb.Gauge != nil {
		return &Metric{name, help, labels, dto.MetricType_GAUGE, pb.GetGauge().GetValue()}
	}
	if pb.Counter != nil {
		return &Metric{name, help, labels, dto.MetricType_COUNTER, pb.GetCounter().GetValue()}
	}
	if pb.Untyped != nil {
		return &Metric{name, help, labels, dto.MetricType_UNTYPED, pb.GetUntyped().GetValue()}
	}
	panic("Unsupported metric type")
}
1268945
func label(l string, indent, width int) string {
	pad := width - indent - len(l)
	if pad < 0 {
		pad = 0
	}
	return fmt.Sprintf("%s%s%s", strings.Repeat(" ", indent), l,
		strings.Repeat(" ", pad))
}
816950
func (s *CirconusSink) AddSampleWithLabels(key []string, val float32, labels []metrics.Label) {
	flatKey := s.flattenKeyLabels(key, labels)
	s.metrics.RecordValue(flatKey, float64(val))
}