Starts a timer metric

@param string $metric     Metric name
@param array  $tags       Metric tags
@param int    $sampleRate Sample rate for metric

@return $this
359355
public function start($metric, array $tags = array(), $sampleRate = AbstractMetric::DEFAULT_SAMPLE_RATE)
    {
        try {
            $this->timers[$metric] = $this->metricFactory->timer($metric, null, $tags, $sampleRate);
            $this->timers[$metric]->start();
        } catch (\Exception $exception) {
            $this->logException($exception);
        }

        return $this;
    }
1023501
public function invalidateTags(array $tags)
    {
        if (!$this->cache instanceof TagAwareAdapterInterface) {
            throw new \RuntimeException('Cannot invalidate tags on a cache
            implementation that does not implement the TagAwareAdapterInterface.');
        }

        try {
            return $this->cache->invalidateTags($tags);
        } catch (InvalidArgumentException $e) {
            return false;
        }
    }
530286
public function doGenerate($tag, array $parameters)
    {
        if (isset($parameters['siteaccess'])) {
            // We generate for a different siteaccess, so potentially in a different language.
            $languages = $this->configResolver->getParameter('languages', null, $parameters['siteaccess']);
            unset($parameters['siteaccess']);
        } else {
            $languages = $this->configResolver->getParameter('languages');
        }

        $tagUrl = '';
        $isInternal = false;
        $originalTagId = $tagId = $tag->id;

        try {
            do {
                $tag = $this->tagsService->loadTag($tagId, $languages);

                $tagKeyword = null;
                foreach ($languages as $language) {
                    $tagKeyword = $tag->getKeyword($language);
                    if (!empty($tagKeyword)) {
                        break;
                    }
                }

                if (empty($tagKeyword)) {
                    if ($tag->alwaysAvailable) {
                        $tagKeyword = $tag->getKeyword();
                    }

                    if (empty($tagKeyword)) {
                        throw new LogicException("Unknown error when generating URL for tag ID #{$originalTagId}");
                    }
                }

                $tagUrl = '/' . $tagKeyword . $tagUrl;

                $tagId = $tag->parentTagId;
            } while ($tagId > 0);
        } catch (NotFoundException $e) {
            $isInternal = true;
            $tagUrl = $this->defaultRouter->generate(
                self::INTERNAL_TAG_ROUTE,
                [
                    'tagId' => $originalTagId,
                ]
            );
        } catch (LogicException $e) {
            if ($this->logger !== null) {
                $this->logger->warning($e->getMessage());
            }

            $isInternal = true;
            $tagUrl = $this->defaultRouter->generate(
                self::INTERNAL_TAG_ROUTE,
                [
                    'tagId' => $originalTagId,
                ]
            );
        }

        $queryString = '';
        if (!empty($parameters)) {
            $queryString = '?' . http_build_query($parameters, '', '&');
        }

        return (!$isInternal ? $this->getPathPrefix() : '') . '/' . trim($tagUrl, '/') . $queryString;
    }
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());
    }
  }
333896
static public function start($name) {
    static::$timers[$name]['start'] = microtime(TRUE);
    static::$timers[$name]['count'] = isset(static::$timers[$name]['count']) ? ++static::$timers[$name]['count'] : 1;
  }
1098747
private function purgeByCacheTag($tag)
    {
        $cacheTagsCacheDir = $this->getTagPath($tag);
        if (!file_exists($cacheTagsCacheDir) || !is_dir($cacheTagsCacheDir)) {
            return;
        }

        $files = (new Finder())->files()->in($cacheTagsCacheDir);
        foreach ($files as $file) {
            // @todo Change to be able to reuse parent::invalidate() or parent::purge() ?
            if ($digest = file_get_contents($file->getRealPath())) {
                @unlink($this->getPath($digest));
            }
            @unlink($file);
        }
        // We let folder stay in case another process have just written new cache tags.
    }
666742
public function gauge($metric, $level, array $tags = array(), $sampleRate = AbstractMetric::DEFAULT_SAMPLE_RATE)
    {
        try {
            $this->sendMetric($this->metricFactory->gauge($metric, $level, $tags, $sampleRate));
        } catch (\Exception $exception) {
            $this->logException($exception);
        }

        return $this;
    }
154709
public function setTagsAttribute($tags)
    {
        if (! $this->exists) {
            $this->queuedTags = $tags;

            return;
        }

        $this->tag($tags);
    }
705413
public function getSum($metric, $tags, $endDt = null) {
        if (null == $metric) {
            return 0;
        }
        
        $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";
  
        $where = [];
        
        if (!isset($endDt)) {
            $endDt = '2100-01-01T00:00:00Z';
        }
        
        if (strtotime($endDt) < strtotime($lastHourDt)) {
           return 0;
        }
        
        $where[] = "time >= '" . $lastHourDt . "' AND time <= '" . $endDt . "'";
        
        foreach ($tags as $key => $val) {
            $where[] = "$key = '" . $val . "'";
        }

        $points = $this->db->getQueryBuilder()
                ->from($metric)
                ->where($where)
                ->sum('value')
                ->getResultSet()
                ->getPoints();
        
        return isset($points[0]) && isset($points[0]["sum"]) ? $points[0]["sum"] : 0;
    }
113866
public function save($metric, $tags = array(), $value = 1, $date = null, $rp = null) {
        try {
            $command = isset($date) ? " -d '" . $this->normalizeUTC($date) . "'" : "";
            // Time precision is in nanaoseconds
            $timeNs = exec("date $command +%s%N"); 
            $fields = array();

            $points = array(
                new Point(
                        $metric, 
                        $value, 
                        $tags, 
                        $fields, 
                        $timeNs
                )
            );
            return $this->db->writePoints($points, InfluxDB::PRECISION_NANOSECONDS, $rp);
        } catch (Exception $e) {
            throw new AnalyticsException("Error saving analytics data", 0, $e);
        }
    }
1218265
public function increment($stats, $sampleRate = 1, array $tags = null)
    {
        return $this->updateStats($stats, 1, $sampleRate, $tags);
    }
528921
def submit_as_gauge_and_monotonic_count(self, metric_suffix, metric, scraper_config):
        
        metric_name = scraper_config['namespace'] + metric_suffix
        for sample in metric.samples:
            # Explicit shallow copy of the instance tags
            _tags = list(scraper_config['custom_tags'])

            for label_name, label_value in iteritems(sample[self.SAMPLE_LABELS]):
                _tags.append('{}:{}'.format(label_name, label_value))
            # submit raw metric
            self.gauge(metric_name, sample[self.SAMPLE_VALUE], _tags)
            # submit rate metric
            self.monotonic_count(metric_name + '.count', sample[self.SAMPLE_VALUE], _tags)
293892
private void timing(String metric, Date startDate) {
        m_logger.trace("Time for '{}': {}", metric,
                       ((new Date()).getTime() - startDate.getTime()) + " millis");
    }
1278430
public function syncTags($tags, bool $detaching = true)
    {
        $this->tags()->sync($this->parseTags($tags, null, null, true), $detaching);

        return $this;
    }
402417
public function set($metric, $uniqueValue, array $tags = array(), $sampleRate = AbstractMetric::DEFAULT_SAMPLE_RATE)
    {
        try {
            $this->sendMetric($this->metricFactory->set($metric, $uniqueValue, $tags, $sampleRate));
        } catch (\Exception $exception) {
            $this->logException($exception);
        }

        return $this;
    }
1230575
protected function sendGauge(GaugeInterface $metric, $timestamp)
    {
        $this->interactor->addCustomMetric($metric->getName(), $metric->getValue());
    }
827176
protected function start($tag, $attr = array())
    {
        return $this->generator->generateFromToken(
            new HTMLPurifier_Token_Start($tag, $attr ? $attr : array())
        );
    }