Return the query type.

@param \CachetHQ\Cachet\Models\Metric $metric

@return string
519572
protected function getQueryType(Metric $metric)
    {
        if (!isset($metric->calc_type) || $metric->calc_type == Metric::CALC_SUM) {
            return "sum({$this->getMetricPointsTable()}.value * {$this->getMetricPointsTable()}.counter) AS value";
        } elseif ($metric->calc_type == Metric::CALC_AVG) {
            return "avg({$this->getMetricPointsTable()}.value) AS value";
        } else {
            return "sum({$this->getMetricPointsTable()}.value * {$this->getMetricPointsTable()}.counter) AS value";
        }
    }
1082719
public function send(AbstractMetric $metric)
    {
        $data = $this->getData($metric);
        $tags = array_merge($data, $metric->getTags());
        $this->logger->log($this->level, $this->getMessage($data), $tags);
    }
321378
public function getType($id)
    {
        if (null === $id) {
            // The caller might call us using a row from database that contains
            // a strict null, it is useless for us to do any query since null
            // typed messages are valid by the MessageInterface signature
            return null;
        }

        if (null === $this->types) {
            $this->loadCache();
        }

        if (!isset($this->types[$id])) {
            // Someone may have created it before we loaded the cache
            $this->loadCache();

            if (!isset($this->types[$id])) {
                // It seems that the type really does not exists, mark it as
                // being wrong in order to avoid to refresh the cache too often
                // and return a null type
                $this->types[$id] = false;
            }
        }

        if (false === $this->types[$id]) {
            return null;
        } else {
            return $this->types[$id];
        }
    }
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;
    }
506674
protected char getStatsdMetricType(@Nonnull QueryResult result) {
        String metricType = result.getType();
        char statsBucketType;
        if(metricType == null || metricType.equalsIgnoreCase("counter")) {
            statsBucketType = 'c';
        } else if(metricType.equalsIgnoreCase("gauge")) {
            statsBucketType = 'g';
        } else if (metricType.equalsIgnoreCase("set")) {
            statsBucketType = 's';
        } else if(metricType.length() == 1) {
            statsBucketType = metricType.charAt(0);
        } else {
            logger.warn("Unknown metric type for {}, default to 'c'", result);
            statsBucketType = 'c';
        }
        return statsBucketType;
    }
41536
protected function recurse(array $metrics)
    {
        $flat = array();
        $metrics = (array) $metrics;

        foreach ($metrics as $metric => $value) {
            // name & children are meta data, not metrics
            if (!in_array($metric, array('name', 'children'))) {
                $name = isset($metrics['name']) ? $metrics['name'] : '';
                $flat[$metric][$name] = $value;
            }
        }

        if (isset($metrics['children'])) {
            foreach ($metrics['children'] as $child) {
                $childTotals = $this->recurse($child);
                $flat = array_merge_recursive($flat, $childTotals);
            }
        }

        foreach ($flat as $metric => $data) {
            // array_merge_recursive will merge into an array of values if there
            // are multiple things with the same name, in which case we'll just
            // go with the last occurrence
            $flat[$metric] = array_map(function ($value) {
                return is_array($value) ? array_pop($value) : $value;
            }, $flat[$metric]);
        }

        return $flat;
    }
1037839
public function sendMetric(Metric $metric) {
        $points = $metric->getPoints();
        if (empty($points)) {
            throw new EmptyMetricException('The metric must contain points to send');
        }

        $this->sendSeries(new Series($metric));

        return $this;
    }
657744
public function index(Request $request)
    {
        $query = Tag::query();

        if ($request->has('filter.containing')) {
            $query->containing($request['filter']['containing']);
        }

        if ($request->has('filter.type')) {
            $query->where('type', $request['filter']['type']);
        }

        if ($request->has('limit')) {
            $query->limit($request['limit']);
        }

        return $query->get()->map(function (Tag $tag) {
            return $tag->name;
        });
    }
75338
public function index(Request $request)
    {
        // GET THE SLUG, ex. 'posts', 'pages', etc.
        $slug = $this->getSlug($request);

        // GET THE DataType based on the slug
        $dataType = Admin::model('DataType')->where('slug', '=', $slug)->first();

        // Check permission
        $this->authorize('browse', app($dataType->model_name));

        if ($dataType->pagination === 'ajax') {
            return $this->indexAjax($request);
        }

        $getter = $dataType->pagination === 'php' ? 'paginate' : 'get';

        $search = (object) ['value' => $request->get('s'), 'key' => $request->get('key'), 'filter' => $request->get('filter')];
        $searchable = $dataType->pagination === 'php' ? array_keys(SchemaManager::describeTable(app($dataType->model_name)->getTable())->toArray()) : '';
        $orderBy = $request->get('order_by');
        $sortOrder = $request->get('sort_order', null);

        // Next Get or Paginate the actual content from the MODEL that corresponds to the slug DataType
        if (strlen($dataType->model_name) != 0) {
            $model = app($dataType->model_name);

            $query = $model;

            if (method_exists($model, 'adminList')) {
                $query = $model->adminList();
            }

            $query->select('*');

            $relationships = $this->getRelationships($dataType);

            // If a column has a relationship associated with it, we do not want to show that field
            $this->removeRelationshipField($dataType, 'browse');

            if ($search->value && $search->key && $search->filter) {
                $search_filter = ($search->filter == 'equals') ? '=' : 'LIKE';
                $search_value = ($search->filter == 'equals') ? $search->value : '%'.$search->value.'%';
                $query = $query->where($search->key, $search_filter, $search_value);
            }

            if ($orderBy && in_array($orderBy, $dataType->fields())) {
                $querySortOrder = (!empty($sortOrder)) ? $sortOrder : 'DESC';
                $dataTypeContent = call_user_func([
                    $query = $query->with($relationships)->orderBy($orderBy, $querySortOrder),
                    $getter,
                ]);
            } elseif ($model->timestamps) {
                $dataTypeContent = call_user_func([$query->latest($model::CREATED_AT), $getter]);
            } else {
                $dataTypeContent = call_user_func([$query->with($relationships)->orderBy($model->getKeyName(), 'DESC'), $getter]);
            }

            // Replace relationships' keys for labels and create READ links if a slug is provided.
            $dataTypeContent = $this->resolveRelations($dataTypeContent, $dataType);
        } else {
            // If Model doesn't exist, get data from table name
            $dataTypeContent = call_user_func([DB::table($dataType->name), $getter]);
            $model = false;
        }

        // Check if CRUD is Translatable
        if (($isModelTranslatable = is_crud_translatable($model))) {
            $dataTypeContent->load('translations');
        }

        // Check if server side pagination is enabled
        $isServerSide = $dataType->isServerSide();

        $view = 'admin::crud.browse';

        if (view()->exists("admin::$slug.browse")) {
            $view = "admin::$slug.browse";
        }

        return Admin::view($view, compact(
            'dataType',
            'dataTypeContent',
            'isModelTranslatable',
            'search',
            'orderBy',
            'sortOrder',
            'searchable',
            'isServerSide'
        ));
    }
974827
public function postTypeFinder($request)
    {
        if (key_exists('type', $request->query)) {
            return $request->query['type'];
        }
        if (key_exists(0, $request->params['pass'])) {
            return $request->params['pass'][0];
        }
        return '';
    }
1231327
public function getQuery() : string {
        switch ($this->authType) {
            case self::CREDENTIAL:
                return sprintf('credentialToken=%s', $this->getCredentialToken());
            case self::HANDLER:
                return sprintf('handlerToken=%s', $this->getHandlerToken());
            case self::IDENTITY:
                return sprintf('identityToken=%s', $this->getIdentityToken());
        }
    }
1257335
protected function isMetricValid($metric) {
        if (!isset($metric) || !is_array($metric) 
                || !isset($metric["influx"]) || !isset($metric["influx"]["tags"]) 
                || !isset($metric["mysql"]) || !isset($metric["mysql"]["query"])) {
                    return false;
        }
        return true;
    }
519430
public function indexPoints($metricId, $num = 1000, $page = 1)
    {
        if ($this->cache != false) {
            return $this->cachePoints($metricId, $num, $page);
        }

        return $this->client->call(
            'GET',
            "metrics/$metricId/points",
            [
                'query' => [
                    'per_page' => $num,
                    'current_page' => $page,
                ],
            ]
        );
    }
326186
function (metricType, statsdKey) {
                statsdKey = statsdKey.replace(/([^a-zA-Z0-9:_])/g, '_');
                return [prefixes[metricType], '_', statsdKey].join('');
            }
678996
private boolean _canSkipWhileScanning(MetricSchemaRecordQuery query, RecordType type) {


		if( (RecordType.METRIC.equals(type) || RecordType.SCOPE.equals(type))
				&& !SchemaService.containsFilter(query.getTagKey())
				&& !SchemaService.containsFilter(query.getTagValue())
				&& !SchemaService.containsFilter(query.getNamespace())) {
			if(RecordType.METRIC.equals(type) && !SchemaService.containsFilter(query.getMetric())) {
				return false;
			}

			if(RecordType.SCOPE.equals(type) && !SchemaService.containsFilter(query.getScope())) {
				return false;
			}

			return true;
		}

		return false;
	}
5156
function(metric_type, metric) {
	var ary = metric.split('.');
	if (options.prefix) ary.shift();
	ary.unshift(metric_type);
	return ary.join('.')+'_'+options.rate;
}
460825
public function getQueryType($query)
    {
        $ipTools = new IpTools;

        if ($ipTools->validIp($query, 'ipv4', false)) {
            if ($ipTools->validIp($query, 'ipv4')) {
                return self::QTYPE_IPV4;
            } else {
                return self::QTYPE_UNKNOWN;
            }
        } elseif ($ipTools->validIp($query, 'ipv6', false)) {
            if ($ipTools->validIp($query, 'ipv6')) {
                return self::QTYPE_IPV6;
            } else {
                return self::QTYPE_UNKNOWN;
            }
        } elseif (!empty($query) && strpos($query, '.') !== false) {
            return self::QTYPE_DOMAIN;
        } elseif (!empty($query) && strpos($query, '.') === false) {
            return self::QTYPE_AS;
        } else {
            return self::QTYPE_UNKNOWN;
        }
    }