diff options
Diffstat (limited to 'vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender')
4 files changed, 197 insertions, 0 deletions
diff --git a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/EchoSender.php b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/EchoSender.php new file mode 100644 index 00000000..1015ca94 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/EchoSender.php @@ -0,0 +1,35 @@ +<?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]"; + } +} diff --git a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/SenderInterface.php b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/SenderInterface.php new file mode 100644 index 00000000..8dc8fd3a --- /dev/null +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/SenderInterface.php @@ -0,0 +1,32 @@ +<?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); +} diff --git a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/SocketSender.php b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/SocketSender.php new file mode 100644 index 00000000..c319f077 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/SocketSender.php @@ -0,0 +1,88 @@ +<?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; + } +} diff --git a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/SysLogSender.php b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/SysLogSender.php new file mode 100644 index 00000000..537ead39 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/SysLogSender.php @@ -0,0 +1,42 @@ +<?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"); + } +} |