Файловый менеджер - Редактировать - /var/www/html/liuggio.zip
Ðазад
PK ! �F��� � statsd-php-client/README.mdnu �Iw�� ## statsd-php-client [](http://travis-ci.org/liuggio/statsd-php-client) [](https://packagist.org/packages/liuggio/statsd-php-client) [](https://packagist.org/packages/liuggio/statsd-php-client) `statsd-php-client` is an Open Source, and **Object Oriented** Client for **etsy/statsd** written in php ### Install with composer ```bash composer require liuggio/statsd-php-client ``` ### Simple Usage ```php $statsd = new StatsdService(); $service->timing('usageTime', 100); $service->increment('visitor'); $service->decrement('click'); $service->gauge('gaugor', 333); $service->set('uniques', 765); $service->flush(); ``` ## Why use this library instead the [statsd/php-example](https://github.com/etsy/statsd/blob/master/examples/php-example.php)? - You are wise. - You could also use monolog to redirect data to statsd - This library is tested. - This library optimizes the messages to send, compressing multiple messages in individual UDP packets. - This library pays attention to the maximum length of the UDP. - This library is made by Objects not array, but it also accepts array. - You do want to debug the packets, and using `SysLogSender` the packets will be logged in your `syslog` log (on debian-like distro: `tail -f /var/log/syslog`) ### Advanced Instantiation ```php use Liuggio\StatsdClient\StatsdClient, Liuggio\StatsdClient\Factory\StatsdDataFactory, Liuggio\StatsdClient\Sender\SocketSender, Liuggio\StatsdClient\Service\StatsdService; // use Liuggio\StatsdClient\Sender\SysLogSender; $sender = new SocketSender(/*'localhost', 8126, 'udp'*/); // $sender = new SysLogSender(); // enabling this, the packet will not send over the socket $client = new StatsdClient($sender); $factory = new StatsdDataFactory('\Liuggio\StatsdClient\Entity\StatsdData'); $service = new StatsdService($client, $factory); // create the metrics with the service $service->timing('usageTime', 100); //... // send the data to statsd $service->flush(); ``` ### Usage with Monolog ```php use Liuggio\StatsdClient\StatsdClient, Liuggio\StatsdClient\Factory\StatsdDataFactory, Liuggio\StatsdClient\Sender\SocketSender; // use Liuggio\StatsdClient\Sender\SysLogSender; use Monolog\Logger; use Liuggio\StatsdClient\Monolog\Handler\StatsDHandler; $sender = new SocketSender(/*'localhost', 8126, 'udp'*/); // $sender = new SysLogSender(); // enabling this, the packet will not send over the socket $client = new StatsdClient($sender); $factory = new StatsdDataFactory(); $logger = new Logger('my_logger'); $logger->pushHandler(new StatsDHandler($client, $factory, 'prefix', Logger::DEBUG)); $logger->addInfo('My logger is now ready'); ``` the output will be: `prefix.my_logger.INFO.My-logger:1|c" 36 Bytes` ## Short Theory ### Easily Install StatSD and Graphite In order to try this application monitor you have to install etsy/statsd and Graphite see this blog post to install it with vagrant [Easy install statsd graphite](http://welcometothebundle.com/easily-install-statsd-and-graphite-with-vagrant/). #### [StatsD](https://github.com/etsy/statsd) StatsD is a simple daemon for easy stats aggregation #### [Graphite](http://graphite.wikidot.com/) Graphite is a Scalable Realtime Graphing #### The Client sends data with UDP (faster) https://www.google.com/search?q=tcp+vs+udp ## Contribution Active contribution and patches are very welcome. To keep things in shape we have quite a bunch of unit tests. If you're submitting pull requests please make sure that they are still passing and if you add functionality please take a look at the coverage as well it should be pretty high :) - First fork or clone the repository ``` git clone git://github.com/liuggio/statsd-php-client.git cd statsd-php-client ``` - Install vendors: ``` bash composer.phar install ``` - This will give you proper results: ``` bash phpunit --coverage-html reports ``` ## Core developers: This project is actively mantained by David Moreau AKA @dav-m85 and @liuggio PK ! �$��w w Q statsd-php-client/src/Liuggio/StatsdClient/Exception/InvalidArgumentException.phpnu �Iw�� <?php namespace Liuggio\StatsdClient\Exception; class InvalidArgumentException extends \InvalidArgumentException { } PK ! �9�� � B statsd-php-client/src/Liuggio/StatsdClient/Sender/SocketSender.phpnu �Iw�� <?php namespace Liuggio\StatsdClient\Sender; use Liuggio\StatsdClient\Exception\InvalidArgumentException; Class SocketSender implements SenderInterface { private $port; private $host; private $protocol; public function __construct($hostname = 'localhost', $port = 8126, $protocol = 'udp') { $this->host = $hostname; $this->port = $port; switch ($protocol) { case 'udp': $this->protocol = SOL_UDP; break; case 'tcp': $this->protocol = SOL_TCP; break; default: throw new InvalidArgumentException(sprintf('Use udp or tcp as protocol given %s', $protocol)); break; } } /** * {@inheritDoc} */ public function open() { $fp = socket_create(AF_INET, SOCK_DGRAM, $this->getProtocol()); return $fp; } /** * {@inheritDoc} */ public function write($handle, $message, $length = null) { return socket_sendto($handle, $message, strlen($message), 0, $this->getHost(), $this->getPort()); } /** * {@inheritDoc} */ public function close($handle) { socket_close($handle); } protected function setHost($host) { $this->host = $host; } protected function getHost() { return $this->host; } protected function setPort($port) { $this->port = $port; } protected function getPort() { return $this->port; } protected function setProtocol($protocol) { $this->protocol = $protocol; } protected function getProtocol() { return $this->protocol; } } PK ! �=h(� � E statsd-php-client/src/Liuggio/StatsdClient/Sender/SenderInterface.phpnu �Iw�� <?php namespace Liuggio\StatsdClient\Sender; Interface SenderInterface { /** * @abstract * @return mixed */ function open(); /** * @abstract * * @param $handle * @param string $string * @param null $length * * @return mixed */ function write($handle, $string, $length = null); /** * @abstract * * @param $handle * * @return mixed */ function close($handle); } PK ! ��Z� � B statsd-php-client/src/Liuggio/StatsdClient/Sender/SysLogSender.phpnu �Iw�� <?php namespace Liuggio\StatsdClient\Sender; Class SysLogSender implements SenderInterface { private $priority; public function __construct($priority = LOG_INFO) { $this->priority = $priority; } /** * {@inheritDoc} */ public function open() { syslog($this->priority, "statsd-client-open"); return true; } /** * {@inheritDoc} */ function write($handle, $message, $length = null) { syslog($this->priority, sprintf("statsd-client-write \"%s\" %d Bytes", $message, strlen($message))); return strlen($message); } /** * {@inheritDoc} */ function close($handle) { syslog($this->priority, "statsd-client-close"); } } PK ! ͒�3� � @ statsd-php-client/src/Liuggio/StatsdClient/Sender/EchoSender.phpnu �Iw�� <?php namespace Liuggio\StatsdClient\Sender; Class EchoSender implements SenderInterface { /** * {@inheritDoc} */ public function open() { echo "[open]"; return true; } /** * {@inheritDoc} */ function write($handle, $message, $length = null) { echo "[$message]"; return strlen($message); } /** * {@inheritDoc} */ function close($handle) { echo "[closed]"; } } PK ! =�� � ; statsd-php-client/src/Liuggio/StatsdClient/StatsdClient.phpnu �Iw�� <?php namespace Liuggio\StatsdClient; use Liuggio\StatsdClient\Sender\SenderInterface; use Liuggio\StatsdClient\Entity\StatsdDataInterface; use Liuggio\StatsdClient\Exception\InvalidArgumentException; class StatsdClient implements StatsdClientInterface { /** * @var boolean */ private $failSilently; /** * @var \Liuggio\StatsdClient\Sender\SenderInterface */ private $sender; /** * @var boolean */ private $reducePacket; /** * Constructor. * * @param \Liuggio\StatsdClient\Sender\SenderInterface $sender * @param Boolean $reducePacket * @param Boolean $fail_silently */ public function __construct(SenderInterface $sender, $reducePacket = true, $fail_silently = true) { $this->sender = $sender; $this->reducePacket = $reducePacket; $this->failSilently = $fail_silently; } /** * Throws an exc only if failSilently if getFailSilently is false. * * @param \Exception $exception * * @throws \Exception */ private function throwException(\Exception $exception) { if (!$this->getFailSilently()) { throw $exception; } } /** * This function reduces the number of packets,the reduced has the maximum dimension of self::MAX_UDP_SIZE_STR * Reference: * https://github.com/etsy/statsd/blob/master/README.md * All metrics can also be batch send in a single UDP packet, separated by a newline character. * * @param array $reducedMetrics * @param array $metric * * @return array */ private static function doReduce($reducedMetrics, $metric) { $metricLength = strlen($metric); $lastReducedMetric = count($reducedMetrics) > 0 ? end($reducedMetrics) : null; if ($metricLength >= self::MAX_UDP_SIZE_STR || null === $lastReducedMetric || strlen($newMetric = $lastReducedMetric . "\n" . $metric) > self::MAX_UDP_SIZE_STR ) { $reducedMetrics[] = $metric; } else { array_pop($reducedMetrics); $reducedMetrics[] = $newMetric; } return $reducedMetrics; } /** * this function reduce the amount of data that should be send * * @param mixed $arrayData * * @return mixed $arrayData */ public function reduceCount($arrayData) { if (is_array($arrayData)) { $arrayData = array_reduce($arrayData, "self::doReduce", array()); } return $arrayData; } /** * Reference: https://github.com/etsy/statsd/blob/master/README.md * Sampling 0.1 * Tells StatsD that this counter is being sent sampled every 1/10th of the time. * * @param mixed $data * @param int $sampleRate * * @return mixed $data */ public function appendSampleRate($data, $sampleRate = 1) { if ($sampleRate < 1) { array_walk($data, function(&$message, $key) use ($sampleRate) { $message = sprintf('%s|@%s', $message, $sampleRate); }); } return $data; } /* * Send the metrics over UDP * * {@inheritDoc} */ public function send($data, $sampleRate = 1) { // check format if ($data instanceof StatsdDataInterface || is_string($data)) { $data = array($data); } if (!is_array($data) || empty($data)) { return; } // add sampling if ($sampleRate < 1) { $data = $this->appendSampleRate($data, $sampleRate); } // reduce number of packets if ($this->getReducePacket()) { $data = $this->reduceCount($data); } //failures in any of this should be silently ignored if .. try { $fp = $this->getSender()->open(); if (!$fp) { return; } $written = 0; foreach ($data as $key => $message) { $written += $this->getSender()->write($fp, $message); } $this->getSender()->close($fp); } catch (\Exception $e) { $this->throwException($e); } return $written; } /** * @param boolean $failSilently */ public function setFailSilently($failSilently) { $this->failSilently = $failSilently; } /** * @return boolean */ public function getFailSilently() { return $this->failSilently; } /** * @param \Liuggio\StatsdClient\Sender\SenderInterface $sender */ public function setSender(SenderInterface $sender) { $this->sender = $sender; } /** * @return \Liuggio\StatsdClient\Sender\SenderInterface */ public function getSender() { return $this->sender; } /** * @param boolean $reducePacket */ public function setReducePacket($reducePacket) { $this->reducePacket = $reducePacket; } /** * @return boolean */ public function getReducePacket() { return $this->reducePacket; } } PK ! ��pi� � @ statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdData.phpnu ��̗� <?php namespace Liuggio\StatsdClient\Entity; use Liuggio\StatsdClient\Entity\StatsdDataInterface; class StatsdData implements StatsdDataInterface { private $key; private $value; private $metric; private $sampleRate = 1; /** * @param string $key */ public function setKey($key) { $this->key = $key; } /** * @return string */ public function getKey() { return $this->key; } /** * @param int $value */ public function setValue($value) { $this->value = $value; } /** * @return int */ public function getValue() { return $this->value; } public function setMetric($metric) { $this->metric = $metric; } public function getMetric() { return $this->metric; } /** * @param float $sampleRate */ public function setSampleRate($sampleRate) { $this->sampleRate = $sampleRate; } /** * @return float */ public function getSampleRate() { return $this->sampleRate; } /** * @param bool $withMetric * * @return string */ public function getMessage($withMetric = true) { if (!$withMetric) { $result = sprintf('%s:%s', $this->getKey(), $this->getValue()); } else { $result = sprintf('%s:%s|%s', $this->getKey(), $this->getValue(), $this->getMetric()); } $sampleRate = $this->getSampleRate(); if($sampleRate < 1){ $result.= "|@$sampleRate"; } return $result; } /** * @return string */ public function __toString() { return $this->getMessage(); } } PK ! ���� � I statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdDataInterface.phpnu ��̗� <?php namespace Liuggio\StatsdClient\Entity; interface StatsdDataInterface { CONST STATSD_METRIC_TIMING = 'ms'; CONST STATSD_METRIC_GAUGE = 'g'; CONST STATSD_METRIC_SET = 's'; CONST STATSD_METRIC_COUNT = 'c'; /** * @abstract * @return string */ function getKey(); /** * @abstract * @return mixed */ function getValue(); /** * @abstract * @return string */ function getMetric(); /** * @abstract * @return string */ function getMessage(); /** * @abstract * @return float */ function getSampleRate(); /** * @abstract * @return string */ function __toString(); } PK ! �<�� � Q statsd-php-client/src/Liuggio/StatsdClient/Factory/StatsdDataFactoryInterface.phpnu �Iw�� <?php namespace Liuggio\StatsdClient\Factory; use Liuggio\StatsdClient\Entity\StatsdDataInterface; Interface StatsdDataFactoryInterface { /** * This function creates a 'timing' StatsdData. * * @abstract * * @param string|array $key The metric(s) to set. * @param float $time The elapsed time (ms) to log **/ function timing($key, $time); /** * This function creates a 'gauge' StatsdData. * * @abstract * * @param string|array $key The metric(s) to set. * @param float $value The value for the stats. **/ function gauge($key, $value); /** * This function creates a 'set' StatsdData object * A "Set" is a count of unique events. * This data type acts like a counter, but supports counting * of unique occurrences of values between flushes. The backend * receives the number of unique events that happened since * the last flush. * * The reference use case involved tracking the number of active * and logged in users by sending the current userId of a user * with each request with a key of "uniques" (or similar). * * @abstract * * @param string|array $key The metric(s) to set. * @param float $value The value for the stats. * * @return array **/ function set($key, $value); /** * This function creates a 'increment' StatsdData object. * * @abstract * * @param string|array $key The metric(s) to increment. * @param float|1 $sampleRate The rate (0-1) for sampling. * * @return array **/ function increment($key); /** * This function creates a 'decrement' StatsdData object. * * @abstract * * @param string|array $key The metric(s) to decrement. * @param float|1 $sampleRate The rate (0-1) for sampling. * * @return mixed **/ function decrement($key); /** * This function creates a 'updateCount' StatsdData object. * * @abstract * * @param string|array $key The metric(s) to decrement. * @param integer $delta The delta to add to the each metric * * @return mixed **/ function updateCount($key, $delta); /** * Produce a StatsdDataInterface Object. * * @abstract * * @param string $key The key of the metric * @param int $value The amount to increment/decrement each metric by. * @param string $metric The metric type ("c" for count, "ms" for timing, "g" for gauge, "s" for set) * * @return StatsdDataInterface **/ function produceStatsdData($key, $value = 1, $metric = StatsdDataInterface::STATSD_METRIC_COUNT); } PK ! @0�מ � H statsd-php-client/src/Liuggio/StatsdClient/Factory/StatsdDataFactory.phpnu �Iw�� <?php namespace Liuggio\StatsdClient\Factory; use Liuggio\StatsdClient\Entity\StatsdDataInterface; class StatsdDataFactory implements StatsdDataFactoryInterface { /** * @var StatsdDataInterface */ private $entityClass; public function __construct($entity_class = '\Liuggio\StatsdClient\Entity\StatsdData') { $this->setEntityClass($entity_class); } /** * {@inheritDoc} **/ public function timing($key, $time) { return $this->produceStatsdData($key, $time, StatsdDataInterface::STATSD_METRIC_TIMING); } /** * {@inheritDoc} **/ public function gauge($key, $value) { return $this->produceStatsdData($key, $value, StatsdDataInterface::STATSD_METRIC_GAUGE); } /** * {@inheritDoc} **/ public function set($key, $value) { return $this->produceStatsdData($key, $value, StatsdDataInterface::STATSD_METRIC_SET); } /** * {@inheritDoc} **/ public function increment($key) { return $this->produceStatsdData($key, 1, StatsdDataInterface::STATSD_METRIC_COUNT); } /** * {@inheritDoc} **/ public function decrement($key) { return $this->produceStatsdData($key, -1, StatsdDataInterface::STATSD_METRIC_COUNT); } /** * {@inheritDoc} **/ public function updateCount($key, $delta) { return $this->produceStatsdData($key, $delta, StatsdDataInterface::STATSD_METRIC_COUNT); } /** * {@inheritDoc} **/ public function produceStatsdData($key, $value = 1, $metric = StatsdDataInterface::STATSD_METRIC_COUNT) { $statsdData = $this->produceStatsdDataEntity(); if (null !== $key) { $statsdData->setKey($key); } if (null !== $value) { $statsdData->setValue($value); } if (null !== $metric) { $statsdData->setMetric($metric); } return $statsdData; } /** * {@inheritDoc} **/ public function produceStatsdDataEntity() { $statsdData = $this->getEntityClass(); return new $statsdData(); } /** * {@inheritDoc} **/ public function setFailSilently($failSilently) { $this->failSilently = $failSilently; } /** * {@inheritDoc} **/ public function getFailSilently() { return $this->failSilently; } /** * {@inheritDoc} **/ public function setEntityClass($entityClass) { $this->entityClass = $entityClass; } /** * {@inheritDoc} **/ public function getEntityClass() { return $this->entityClass; } } PK ! f>t�7 7 P statsd-php-client/src/Liuggio/StatsdClient/Monolog/Formatter/StatsDFormatter.phpnu �Iw�� <?php namespace Liuggio\StatsdClient\Monolog\Formatter; use Monolog\Formatter\LineFormatter; /** * Formats incoming records in order to be a perfect StatsD key. * * This is especially useful for logging to files * * @author Jordi Boggiano <j.boggiano@seld.be> * @author Christophe Coevoet <stof@notk.org> * @author Giulio De Donato <liuggio@gmail.com> */ class StatsDFormatter extends LineFormatter { const SIMPLE_FORMAT = "%channel%.%level_name%.%short_message%"; protected $numberOfWords; protected $logContext; protected $logExtra; /** * @param string $format The format of the message * @param Boolean $logContext If true add multiple rows containing Context information * @param Boolean $logExtra If true add multiple rows containing Extra information * @param integer $numberOfWords The number of words to show. */ public function __construct($format = null, $logContext = true, $logExtra = true, $numberOfWords = 2) { $this->format = $format ? : static::SIMPLE_FORMAT; $this->numberOfWords = $numberOfWords; $this->logContext = $logContext; $this->logExtra = $logExtra; parent::__construct(); } /** * This function converts a long message into a string with the first N-words. * eg. from: "Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener" * to: "Notified event" * * @param string $message The message to shortify. * * @return string */ public function getFirstWords($message) { $glue = '-'; $pieces = explode(' ', $message); array_splice($pieces, $this->numberOfWords); $shortMessage = preg_replace("/[^A-Za-z0-9?![:space:]]/", "-", implode($glue, $pieces)); return $shortMessage; } /** * {@inheritdoc} */ public function format(array $record) { $vars = $this->normalize($record); $firstRow = $this->format; $output = array(); $vars['short_message'] = $this->getFirstWords($vars['message']); foreach ($vars as $var => $val) { $firstRow = str_replace('%' . $var . '%', $this->convertToString($val), $firstRow); } $output[] = $firstRow; // creating more rows for context content if ($this->logContext && isset($vars['context'])) { foreach ($vars['context'] as $key => $parameter) { if (!is_string($parameter)) { $parameter = json_encode($parameter); } $output[] = sprintf("%s.context.%s.%s", $firstRow, $key, $parameter); } } // creating more rows for extra content if ($this->logExtra && isset($vars['extra'])) { foreach ($vars['extra'] as $key => $parameter) { if (!is_string($parameter)) { $parameter = json_encode($parameter); } $output[] = sprintf("%s.extra.%s.%s", $firstRow, $key, $parameter); } } return $output; } /** * {@inheritdoc} */ public function formatBatch(array $records) { $output = array(); foreach ($records as $record) { $output = array_merge($output, $this->format($record)); } return $output; } }PK ! �M��� � L statsd-php-client/src/Liuggio/StatsdClient/Monolog/Handler/StatsDHandler.phpnu �Iw�� <?php namespace Liuggio\StatsdClient\Monolog\Handler; use Monolog\Logger; use Monolog\Handler\AbstractProcessingHandler; use Monolog\Formatter\FormatterInterface; use Liuggio\StatsdClient\Monolog\Formatter\StatsDFormatter; use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface; use Liuggio\StatsdClient\Factory\StatsdDataFactory; use Liuggio\StatsdClient\StatsdClientInterface; /** * A processing handler for StatsD. * * @author Giulio De Donato <liuggio@gmail.com> */ class StatsDHandler extends AbstractProcessingHandler { /** * @var array */ protected $buffer = array(); /** * @var string */ protected $prefix; /** * @var statsDService */ protected $statsDService; /** * @var statsDFactory */ protected $statsDFactory; /** * @param StatsdClientInterface $statsDService The Service sends the packet * @param StatsdDataFactoryInterface $statsDFactory The Factory creates the StatsDPacket * @param string $prefix Statsd key prefix * @param integer $level The minimum logging level at which this handler will be triggered * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not */ public function __construct(StatsdClientInterface $statsDService, StatsdDataFactoryInterface $statsDFactory = null, $prefix, $level = Logger::DEBUG, $bubble = true) { parent::__construct($level, $bubble); $this->statsDService = $statsDService; $this->statsDFactory = $statsDFactory ? $statsDFactory : new StatsdDataFactory(); $this->prefix = $prefix; } /** * {@inheritdoc} */ public function close() { $this->statsDService->send($this->buffer); } /** * {@inheritdoc} */ protected function write(array $record) { $records = is_array($record['formatted']) ? $record['formatted'] : array($record['formatted']); foreach ($records as $record) { if (!empty($record)) { $this->buffer[] = $this->statsDFactory->increment(sprintf('%s.%s', $this->getPrefix(), $record)); } } } /** * Gets the default formatter. * * @return FormatterInterface */ protected function getDefaultFormatter() { return new StatsDFormatter(); } /** * @param string $prefix */ public function setPrefix($prefix) { $this->prefix = $prefix; } /** * @return string */ public function getPrefix() { return $this->prefix; } /** * @param StatsdClientInterface $statsDService */ public function setStatsDService(StatsdClientInterface $statsDService) { $this->statsDService = $statsDService; } /** * @param StatsdDataFactoryInterface $statsDFactory */ public function setStatsDFactory(StatsdDataFactoryInterface $statsDFactory) { $this->statsDFactory = $statsDFactory; } } PK ! ��Nn n D statsd-php-client/src/Liuggio/StatsdClient/StatsdClientInterface.phpnu �Iw�� <?php namespace Liuggio\StatsdClient; use Liuggio\StatsdClient\Sender\SenderInterface; use Liuggio\StatsdClient\Entity\StatsdDataInterface; use Liuggio\StatsdClient\Exception\InvalidArgumentException; Interface StatsdClientInterface { const MAX_UDP_SIZE_STR = 512; /* * Send the metrics over UDP * * @abstract * @param array|string|StatsdDataInterface $data message(s) to sent * @param int $sampleRate Tells StatsD that this counter is being sent sampled every Xth of the time. * * @return integer the data sent in bytes */ function send($data, $sampleRate = 1); } PK ! w�o�h h D statsd-php-client/src/Liuggio/StatsdClient/Service/StatsdService.phpnu �Iw�� <?php namespace Liuggio\StatsdClient\Service; use Liuggio\StatsdClient\Entity\StatsdDataInterface; use Liuggio\StatsdClient\Factory\StatsdDataFactory; use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface; use Liuggio\StatsdClient\StatsdClient; use Liuggio\StatsdClient\Entity\StatsdData; /** * Simplifies access to StatsD client and factory, buffers all data. */ class StatsdService implements StatsdDataFactoryInterface { /** * @var \Liuggio\StatsdClient\StatsdClient */ protected $client; /** * @var \Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface */ protected $factory; /** * @var StatsdData[] */ protected $buffer = array(); /** * @var float */ protected $samplingRate; private $samplingFunction; /** * @param StatsdClient $client * @param StatsdDataFactoryInterface $factory * @param float $samplingRate see setSamplingRate */ public function __construct( StatsdClient $client, StatsdDataFactoryInterface $factory = null, $samplingRate = 1 ) { $this->client = $client; if (is_null($factory)) { $factory = new StatsdDataFactory(); } $this->factory = $factory; $this->setSamplingRate($samplingRate); } /** * Actually defines the sampling rate used by the service. * If set to 0.1, the service will automatically discard 10% * of the incoming metrics. It will also automatically flag these * as sampled data to statsd. * * @param float $samplingRate */ public function setSamplingRate($samplingRate) { if ($samplingRate <= 0.0 || 1.0 < $samplingRate) { throw new \LogicException('Sampling rate shall be within ]0, 1]'); } $this->samplingRate = $samplingRate; $this->samplingFunction = function($min, $max){ return rand($min, $max); }; } /** * @return float */ public function getSamplingRate() { return $this->samplingRate; } /** * {@inheritdoc} */ public function timing($key, $time) { $this->appendToBuffer( $this->factory->timing($key, $time) ); return $this; } /** * {@inheritdoc} */ public function gauge($key, $value) { $this->appendToBuffer( $this->factory->gauge($key, $value) ); return $this; } /** * {@inheritdoc} */ public function set($key, $value) { $this->appendToBuffer( $this->factory->set($key, $value) ); return $this; } /** * {@inheritdoc} */ public function increment($key) { $this->appendToBuffer( $this->factory->increment($key) ); return $this; } /** * {@inheritdoc} */ public function decrement($key) { $this->appendToBuffer( $this->factory->decrement($key) ); return $this; } /** * {@inheritdoc} */ public function updateCount($key, $delta) { $this->appendToBuffer( $this->factory->updateCount($key, $delta) ); return $this; } /** * {@inheritdoc} */ public function produceStatsdData($key, $value = 1, $metric = StatsdDataInterface::STATSD_METRIC_COUNT) { throw new \BadFunctionCallException('produceStatsdData is not implemented'); } /** * @param callable $samplingFunction rand() function by default. */ public function setSamplingFunction(\Closure $samplingFunction) { $this->samplingFunction = $samplingFunction; } private function appendToBuffer(StatsdData $data) { if($this->samplingRate < 1){ $data->setSampleRate($this->samplingRate); $result = call_user_func($this->samplingFunction, 0 , floor(1 / $this->samplingRate)); if ($result == 0) { array_push($this->buffer, $data); }; } else { array_push($this->buffer, $data); } } /** * Send all buffered data to statsd. * * @return $this */ public function flush() { $this->client->send($this->buffer); $this->buffer = array(); return $this; } } PK ! �[bd statsd-php-client/LICENSEnu �Iw�� Copyright (c) Giulio De Donato Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK ! 0���� � statsd-php-client/phpunit.xmlnu �Iw�� <?xml version="1.0" encoding="UTF-8"?> <phpunit bootstrap="vendor/autoload.php" colors="true"> <testsuites> <testsuite name="Statsd-Service Test Suite"> <directory>tests/Liuggio/StatsdClient</directory> </testsuite> </testsuites> <filter> <whitelist> <directory suffix=".php">src/Liuggio/</directory> </whitelist> </filter> </phpunit>PK ! `�9�T T statsd-php-client/CHANGELOG.mdnu �Iw�� CHANGELOG for 1.x.x =================== This changelog references the relevant changes (bug and security fixes) done in 1.x.x minor. To get the diff for a specific change, go to https://github.com/liuggio/statsd-php-client/commit/XXX where XXX is the change hash To get the diff between two versions, go to https://github.com/liuggio/statsd-php-client/compare/v1.0.12...v1.0.13 ### 1.0.14, 1.0.16 * fix minor casing issue * php 5.3.2 instead of php5.2 ### 1.0.13 * add changelog * feature StatsdService abstracting Client/Factory usage * feature Deal with sampling in StatsdService PK ! �6�% % F statsd-php-client/tests/Liuggio/StatsdClient/StatsdDataFactoryTest.phpnu ��̗� <?php namespace Liuggio\StatsdClient\Factory; use Liuggio\StatsdClient\Factory\StatsdDataFactory; class StatsDataFactoryTest extends \PHPUnit_Framework_TestCase { private $statsDataFactory; public function setUp() { $this->statsDataFactory = new StatsdDataFactory('\Liuggio\StatsdClient\Entity\StatsdData'); } public function testProduceStatsdData() { $key = 'key'; $value='val'; $obj = $this->statsDataFactory->produceStatsdData($key, $value); $this->assertEquals($key, $obj->getKey()); $this->assertEquals($value, $obj->getValue()); } public function testTiming() { $key = 'key'; $value = microtime(); $valueFloat = (string) floatval($value); $obj = $this->statsDataFactory->timing($key, $value); $this->assertEquals($key, $obj->getKey()); $this->assertContains($valueFloat, $obj->getValue()); $this->assertContains('ms', $obj->getMetric()); } public function testProduceStatsdDataDecrement() { $key = 'key'; $value = -1; $stringValue = intval($value); $obj = $this->statsDataFactory->produceStatsdData($key, $value); $this->assertEquals($key, $obj->getKey()); $this->assertEquals($stringValue, $obj->getValue()); $this->assertEquals('c', $obj->getMetric()); } public function testGauge() { $key = 'key'; $value = 1000; $stringValue = (string) intval($value); $obj = $this->statsDataFactory->gauge($key, $value); $this->assertEquals($key, $obj->getKey()); $this->assertEquals($stringValue, $obj->getValue()); $this->assertEquals('g', $obj->getMetric()); } public function testDecrement() { $key = 'key'; $value = -1; $stringValue = intval($value); $obj = $this->statsDataFactory->decrement($key); $this->assertEquals($key, $obj->getKey()); $this->assertEquals($stringValue, $obj->getValue()); $this->assertEquals('c', $obj->getMetric()); } public function testcreateStatsdDataIncrement() { $key = 'key'; $value = 1; $stringValue = intval($value); $obj = $this->statsDataFactory->increment($key); $this->assertEquals($key, $obj->getKey()); $this->assertEquals($stringValue, $obj->getValue()); $this->assertEquals('c', $obj->getMetric()); } public function testCreateStatsdDataUpdateCount() { $key = 'key'; $value = 10; $stringValue = intval($value); $obj = $this->statsDataFactory->updateCount($key, 10); $this->assertEquals($key, $obj->getKey()); $this->assertEquals($stringValue, $obj->getValue()); $this->assertEquals('c', $obj->getMetric()); } } PK ! �u`ry y ; statsd-php-client/tests/Liuggio/StatsdClient/ReadmeTest.phpnu �Iw�� <?php namespace Liuggio\StatsdClient; use Liuggio\StatsdClient\StatsdClient; use Liuggio\StatsdClient\Factory\StatsdDataFactory; //use Liuggio\StatsdClient\Sender\SocketSender; class ReadmeTest extends \PHPUnit_Framework_TestCase { public function testFullUsageWithObject() { $sender = $this->mockSender(); // $sender = new Sender(); // StatsdClient(SenderInterface $sender, $host = 'udp://localhost', $port = 8126, $reducePacket = true, $fail_silently = true) $client = new StatsdClient($sender); $factory = new StatsdDataFactory('\Liuggio\StatsdClient\Entity\StatsdData'); // create the data with the factory $data[] = $factory->timing('usageTime', 100); $data[] = $factory->increment('visitor'); $data[] = $factory->decrement('click'); $data[] = $factory->gauge('gaugor', 333); $data[] = $factory->set('uniques', 765); // send the data as array or directly as object $client->send($data); } public function testFullUsageArray() { $sender = $this->mockSender(); // $sender = new Sender(); // StatsdClient(SenderInterface $sender, $host = 'localhost', $port = 8126, $protocol='udp', $reducePacket = true, $fail_silently = true) $client = new StatsdClient($sender, $host = 'localhost', $port = 8126, 'udp', $reducePacket = true, $fail_silently = true); $data[] ="increment:1|c"; $data[] ="set:value|s"; $data[] ="gauge:value|g"; $data[] = "timing:10|ms"; $data[] = "decrement:-1|c"; $data[] ="key:1|c"; // send the data as array or directly as object $client->send($data); } private function mockSender() { $sender = $this->getMock('\Liuggio\StatsdClient\Sender\SenderInterface', array('open', 'write', 'close')); $sender->expects($this->once()) ->method('open') ->will($this->returnValue(true)); $sender->expects($this->any()) //If you set the reduce = true into the StatsdClient the write will be called once ->method('write') ->will($this->returnCallBack(function($fp, $message) { // echo PHP_EOL . "- " . $message; })); $sender->expects($this->once()) ->method('close') ->will($this->returnValue(true)); return $sender; } }PK ! ̎\y� � A statsd-php-client/tests/Liuggio/StatsdClient/StatsdClientTest.phpnu �Iw�� <?php namespace Liuggio\StatsdClient; use Liuggio\StatsdClient\StatsdClient; use Liuggio\StatsdClient\Entity\StatsdData; class StatsdClientTest extends \PHPUnit_Framework_TestCase { public function mockSenderWithAssertionOnWrite($messageToAssert=null) { $mock = $this->getMockBuilder('\Liuggio\StatsdClient\Sender\SocketSender') ->disableOriginalConstructor() ->getMock(); $phpUnit = $this; $mock->expects($this->any()) ->method('open') ->will($this->returnValue(true)); // if the input is an array expects a call foreach item if (is_array($messageToAssert)) { $index = 0; foreach ($messageToAssert as $oneMessage) { $index++; $mock->expects($this->at($index)) ->method('write') ->will($this->returnCallBack(function($fp, $message) use ($phpUnit, $oneMessage) { $phpUnit->assertEquals($message, $oneMessage); })); } } else if (null !== $messageToAssert){ // if the input is a string expects only once $mock->expects($this->once()) ->method('write') ->will($this->returnCallBack(function($fp, $message) use ($phpUnit, $messageToAssert) { $phpUnit->assertEquals($message, $messageToAssert); })); } return $mock; } public function mockStatsdClientWithAssertionOnWrite($messageToAssert) { $mockSender = $this->mockSenderWithAssertionOnWrite($messageToAssert); return new StatsdClient($mockSender, false, false); } public function mockFactory() { $mock = $this->getMock('\Liuggio\StatsdClient\Factory\StatsdDataFactory', array('timing')); $statsData = new StatsdData(); $statsData->setKey('key'); $statsData->setValue('1'); $statsData->setMetric('ms'); $phpUnit = $this; $mock->expects($this->any()) ->method('timing') ->will($this->returnValue($statsData)); return $mock; } public static function provider() { /** * First */ $statsData0 = new StatsdData(); $statsData0->setKey('keyTiming'); $statsData0->setValue('1'); $statsData0->setMetric('ms'); /** * Second */ $stats1 = array(); $statsData1 = new StatsdData(); $statsData1->setKey('keyTiming'); $statsData1->setValue('1'); $statsData1->setMetric('ms'); $stats1[] = $statsData1; $statsData1 = new StatsdData(); $statsData1->setKey('keyIncrement'); $statsData1->setValue('1'); $statsData1->setMetric('c'); $stats1[] = $statsData1; return array( array($statsData0, "keyTiming:1|ms"), array($stats1, array("keyTiming:1|ms", "keyIncrement:1|c")), ); } public static function providerSend() { return array( array(array('gauge:value|g'), 'gauge:value|g'), array(array("keyTiming:1|ms", "keyIncrement:1|c"), array("keyTiming:1|ms", "keyIncrement:1|c")), ); } /** * @dataProvider provider */ public function testPrepareAndSend($statsdInput, $assertion) { $statsdMock = $this->mockStatsdClientWithAssertionOnWrite($assertion); $statsdMock->send($statsdInput); } /** * @dataProvider providerSend */ public function testSend($array, $assertion) { $statsdMock = $this->mockStatsdClientWithAssertionOnWrite($assertion); $statsdMock->send($array); } public function testReduceCount() { $statsd = $this->mockStatsdClientWithAssertionOnWrite(null); $entity0 = new StatsdData(); $entity0->setKey('key1'); $entity0->setValue('1'); $entity0->setMetric('c'); $array0[] = $entity0; $entity0 = new StatsdData(); $entity0->setKey('key2'); $entity0->setValue('2'); $entity0->setMetric('ms'); $array0[] = $entity0; $reducedMessage = array('key1:1|c' . PHP_EOL . 'key2:2|ms'); $this->assertEquals($statsd->reduceCount($array0), $reducedMessage); } public function testReduceWithString() { $statsd = $this->mockStatsdClientWithAssertionOnWrite(null); $msg = 'A3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789:'; $msg .= '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789|c'; $array0[] = $msg; $msg = 'B3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789:'; $msg .= '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789|c'; $array0[] = $msg; $reduced = $statsd->reduceCount($array0); $combined = $array0[0] . PHP_EOL . $array0[1]; $this->assertEquals($combined, $reduced[0]); } public function testReduceWithMaxUdpPacketSplitInTwoPacket() { $statsd = $this->mockStatsdClientWithAssertionOnWrite(null); $msg = 'A3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789'; //1 $msg .= '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 '; //2 $msg .= '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 '; //3 $msg .= '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 '; //4 $msg .= '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789|c'; //500 $array0[] = $msg; $msg = 'Bkey:'; $msg .= '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789|c'; $array0[] = $msg; $reduced = $statsd->reduceCount($array0); $this->assertEquals($array0[0], $reduced[0]); $this->assertEquals($array0[1], $reduced[1]); } public function testMultiplePacketsWithReducing() { $msg = 'A23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789'; $array0[] = $msg; $array0[] = $msg; $array0[] = $msg; $array0[] = $msg; $array0[] = $msg; $array0[] = $msg; $array0[] = $msg; $array0[] = $msg; $total = count($array0) * strlen($msg); $reducedPacketsAssertion = (int) ceil($total / StatsdClientInterface::MAX_UDP_SIZE_STR); $mockSender = $this->mockSenderWithAssertionOnWrite(); $statsd = new StatsdClient($mockSender, true, false); $reduced = $statsd->reduceCount($array0); $this->assertEquals($reducedPacketsAssertion, count($reduced)); } public function testSampleRate() { $senderMock = $this->getMock('Liuggio\StatsdClient\Sender\SenderInterface'); $senderMock ->expects($this->once()) ->method('open') ->will($this->returnValue(true)) ; $senderMock ->expects($this->once()) ->method('write') ->with($this->anything(), 'foo|@0.2') ; $client = new StatsdClient($senderMock, false, false); $client->send( 'foo', 0.2 ); } } PK ! ��侉 � F statsd-php-client/tests/Liuggio/StatsdClient/Entity/StatsdDataTest.phpnu ��̗� <?php namespace Liuggio\StatsdClient\Entity; use Liuggio\StatsdClient\Entity\StatsdData; class StatsdDataTest extends \PHPUnit_Framework_TestCase { public function testGetMessage() { $statsdData = new StatsdData(); $statsdData->setKey('key'); $statsdData->setValue('value'); $statsdData->setMetric('c'); $this->assertEquals($statsdData->getMessage(), 'key:value|c'); $statsdData = new StatsdData(); $statsdData->setKey('key'); $statsdData->setValue(-1); $statsdData->setMetric('c'); $this->assertEquals($statsdData->getMessage(), 'key:-1|c'); } } PK ! p�y� V statsd-php-client/tests/Liuggio/StatsdClient/Monolog/Formatter/StatsDFormatterTest.phpnu �Iw�� <?php namespace Liuggio\StatsdClient\Tests\Monolog\Formatter; use Monolog\Logger; use Liuggio\StatsdClient\Monolog\Formatter\StatsDFormatter; /** * @covers Liuggio\StatsdClient\Monolog\Formatter\StatsDFormatter */ class StatsDFormatterTest extends \PHPUnit_Framework_TestCase { public function testBatchFormat() { $formatter = new StatsDFormatter(null, 2); $message = $formatter->formatBatch(array( array( 'level_name' => 'CRITICAL', 'channel' => 'test', 'message' => 'bar', 'context' => array(), 'datetime' => new \DateTime, 'extra' => array(), ), array( 'level_name' => 'WARNING', 'channel' => 'log', 'message' => 'foo', 'context' => array(), 'datetime' => new \DateTime, 'extra' => array(), ), )); $this->assertEquals(array('test.CRITICAL.bar', 'log.WARNING.foo'), $message); } public function testDefFormatWithString() { $formatter = new StatsDFormatter(StatsDFormatter::SIMPLE_FORMAT); $message = $formatter->format(array( 'level_name' => 'WARNING', 'channel' => 'log', 'context' => array(), 'message' => 'foo', 'datetime' => new \DateTime, 'extra' => array(), )); $this->assertEquals(array('log.WARNING.foo'), $message); } public function testDefFormatWithArrayContext() { $formatter = new StatsDFormatter(); $message = $formatter->format(array( 'level_name' => 'ERROR', 'channel' => 'meh', 'message' => 'foo', 'datetime' => new \DateTime, 'extra' => array(), 'context' => array( 'foo' => 'bar', 'baz' => 'qux', ) )); $assert = array('meh.ERROR.foo', 'meh.ERROR.foo.context.foo.bar', 'meh.ERROR.foo.context.baz.qux'); $this->assertEquals($assert, $message); } public function testDefFormatWithArrayContextAndExtra() { $formatter = new StatsDFormatter(); $message = $formatter->format(array( 'level_name' => 'ERROR', 'channel' => 'meh', 'message' => 'foo', 'datetime' => new \DateTime, 'extra' => array('extra'=>'woow'), 'context' => array( 'foo' => 'bar', 'baz' => 'qux', ) )); $assert = array('meh.ERROR.foo', 'meh.ERROR.foo.context.foo.bar', 'meh.ERROR.foo.context.baz.qux', 'meh.ERROR.foo.extra.extra.woow'); $this->assertEquals($assert, $message); } public function testDefLongFormat() { $formatter = new StatsDFormatter(); $message = $formatter->format(array( 'level_name' => 'DEBUG', 'channel' => 'doctrine', 'message' => 'INSERT INTO viaggio_calendar (enable, viaggio_id, calendar_id) VALUES (?, ?, ?)', 'datetime' => new \DateTime, 'extra' => array(), 'context' => array( 'foo' => 'bar', 'baz' => 'qux', ) )); $this->assertEquals(array("doctrine.DEBUG.INSERT-INTO", "doctrine.DEBUG.INSERT-INTO.context.foo.bar", "doctrine.DEBUG.INSERT-INTO.context.baz.qux"), $message); } public function testDefLongFormatWith3WordsNoContextAndNoExtra() { $formatter = new StatsDFormatter(null, false, false, 3); $message = $formatter->format(array( 'level_name' => 'DEBUG', 'channel' => 'doctrine', 'message' => 'INSERT INTO viaggio_calendar (enable, viaggio_id, calendar_id) VALUES (?, ?, ?)', 'datetime' => new \DateTime, 'extra' => array(), 'context' => array( 'foo' => 'bar', 'baz' => 'qux', ) )); $this->assertEquals(array("doctrine.DEBUG.INSERT-INTO-viaggio-calendar"), $message); } public function testDefRouteException() { $formatter = new StatsDFormatter(); $message = $formatter->format(array( 'level_name' => 'DEBUG', 'channel' => 'doctrine', 'message' => 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /ddd" (uncaught exception) at /xxxx/classes.php line 5062', 'datetime' => new \DateTime, 'extra' => array(), )); $this->assertEquals(array('doctrine.DEBUG.Symfony-Component-HttpKernel-Exception-NotFoundHttpException--No'), $message); } public function testDefKernelException() { $formatter = new StatsDFormatter(); $message = $formatter->format(array( 'level_name' => 'DEBUG', 'channel' => 'doctrine', 'message' => 'Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException"', 'datetime' => new \DateTime, 'extra' => array(), 'context' => array( 'foo' => 'bar', 'baz' => 'qux', ) )); $assert = array('doctrine.DEBUG.Notified-event', 'doctrine.DEBUG.Notified-event.context.foo.bar', 'doctrine.DEBUG.Notified-event.context.baz.qux'); $this->assertEquals($assert, $message); } } PK ! nu�R R R statsd-php-client/tests/Liuggio/StatsdClient/Monolog/Handler/StatsDHandlerTest.phpnu �Iw�� <?php namespace Liuggio\StatsdClient\Tests\Monolog\Handler; use Monolog\Logger; use Liuggio\StatsdClient\Monolog\Handler\StatsDHandler; class StatsDHandlerTest extends \PHPUnit_Framework_TestCase { /** * @return array Record */ protected function getRecord($level = Logger::WARNING, $message = 'test', $context = array()) { return array( 'message' => $message, 'context' => $context, 'level' => $level, 'level_name' => Logger::getLevelName($level), 'channel' => 'test', 'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true))), 'extra' => array(), ); } /** * @return array */ protected function getMultipleRecords() { return array( $this->getRecord(Logger::DEBUG, 'debug message 1'), $this->getRecord(Logger::DEBUG, 'debug message 2'), $this->getRecord(Logger::INFO, 'information'), $this->getRecord(Logger::WARNING, 'warning'), $this->getRecord(Logger::ERROR, 'error') ); } /** * @return Monolog\Formatter\FormatterInterface */ protected function getIdentityFormatter() { $formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface'); $formatter->expects($this->any()) ->method('format') ->will($this->returnCallback(function($record) { return $record['message']; })); return $formatter; } protected function setup() { if (!interface_exists('Liuggio\StatsdClient\StatsdClientInterface')) { $this->markTestSkipped('The "liuggio/statsd-php-client" package is not installed'); } } public function testHandle() { $client = $this->getMock('Liuggio\StatsdClient\StatsdClientInterface'); $factory = $this->getMock('Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface'); $factory->expects($this->any()) ->method('increment') ->will($this->returnCallback(function ($input){ return sprintf('%s|c|1', $input); })); $prefixToAssert = 'prefix'; $messageToAssert = 'test-msg'; $record = $this->getRecord(Logger::WARNING, $messageToAssert, array('data' => new \stdClass, 'foo' => 34)); $assert = array(sprintf('%s.test.WARNING.%s|c|1',$prefixToAssert, $messageToAssert), sprintf('%s.test.WARNING.%s.context.data.[object] (stdClass: {})|c|1',$prefixToAssert, $messageToAssert), sprintf('%s.test.WARNING.%s.context.foo.34|c|1',$prefixToAssert, $messageToAssert)); $client->expects($this->once()) ->method('send') ->with($assert); $handler = new StatsDHandler($client, $factory, $prefixToAssert); $handler->handle($record); } }PK ! �S��� � J statsd-php-client/tests/Liuggio/StatsdClient/Service/StatsdServiceTest.phpnu �Iw�� <?php namespace Liuggio\StatsdClient\Entity; use Liuggio\StatsdClient\Service\StatsdService; class StatsdServiceTest extends \PHPUnit_Framework_TestCase { private $clientMock; private $factoryMock; public function setUp() { $this->clientMock = $this->getMockBuilder('Liuggio\StatsdClient\StatsdClient') ->disableOriginalConstructor() ->getMock(); $this->factoryMock = $this->getMockBuilder('Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface') ->disableOriginalConstructor() ->getMock(); } public function testConstructorWithoutFactory() { $dut = new StatsdService($this->clientMock); $dut->timing('foo.bar', 123); } public function testFactoryImplementation() { $data = new StatsdData(); // Configure the client mock. $this->factoryMock->expects($this->once())->method('timing')->willReturn($data); $this->factoryMock->expects($this->once())->method('gauge')->willReturn($data); $this->factoryMock->expects($this->once())->method('set')->willReturn($data); $this->factoryMock->expects($this->once())->method('increment')->willReturn($data); $this->factoryMock->expects($this->once())->method('decrement')->willReturn($data); $this->factoryMock->expects($this->once())->method('updateCount')->willReturn($data); // Actual test $dut = new StatsdService($this->clientMock, $this->factoryMock); $dut->timing('foo.bar', 123); $dut->gauge('foo.bar', 123); $dut->set('foo.bar', 123); $dut->increment('foo.bar'); $dut->decrement('foo.bar'); $dut->updateCount('foo.bar', 123); } public function testFlush() { $data = new StatsdData(); $this->factoryMock->expects($this->once())->method('timing')->willReturn($data); $this->clientMock->expects($this->once())->method('send') ->with($this->equalTo(array($data))); // Actual test $dut = new StatsdService($this->clientMock, $this->factoryMock); $dut->timing('foobar', 123); $dut->flush(); } public function testSampling() { $tries = false; $closure = function($a, $b) use (&$tries) { $tries = !$tries; return $tries ? 1 : 0; }; $data = new StatsdData(); $this->factoryMock->expects($this->exactly(2))->method('timing')->willReturn($data); $this->clientMock->expects($this->once())->method('send') ->with($this->equalTo(array($data))); // Actual test $dut = new StatsdService($this->clientMock, $this->factoryMock); $dut->setSamplingRate(0.1); $dut->setSamplingFunction($closure); $dut->timing('foo', 123); $dut->timing('bar', 123); $dut->flush(); $this->assertSame(0.1, $data->getSampleRate()); } } PK ! .��6 statsd-php-client/composer.jsonnu �Iw�� { "name": "liuggio/statsd-php-client", "description": "Statsd (Object Oriented) client library for PHP", "keywords": ["statsd", "monitoring", "etsy", "php"], "homepage": "https://github.com/liuggio/statsd-php-client/", "type": "library", "license": "MIT", "require": { "php": ">=5.3.2" }, "authors": [ { "name": "Giulio De Donato", "email": "liuggio@gmail.com" } ], "autoload": { "psr-0": {"Liuggio": "src/"} }, "autoload-dev": { "psr-0": {"Liuggio": "tests/"} }, "require-dev": { "monolog/monolog": ">=1.2.0", "phpunit/phpunit": "^4.7" }, "suggest": { "monolog/monolog": "Monolog, in order to do generate statistic from log >=1.2.0)" } } PK ! �F��� � statsd-php-client/README.mdnu �Iw�� PK ! �$��w w Q � statsd-php-client/src/Liuggio/StatsdClient/Exception/InvalidArgumentException.phpnu �Iw�� PK ! �9�� � B � statsd-php-client/src/Liuggio/StatsdClient/Sender/SocketSender.phpnu �Iw�� PK ! �=h(� � E statsd-php-client/src/Liuggio/StatsdClient/Sender/SenderInterface.phpnu �Iw�� PK ! ��Z� � B v statsd-php-client/src/Liuggio/StatsdClient/Sender/SysLogSender.phpnu �Iw�� PK ! ͒�3� � @ � statsd-php-client/src/Liuggio/StatsdClient/Sender/EchoSender.phpnu �Iw�� PK ! =�� � ; 5! statsd-php-client/src/Liuggio/StatsdClient/StatsdClient.phpnu �Iw�� PK ! ��pi� � @ R6 statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdData.phpnu ��̗� PK ! ���� � I �= statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdDataInterface.phpnu ��̗� PK ! �<�� � Q �@ statsd-php-client/src/Liuggio/StatsdClient/Factory/StatsdDataFactoryInterface.phpnu �Iw�� PK ! @0�מ � H fL statsd-php-client/src/Liuggio/StatsdClient/Factory/StatsdDataFactory.phpnu �Iw�� PK ! f>t�7 7 P |W statsd-php-client/src/Liuggio/StatsdClient/Monolog/Formatter/StatsDFormatter.phpnu �Iw�� PK ! �M��� � L 3e statsd-php-client/src/Liuggio/StatsdClient/Monolog/Handler/StatsDHandler.phpnu �Iw�� PK ! ��Nn n D �q statsd-php-client/src/Liuggio/StatsdClient/StatsdClientInterface.phpnu �Iw�� PK ! w�o�h h D et statsd-php-client/src/Liuggio/StatsdClient/Service/StatsdService.phpnu �Iw�� PK ! �[bd A� statsd-php-client/LICENSEnu �Iw�� PK ! 0���� � �� statsd-php-client/phpunit.xmlnu �Iw�� PK ! `�9�T T �� statsd-php-client/CHANGELOG.mdnu �Iw�� PK ! �6�% % F 0� statsd-php-client/tests/Liuggio/StatsdClient/StatsdDataFactoryTest.phpnu ��̗� PK ! �u`ry y ; ˚ statsd-php-client/tests/Liuggio/StatsdClient/ReadmeTest.phpnu �Iw�� PK ! ̎\y� � A �� statsd-php-client/tests/Liuggio/StatsdClient/StatsdClientTest.phpnu �Iw�� PK ! ��侉 � F �� statsd-php-client/tests/Liuggio/StatsdClient/Entity/StatsdDataTest.phpnu ��̗� PK ! p�y� V �� statsd-php-client/tests/Liuggio/StatsdClient/Monolog/Formatter/StatsDFormatterTest.phpnu �Iw�� PK ! nu�R R R v� statsd-php-client/tests/Liuggio/StatsdClient/Monolog/Handler/StatsDHandlerTest.phpnu �Iw�� PK ! �S��� � J J� statsd-php-client/tests/Liuggio/StatsdClient/Service/StatsdServiceTest.phpnu �Iw�� PK ! .��6 I� statsd-php-client/composer.jsonnu �Iw�� PK � ��
| ver. 1.1 | |
.
| PHP 8.4.18 | Ð“ÐµÐ½ÐµÑ€Ð°Ñ†Ð¸Ñ Ñтраницы: 0 |
proxy
|
phpinfo
|
ÐаÑтройка