Creates a new set

@param string $metric      Metric name
@param mixed  $uniqueValue Unique value for the set
@param array  $tags        Metric tags
@param int    $sampleRate  Metric sample rate

@return Set
170286
public function set($metric, $uniqueValue, array $tags =array(), $sampleRate = AbstractMetric::DEFAULT_SAMPLE_RATE)
    {
        return new Set($this->prefix($metric), $uniqueValue, array_merge($this->defaultTags, $tags), $sampleRate);
    }
321344
static void checkMetricAndTags(final String metric,
      final Map<String, String> tags) {
    if (tags.size() <= 0) {
      throw new IllegalArgumentException("Need at least one tag (metric="
          + metric + ", tags=" + tags + ')');
    } else if (tags.size() > Const.MAX_NUM_TAGS()) {
      throw new IllegalArgumentException("Too many tags: " + tags.size()
          + " maximum allowed: " + Const.MAX_NUM_TAGS() + ", tags: " + tags);
    }

    Tags.validateString("metric name", metric);
    for (final Map.Entry<String, String> tag : tags.entrySet()) {
      Tags.validateString("tag name with value [" + tag.getValue() + "]", 
          tag.getKey());
      Tags.validateString("tag value with key [" + tag.getKey() + "]", 
          tag.getValue());
    }
  }
29387
public static String getMetricNameWithUserTag(String metricName, String userName) {
    UserMetricKey k = new UserMetricKey(metricName, userName);
    String result = CACHED_METRICS.get(k);
    if (result != null) {
      return result;
    }
    return CACHED_METRICS.computeIfAbsent(k, key -> metricName + "." + CommonMetrics.TAG_USER
        + TAG_SEPARATOR + userName);
  }
813752
private void addMetric(
      List<Metric> metrics,
      String name,
      TagList tags,
      Object value) {
    long now = System.currentTimeMillis();
    if (onlyNumericMetrics) {
      value = asNumber(value);
    }
    if (value != null) {

      TagList newTags = counters.matches(MonitorConfig.builder(name).withTags(tags).build())
          ? getTagListWithAdditionalTag(tags, DataSourceType.COUNTER)
          : getTagListWithAdditionalTag(tags, DataSourceType.GAUGE);
      Metric m = new Metric(name, newTags, now, value);
      metrics.add(m);
    }
  }
497540
public static void setCommonAttributes(List<Metric> metrics, Metric result) {
        MetricDistiller distiller = new MetricDistiller();

        distiller.distill(metrics);
        result.setDisplayName(distiller.getDisplayName());
        result.setUnits(distiller.getUnits());
        result.setTags(distiller.getTags());
    }
642859
private function validateUnique(array $uniqueFields, array $data, $mode, $class)
    {
        $errors = [];

        foreach ($uniqueFields as $dataProp => $entityProp) {
            if (isset($data[$dataProp])) {
                $qb = $this->om->createQueryBuilder();

                $qb->select('DISTINCT o')
               ->from($class, 'o')
               ->where("o.{$entityProp} LIKE :{$entityProp}")
               ->setParameter($entityProp, $data[$dataProp]);

                if (self::UPDATE === $mode && isset($data['id'])) {
                    $parameter = is_numeric($data['id']) ? 'id' : 'uuid';
                    $value = is_numeric($data['id']) ? (int) $data['id'] : $data['id'];
                    $qb->setParameter($parameter, $value)->andWhere("o.{$parameter} != :{$parameter}");
                }

                $objects = $qb->getQuery()->getResult();

                if ((self::UPDATE === $mode && isset($data['id'])) || self::CREATE === $mode) {
                    if (count($objects) > 0) {
                        $errors[] = ['path' => $dataProp, 'message' => "{$entityProp} already exists and should be unique"];
                    }
                } else {
                    if (count($objects) > 1) {
                        $errors[] = ['path' => $dataProp, 'message' => "{$entityProp} already exists and should be unique"];
                    }
                }
            }
        }

        return $errors;
    }
294626
@Override
    protected void implementationSpecificPut(List<Metric> metrics,
                                             Set<String> scopeNames,
                                             Set<Pair<String, String>> scopesAndMetricNames,
                                             Map<String, MetatagsRecord> metatagsToPut) {
        requireNotDisposed();
        SystemAssert.requireArgument(metrics != null, "Metric list cannot be null.");

        for (Metric metric : metrics) {
            if (metric.getTags().isEmpty()) {
                _putWithoutTag(metric);
            }

            for (Entry<String, String> tag : metric.getTags().entrySet()) {
                _putWithTag(metric, tag);
            }
        }
    }
576053
public function gauge($metric, $level, array $tags = array(), $sampleRate = AbstractMetric::DEFAULT_SAMPLE_RATE)
    {
        return new Gauge($this->prefix($metric), $level, array_merge($this->defaultTags, $tags), $sampleRate);
    }
414695
public function set($stat, $value, $sampleRate = 1, array $tags = null)
    {
        return $this->send(array($stat => "$value|s"), $sampleRate, $tags);
    }
83677
protected function internalCreateTag($single = true, $name, $column1 = null, $column2 = null, $_ = null)
    {
        // Create constructor arguments
        $arguments = func_get_args();
        $single    = array_shift($arguments);

        array_unshift($arguments, $this->maxColumnLengths);

        // Remove null values
        foreach ($arguments as $index => $argument) {
            if ($argument === null) {
                unset($arguments[$index]);
            }
        }

        $arguments = array_values($arguments);
        $tag       = $this->tagPrototype->newInstanceArgs($arguments);

        // Create new tag
        if ($single === true) {
            $this->tags->offsetSet($arguments[1], $tag);
        } else {
            $this->tags->append($tag);
        }

        return $this;
    }
1157992
public MockTags createTags(
            final List<String> resourcesSet, final Map<String, String> tagSet) {

        MockTags ret = new MockTags();
        ret.setResourcesSet(resourcesSet);
        ret.setTagSet(tagSet);

        allMockTags.add(ret);
        return ret;
    }
301774
public function create($title, $tag = null, $group = null, $description = null) {
        $params = [
            'data' => [
                'title' => $title
            ]
        ];

        if (isset($tag)) {
            $params['data']['tag'] = $tag;
        }

        if (isset($group)) {
            $params['data']['group'] = $group;
        }

        if (isset($group)) {
            $params['data']['description'] = $description;
        }

        $result = $this->api->request(
            'checkmk.statictag.create',
            $params
        );

        if (!array_key_exists('id', $result) ||
            !is_numeric($result['id']) ||
            !array_key_exists('success', $result) ||
            $result['success'] !== true) {
            if (array_key_exists('message', $result)) {
                throw new RuntimeException(sprintf('Bad result: %s', $result['message']));
            } else {
                throw new RuntimeException('Bad result');
            }
        }

        return (int) $result['id'];
    }
1267578
public function sendMetric(AbstractMetric $metric)
    {
        try {
            $this->metricFactory->addDefaultTagsToEntity($metric);
            $this->sendMetricThroughSenders($metric);
        } catch (\Exception $exception) {
            $this->logException($exception);
        }

        return $this;
    }
1032059
@VisibleForTesting
  public static TagValue[] createTagValues(int size, String name) {
    TagValue[] values = new TagValue[size];
    for (int i = 0; i < size; i++) {
      values[i] = TagValue.create(name + i);
    }
    return values;
  }
1032558
def uniqueTags(tagList):
    '''
        
    '''
    ret = []
    alreadyAdded = set()
    for tag in tagList:
        myUid = tag.getUid()
        if myUid in alreadyAdded:
            continue
        ret.append(tag)
    return TagCollection(ret)
57580
public function getPoints($metric, $tags, $granularity, $endDt, $timezone = 'utc') {
        if ( null == $metric ) {
            return [];
        }
        
        $where = [];

        $now = $this->normalizeUTC(date("Y-m-d H:i:s"));
        
        $min = intval(date('i'));
        $minutes = $min > 45 ? 45 : ( $min > 30 ? 30 : ( $min > 15 ? 15 : '00') );       
        $lastHourDt = date("Y-m-d") . "T" . date('H') . ":$minutes:00Z";
        
        if (strtotime($endDt) < strtotime($lastHourDt)) {
           return [];
        }
        
        $where[] = "time >= '" . $lastHourDt . "' AND time <= '" . $now  . "'";
        
        foreach ($tags as $key => $val) {
            $where[] = "$key = '" . $val . "'";
        }
        
        $query = $this->db->getQueryBuilder()
                ->sum('value')
                ->from($metric)
                ->where($where);

        $groupBy = "time(1d) tz('" . $timezone . "')";
        if ($granularity == self::GRANULARITY_HOURLY) {
            $groupBy = "time(1h) tz('" . $timezone . "')";
        } else if ($granularity == self::GRANULARITY_DAILY) {
            $groupBy = "time(1d) tz('" . $timezone . "')";
        } else if ($granularity == self::GRANULARITY_WEEKLY) {
            $groupBy = "time(1w) tz('" . $timezone . "')";
        }
        $query->groupBy($groupBy);
        
        return $query->getResultSet()->getPoints();        
    }
321784
public function save($metric, $tags = array(), $value = 1, $date = null, $rp = null) {
        try {
            return $this->mapper->save($metric, $tags, $value, $date, $rp);
        } catch (Exception $e) {
            throw new AnalyticsException("Analytics client save exception", 0, $e);
        }    
    }