|
@@ -7,6 +7,17 @@ namespace StatsDBundle\Services;
|
|
*/
|
|
*/
|
|
class StatsD
|
|
class StatsD
|
|
{
|
|
{
|
|
|
|
+ public function __construct($config = false){
|
|
|
|
+ $this->config = array();
|
|
|
|
+ if(false === $config){
|
|
|
|
+ $this->config["enabled"] = true;
|
|
|
|
+ $this->config["host"] = "127.0.0.1";
|
|
|
|
+ $this->config["port"] = 8125;
|
|
|
|
+ }else{
|
|
|
|
+ $this->confg = $config;
|
|
|
|
+ $this->config["enabled"] = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Sets one or more timing values
|
|
* Sets one or more timing values
|
|
@@ -108,8 +119,8 @@ class StatsD
|
|
*/
|
|
*/
|
|
public static function send($data, $sampleRate = 1)
|
|
public static function send($data, $sampleRate = 1)
|
|
{
|
|
{
|
|
- $config = Config::getInstance();
|
|
|
|
- if (!$config->isEnabled("statsd")) {
|
|
|
|
|
|
+ $config = $this->config;
|
|
|
|
+ if (!$config["enabled"]){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -136,8 +147,8 @@ class StatsD
|
|
$count = 1;
|
|
$count = 1;
|
|
// print_r("Total: ".count($sampledData).PHP_EOL);
|
|
// print_r("Total: ".count($sampledData).PHP_EOL);
|
|
try {
|
|
try {
|
|
- $host = $config->getConfig("statsd.host");
|
|
|
|
- $port = $config->getConfig("statsd.port");
|
|
|
|
|
|
+ $host = $config["host"];
|
|
|
|
+ $port = $config["port"];
|
|
$fp = fsockopen("udp://$host", $port, $errno, $errstr);
|
|
$fp = fsockopen("udp://$host", $port, $errno, $errstr);
|
|
if (!$fp) {
|
|
if (!$fp) {
|
|
return;
|
|
return;
|