Histogram

@param string $stat The metric
@param float $value The value
@param float|1 $sampleRate the rate (0-1) for sampling.
@param array|null $tags
@return Observable
356732
public function histogram($stat, $value, $sampleRate = 1, array $tags = null)
    {
        return $this->send(array($stat => "$value|h"), $sampleRate, $tags);
    }
1226964
public function tag($tag, $value, array $options = array()) {
        if ($options) {
            $this->_tags[$tag][] = array('value' => $value) + $options;
        } else {
            $this->_tags[$tag] = $value;
        }

        return $this;
    }
349947
public function drawScatterThreshold($Value, array $Format = [])
    {
        $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
        $R = isset($Format["R"]) ? $Format["R"] : 255;
        $G = isset($Format["G"]) ? $Format["G"] : 0;
        $B = isset($Format["B"]) ? $Format["B"] : 0;
        $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 50;
        $Weight = isset($Format["Weight"]) ? $Format["Weight"] : null;
        $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : 3;
        $Wide = isset($Format["Wide"]) ? $Format["Wide"] : false;
        $WideFactor = isset($Format["WideFactor"]) ? $Format["WideFactor"] : 5;
        $WriteCaption = isset($Format["WriteCaption"]) ? $Format["WriteCaption"] : false;
        $Caption = isset($Format["Caption"]) ? $Format["Caption"] : null;
        $CaptionAlign = isset($Format["CaptionAlign"]) ? $Format["CaptionAlign"] : CAPTION_LEFT_TOP;
        $CaptionOffset = isset($Format["CaptionOffset"]) ? $Format["CaptionOffset"] : 10;
        $CaptionR = isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
        $CaptionG = isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
        $CaptionB = isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
        $CaptionAlpha = isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
        $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : true;
        $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : false;
        $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 5;
        $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : true;
        $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
        $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
        $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
        $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
        $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 20;
        $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
        $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
        $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
        $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
        $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;

        $CaptionSettings = [
            "DrawBox" => $DrawBox,
            "DrawBoxBorder" => $DrawBoxBorder,
            "BorderOffset" => $BorderOffset,
            "BoxRounded" => $BoxRounded,
            "RoundedRadius" => $RoundedRadius,
            "BoxR" => $BoxR,
            "BoxG" => $BoxG,
            "BoxB" => $BoxB,
            "BoxAlpha" => $BoxAlpha,
            "BoxSurrounding" => $BoxSurrounding,
            "BoxBorderR" => $BoxBorderR,
            "BoxBorderG" => $BoxBorderG,
            "BoxBorderB" => $BoxBorderB,
            "BoxBorderAlpha" => $BoxBorderAlpha,
            "R" => $CaptionR,
            "G" => $CaptionG,
            "B" => $CaptionB,
            "Alpha" => $CaptionAlpha
        ];

        if ($Caption == null) {
            $Caption = $Value;
        }

        $Data = $this->pDataObject->getData();

        if (!isset($Data["Axis"][$AxisID])) {
            return -1;
        }

        if ($Data["Axis"][$AxisID]["Identity"] == AXIS_Y) {
            $X1 = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"];
            $X2 = $this->pChartObject->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"];
            $Y = $this->getPosArray($Value, $AxisID);

            $this->pChartObject->drawLine(
                $X1,
                $Y,
                $X2,
                $Y,
                [
                    "R" => $R,
                    "G" => $G,
                    "B" => $B,
                    "Alpha" => $Alpha,
                    "Ticks" => $Ticks,
                    "Weight" => $Weight
                ]
            );

            if ($Wide) {
                $this->pChartObject->drawLine(
                    $X1,
                    $Y - 1,
                    $X2,
                    $Y - 1,
                    [
                        "R" => $R,
                        "G" => $G,
                        "B" => $B,
                        "Alpha" => $Alpha / $WideFactor,
                        "Ticks" => $Ticks
                    ]
                );
                $this->pChartObject->drawLine(
                    $X1,
                    $Y + 1,
                    $X2,
                    $Y + 1,
                    [
                        "R" => $R,
                        "G" => $G,
                        "B" => $B,
                        "Alpha" => $Alpha / $WideFactor,
                        "Ticks" => $Ticks
                    ]
                );
            }

            if ($WriteCaption) {
                if ($CaptionAlign == CAPTION_LEFT_TOP) {
                    $X = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"] + $CaptionOffset;
                    $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT;
                } else {
                    $X = $this->pChartObject->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"] - $CaptionOffset;
                    $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT;
                }
                $this->pChartObject->drawText($X, $Y, $Caption, $CaptionSettings);
            }

            return ["Y" => $Y];
        } elseif ($Data["Axis"][$AxisID]["Identity"] == AXIS_X) {
            $X = $this->getPosArray($Value, $AxisID);
            $Y1 = $this->pChartObject->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"];
            $Y2 = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"];

            $this->pChartObject->drawLine(
                $X,
                $Y1,
                $X,
                $Y2,
                [
                    "R" => $R,
                    "G" => $G,
                    "B" => $B,
                    "Alpha" => $Alpha,
                    "Ticks" => $Ticks,
                    "Weight" => $Weight
                ]
            );

            if ($Wide) {
                $this->pChartObject->drawLine(
                    $X - 1,
                    $Y1,
                    $X - 1,
                    $Y2,
                    ["R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha / $WideFactor, "Ticks" => $Ticks]
                );
                $this->pChartObject->drawLine(
                    $X + 1,
                    $Y1,
                    $X + 1,
                    $Y2,
                    ["R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha / $WideFactor, "Ticks" => $Ticks]
                );
            }

            if ($WriteCaption) {
                if ($CaptionAlign == CAPTION_LEFT_TOP) {
                    $Y = $this->pChartObject->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"] + $CaptionOffset;
                    $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
                } else {
                    $Y = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"] - $CaptionOffset;
                    $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE;
                }

                $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
                $this->pChartObject->drawText($X, $Y, $Caption, $CaptionSettings);
            }

            return ["X" => $X];
        }
    }
1325454
public function processValue( $value,
                                  ZipArchive $zip,
                                  array $substitutions,
                                  array $domains,
                                  $dbSchema,
                                  array $paragraphIdMap = null)
    {
        if ( empty( $substitutions ) )
        {
            return $value;
        }

        $base       = static::PUBLIC_DIR . static::UPLOADS_DIR;
        $siteInfo   = $this->getSiteInfo();
        $importDir  = null;

        foreach ( $substitutions as $original => $file )
        {
            $stats = $zip->statName( $file, ZipArchive::FL_NOCASE );

            if ( ! empty( $stats ) && isset( $stats['index'] ) )
            {
                $contents   = null;
                $file       = trim( $stats['name'], '/' );

                if ( $siteInfo->getSchema() == $dbSchema &&
                     substr( $file, 0, strlen( $base ) ) == $base &&
                     is_file( $file ) &&
                     filesize( $file ) == $stats['size']  )
                {
                    $contents = $zip->getFromIndex( $stats['index'] );

                    if ( file_get_contents( $file ) == $contents )
                    {
                        $contents = null;
                        continue;
                    }
                }

                if ( null === $importDir )
                {
                    $importDir = static::UPLOADS_DIR
                               . $siteInfo->getSchema()
                               . '/pages/imports/'
                               . (new DateTime)->toHash() . '/';

                    if ( ! is_dir( static::PUBLIC_DIR . $importDir ) )
                    {
                        @mkdir( static::PUBLIC_DIR . $importDir, 0777, true );
                    }
                }

                $info   = pathinfo( $file );
                $name   = str_replace( '%', '.', rawurlencode( $info['filename'] ) );
                $ext    = '';
                $suffix = '';

                if ( isset( $info['extension'] ) )
                {
                    $ext = '.' . str_replace( '%', '.', rawurlencode( $info['extension'] ) );
                }

                while ( is_file( static::PUBLIC_DIR . $importDir . $name . $suffix . $ext ) )
                {
                    --$suffix;
                }

                $url    = $importDir . $name . $suffix . $ext;
                $path   = static::PUBLIC_DIR . $url;

                if ( $contents )
                {
                    $write = false !== file_put_contents( $path, $contents );
                }
                else if ( is_resource( $source = $zip->getStream( $stats['name'] ) ) )
                {
                    $destination = @fopen( $path, 'w' );

                    if ( is_resource( $destination ) )
                    {
                        $write = stream_copy_to_stream( $source, $destination );
                        fclose( $destination );
                    }
                    else
                    {
                        $write = false;
                    }

                    fclose( $source );
                }
                else
                {
                    $write = false;
                }

                if ( $write )
                {
                    $value = str_replace( $original, '/' . $url, $value );
                }
            }
        }

        foreach ( $domains as $domain )
        {
            if ( $domain === $siteInfo->getDomain() )
            {
                continue;
            }

            $value = preg_replace_callback(
                '((https?://)([^/:]+?\.)?'
                    . preg_quote( $domain )
                    . '(:\d+)?/?)i',
                function ( $matches ) use ( $siteInfo )
                {
                    return $siteInfo->getSubdomainUrl(
                        empty( $matches[2] ) ? '' : $matches[2],
                        true
                    );
                },
                $value
            );
        }

        return $value;
    }
569960
public function getTotal($rp, $metric, $tags) {
        try {
            $todayDt = date("Y-m-d") . "T00:00:00Z";
            
            return  $this->mapper->getRpSum('forever', $metric, $tags) +
                    $this->mapper->getRpSum($rp, $metric, $tags, $todayDt) +
                    $this->mapper->getSum($metric, $tags);
        } catch (Exception $e) {
            throw new AnalyticsException("Analytics client get total exception", 0, $e);
        }
    }
359035
public function histogram($metric, $duration, array $tags = array(), $sampleRate = AbstractMetric::DEFAULT_SAMPLE_RATE)
    {
        try {
            $this->sendMetric($this->metricFactory->histogram($metric, $duration, $tags, $sampleRate));
        } catch (\Exception $exception) {
            $this->logException($exception);
        }

        return $this;
    }
462091
public function mark($mark, $value=null)
     {
        $marks = $this->matchingListener->markToArray($mark, $value, $this->knownMarks);
        $newMarks = array_merge($this->marks, $marks);
        return new static($this->root, $newMarks, $this->markFilters);
     }
75816
protected void processOneMetric(List<String> resultStrings, Server server, Result result, Object value, String addTagName,
									String addTagValue) {
		String metricName = this.metricNameStrategy.formatName(result);

		//
		// Skip any non-numeric values since OpenTSDB only supports numeric metrics.
		//
		if (isNumeric(value)) {
			StringBuilder resultString = new StringBuilder();

			formatResultString(resultString, metricName, result.getEpoch() / 1000L, value);
			addTags(resultString, server);

			if (addTagName != null) {
				addTag(resultString, addTagName, addTagValue);
			}

			if (!typeNames.isEmpty()) {
				this.addTypeNamesTags(resultString, result);
			}

			resultStrings.add(resultString.toString());
		} else {
			log.debug("Skipping non-numeric value for metric {}; value={}", metricName, value);
		}
	}
521967
public function counter($metric, $count = 1, array $tags = array(), $sampleRate = AbstractMetric::DEFAULT_SAMPLE_RATE)
    {
        return new Counter($this->prefix($metric), $count, array_merge($this->defaultTags, $tags), $sampleRate);
    }
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);
        }
    }
1167806
function setRequestStatus( $statcode, $text, $extdata=FALSE, $params=FALSE ) {
    $input = array();
    $input['value']['statcode']  = $statcode;
    $input['value']['text']      = $text;
    if( $extdata )
      $input['value']['extdata'] = $extdata;
    $input['params']    = $this->_setParams( $params);
    $this->requeststatus[] = $input;
  }
981861
public function setPost($spec, $value = null)
    {
        if ((null === $value) && !is_array($spec)) {
            throw new \Exception('Invalid value passed to setPost(); must be either array of values or key/value pair');
        }

        if ((null === $value) && is_array($spec)) {
            foreach ($spec as $key => $value) {
                $this->setPost($key, $value);
            }
            return $this;
        }

        $_POST[(string) $spec] = $value;
        return $this;
    }
638549
public function convertToPHPValue($value, AbstractPlatform $platform): ?Status
    {
        if ($value === null) {
            return null;
        }

        return Status::fromString($value);
    }
1087170
def gauge(name, value, rate=1, tags=None):
    
    client().gauge(name, value, rate, tags)
934622
public void addSample(Sample stat) {
        samples.add(stat);
        if (samples.size() == 1) {
            start = stat.start;
            end = stat.end;
        }
        this.ioBytes += stat.ioBytes;
        this.jobMsgCnt += stat.jobMsgCnt;
        this.msgCnt += stat.msgCnt;
        this.msgBytes += stat.msgBytes;
        this.start = Math.min(this.start, stat.start);
        this.end = Math.max(this.end, stat.end);
    }
696320
public function put($id, $value, $tags = [], DateTime $until = null)
    {

        $entry = $this->entryTemplate;

        $canSerialize = $this->canSerialize($value);
        $shouldSerialize = $this->shouldSerialize($value);
        $isPlain = true;

        if (!$canSerialize && !$this->bigStorage) {
            throw new UnexpectedValueException('Cannot store a value of type ' . Type::of($value) . '. Assign a big storage who supports that.');
        }

        // Lets save some memory and try not to copy value more around than
        // necessary

        $plainValue = null;

        if ($shouldSerialize) {
            $plainValue = $value;
            $value = $this->serializer->serialize($value);
            $isPlain = false;
        }

        // $value is now string || resource
        $writtenOutside = $this->writeToBigStorageIfNeeded($id, $value);

        $validUntil = $until ? $until->getTimestamp() : 0;

        $entry['plain'] = (int)$isPlain;
        $entry['outside'] = (int)$writtenOutside;
        $entry['payload'] = $writtenOutside ? '' : $value;
        $entry['tags'] = $tags ? ('|' . implode('|', $tags) . '|') : '';
        $entry['valid_until'] = $until ? $until->getTimestamp() : 0;


        $this->writeStorage[$id] = $entry;

        // Write the unserialized value back to put it into the memory cache
        if (!$isPlain && !$writtenOutside) {
            $entry['plain'] = 1;
            $entry['payload'] = $plainValue;
        }

        $this->entryCache[$id] = $entry;

    }
1167910
protected function createTag(string $value): Tag
    {
        /** @var TagModel $model */
        $model = $this->framework->createInstance(TagModel::class);
        $model->tstamp = \time();
        $model->name = $value;
        $model->source = $this->alias;
        $model->save();

        return ModelCollection::createTagFromModel($model);
    }