Creates a MetricAggregate
@param identity The metric identity
@param currentMinute Current minute
@return The MetricAggregate
498664
public static MetricAggregate fromMetricIdentity(final MetricIdentity identity, final long currentMinute) {
		Preconditions.checkNotNull(identity);
		return new MetricAggregate(identity, currentMinute);
	}
778579
public boolean createOrReplaceMetric(Metric metric) {
        String metricName = metric.getName();
        checkMetricIsEmpty(metricName);
        QueryPart<Metric> queryPart = new Query<Metric>("metrics")
                .path(metricName, true);
        return httpClientManager.updateMetaData(queryPart, put(metric));
    }
807437
public FutureData<Token> createToken(String identity, String service, String token) {
        if (service == null || service.isEmpty()) {
            throw new IllegalArgumentException("A service is required");
        }
        if (token == null || token.isEmpty()) {
            throw new IllegalArgumentException("A token is required");
        }
        FutureData<Token> future = new FutureData<>();
        URI uri = newParams().forURL(config.newAPIEndpointURI(IDENTITY + "/" + identity + "/token"));
        try {
            Request request = config.http()
                    .postJSON(uri, new PageReader(newRequestCallback(future, new Token(), config)))
                    .setData(new NewToken(service, token));
            performRequest(future, request);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return future;
    }
590510
public static String metricName(String type, String topologyId, String componentId, int taskId, String streamId, String group, String name) {
        return concat(type, topologyId, componentId, taskId, streamId, group, name);
    }
457178
protected void aggregateEntry(Entry other, long currentTime,
            double negLambda) {
        this.data.aggregate(other.data, currentTime - this.timestamp,
                negLambda);
        this.timestamp = currentTime;
    }
985795
public void processMetricAggregation() {
        if (!isEmpty(metricAggregation)) {
            String[] aggregations = metricAggregation.split(";");
            for (int i = 0; i < aggregations.length; i++) {
                String definition = aggregations[i].trim();
                int index0 = definition.indexOf("=");
                int index1 = definition.indexOf("(");
                int index2 = definition.indexOf(")");
                String aggregatedName = definition.substring(0, index0);
                String operation = definition.substring(index0 + 1, index1);
                String parameters = definition.substring(index1 + 1, index2);
                List<String> metricNames = new ArrayList<>();
                metricNames.add(operation);
                // Case a list of metricNames
                if (parameters.contains(",")) {
                    String[] listMetricNames = parameters.split(",");
                    for (int j = 0; j < listMetricNames.length; j++) {
                        metricNames.add(listMetricNames[j].trim());
                    }
                } else {
                    Pattern pattern = Pattern.compile(parameters);
                    for (String metricName : nameIdMetrics.keySet()) {
                        if (pattern.matcher(metricName).matches()) {
                            metricNames.add(metricName);
                        }
                    }
                }
                aggregatedMetrics.put(aggregatedName, metricNames);
            }
            log.debugf("Gnocchi Aggregated Metrics from %s -> %s", metricAggregation, aggregatedMetrics);
        }
    }
1095311
public static void collectMetric(
    MetricsRecordBuilder metricsRecordBuilder, String name, Metric metric) {

    if (metric instanceof Timer) {
      Timer t = (Timer) metric;
      metricsRecordBuilder
        .addCounter(new ShuffleServiceMetricsInfo(name + "_count", "Count of timer " + name),
          t.getCount())
        .addGauge(
          new ShuffleServiceMetricsInfo(name + "_rate15", "15 minute rate of timer " + name),
          t.getFifteenMinuteRate())
        .addGauge(
          new ShuffleServiceMetricsInfo(name + "_rate5", "5 minute rate of timer " + name),
          t.getFiveMinuteRate())
        .addGauge(
          new ShuffleServiceMetricsInfo(name + "_rate1", "1 minute rate of timer " + name),
          t.getOneMinuteRate())
        .addGauge(new ShuffleServiceMetricsInfo(name + "_rateMean", "Mean rate of timer " + name),
          t.getMeanRate());
    } else if (metric instanceof Meter) {
      Meter m = (Meter) metric;
      metricsRecordBuilder
        .addCounter(new ShuffleServiceMetricsInfo(name + "_count", "Count of meter " + name),
          m.getCount())
        .addGauge(
          new ShuffleServiceMetricsInfo(name + "_rate15", "15 minute rate of meter " + name),
          m.getFifteenMinuteRate())
        .addGauge(
          new ShuffleServiceMetricsInfo(name + "_rate5", "5 minute rate of meter " + name),
          m.getFiveMinuteRate())
        .addGauge(
          new ShuffleServiceMetricsInfo(name + "_rate1", "1 minute rate of meter " + name),
          m.getOneMinuteRate())
        .addGauge(new ShuffleServiceMetricsInfo(name + "_rateMean", "Mean rate of meter " + name),
          m.getMeanRate());
    } else if (metric instanceof Gauge) {
      final Object gaugeValue = ((Gauge) metric).getValue();
      if (gaugeValue instanceof Integer) {
        metricsRecordBuilder.addGauge(getShuffleServiceMetricsInfo(name), (Integer) gaugeValue);
      } else if (gaugeValue instanceof Long) {
        metricsRecordBuilder.addGauge(getShuffleServiceMetricsInfo(name), (Long) gaugeValue);
      } else if (gaugeValue instanceof Float) {
        metricsRecordBuilder.addGauge(getShuffleServiceMetricsInfo(name), (Float) gaugeValue);
      } else if (gaugeValue instanceof Double) {
        metricsRecordBuilder.addGauge(getShuffleServiceMetricsInfo(name), (Double) gaugeValue);
      } else {
        throw new IllegalStateException(
                "Not supported class type of metric[" + name + "] for value " + gaugeValue);
      }
    } else if (metric instanceof Counter) {
      Counter c = (Counter) metric;
      long counterValue = c.getCount();
      metricsRecordBuilder.addGauge(new ShuffleServiceMetricsInfo(name, "Number of " +
          "connections to shuffle service " + name), counterValue);
    }
  }
308252
public void autoReportLast(final Set<MetricIdentity> autoMetrics) {
		Preconditions.checkNotNull(autoMetrics);
		
		for (MetricIdentity identity : autoMetrics) {
			if (!aggregateExistsForCurrentMinute(identity)) {
				MetricAggregate aggregate = getAggregate(identity);
				
				aggregate.setCount(1);
				
				if (lastValues.containsKey(identity)) {
					aggregate.setValue(lastValues.get(identity));
				} else {
					aggregate.setValue(0.0);					
				}
			}
		}
	}
689120
static Metric toMetricProto(
      io.opencensus.metrics.export.Metric metric,
      @Nullable io.opencensus.resource.Resource resource) {
    Metric.Builder builder = Metric.newBuilder();
    builder.setMetricDescriptor(toMetricDescriptorProto(metric.getMetricDescriptor()));
    for (io.opencensus.metrics.export.TimeSeries timeSeries : metric.getTimeSeriesList()) {
      builder.addTimeseries(toTimeSeriesProto(timeSeries));
    }
    if (resource != null) {
      builder.setResource(toResourceProto(resource));
    }
    return builder.build();
  }
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)
      }
    }
1247926
public ByteBuffer createGlobal(CounterId id, long clock, long count)
    {
        ContextState state = ContextState.allocate(1, 0, 0);
        state.writeGlobal(id, clock, count);
        return state.context;
    }
105554
@NonNull
  public static CreateAggregateStart createAggregate(
      @Nullable String keyspace, @NonNull String aggregateName) {
    return new DefaultCreateAggregate(
        keyspace == null ? null : CqlIdentifier.fromCql(keyspace),
        CqlIdentifier.fromCql(aggregateName));
  }
489161
@Override
	@Transactional(enabled = false)
	public CPMeasurementUnit createCPMeasurementUnit(long CPMeasurementUnitId) {
		return cpMeasurementUnitPersistence.create(CPMeasurementUnitId);
	}
848317
public void add(final Metric metric) {
		Preconditions.checkNotNull(metric);
		
		// get the aggregate for this minute
		
		MetricAggregate aggregate = getAggregate(metric.getIdentity());
		
		// add the current metric into the aggregate
		
		switch (metric.getIdentity().getType()) {
			case COUNTER: 
			case TIMER: 
			case AVERAGE:
				aggregate.setCount(aggregate.getCount() + 1);
				aggregate.setValue(aggregate.getValue() + metric.getValue());
			    break;
			case GAUGE:
				aggregate.setCount(1);
				if (metric.isIncrement()) {
					aggregate.setValue(aggregate.getValue() + metric.getValue());
				} else {
					aggregate.setValue(metric.getValue());
				}
			    break;	
			default:
				LOGGER.info("Unable to aggregate {} metric type", metric.getIdentity().getType());
				break;
		}
	}
460181
public static V1Annotation create(long timestamp, String value, @Nullable Endpoint endpoint) {
    return new V1Annotation(timestamp, value, endpoint);
  }
1210586
@Override
    public List<Metric> transform(QueryContext context, List<Metric> metrics) {
        SystemAssert.requireArgument(metrics != null, "Cannot transform empty metric/metrics");
        if (metrics.isEmpty()) {
            return metrics;
        }

        // do a union transform, the reducer perform a sum calculation
        Transform unionTransform = new MetricUnionTransform(new CountValueUnionReducer());
        List<Metric> sumUnitMetric = unionTransform.transform(null, metrics);

        // union of all timestamp
        Set<Long> unionKeyset = sumUnitMetric.get(0).getDatapoints().keySet();

        // create a list of metrics, for every metric it has union of all timestamps
        List<Metric> paddingMetrics = new ArrayList<Metric>();

        // Padding Zeros for every datapoints map in every metric
        for (Metric metric : metrics) {
            Map<Long, Double> paddingDatapoints = new TreeMap<>();
            Set<Long> metricDPKeyset = metric.getDatapoints().keySet();

            // Calculate those timestamps this datapoint map doesn't have
            for (Long unionKey : unionKeyset) {
                if (!metricDPKeyset.contains(unionKey)) {
                    paddingDatapoints.put(unionKey, 0.0);
                }
            }

            // create paddingDatapoints
            paddingDatapoints.putAll(metric.getDatapoints());
            metric.setDatapoints(paddingDatapoints);
            paddingMetrics.add(metric);
        }

        // adding base metric
        paddingMetrics.add(sumUnitMetric.get(0));

        // do a divide_v transform
        // Transform divide_vTransform = transformFactory.createMetricZipperTransform(Function.DIVIDE_V);
        Transform divide_vTransform = new MetricZipperTransform(new DivideValueZipper());

        return divide_vTransform.transform(null, paddingMetrics);
    }
893069
public static Metric createWithOneTimeSeries(
      MetricDescriptor metricDescriptor, TimeSeries timeSeries) {
    return createInternal(
        metricDescriptor, Collections.singletonList(Utils.checkNotNull(timeSeries, "timeSeries")));
  }