-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The lib can now be auto-load when installed by composer.
- Loading branch information
Showing
7 changed files
with
246 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
"homepage": "https://www.datadoghq.com/", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
{ | ||
"name": "Alex Corley", | ||
"email": "[email protected]", | ||
"role": "Developer" | ||
|
@@ -23,12 +23,14 @@ | |
"php": ">=5.3.0" | ||
}, | ||
"support": { | ||
"email": "[email protected]", | ||
"irc": "irc://irc.freenode.net/datadog", | ||
"issues": "https://github.com/DataDog/php-datadogstatsd/issues", | ||
"source": "https://github.com/DataDog/php-datadogstatsd" | ||
"email": "[email protected]", | ||
"irc": "irc://irc.freenode.net/datadog", | ||
"issues": "https://github.com/DataDog/php-datadogstatsd/issues", | ||
"source": "https://github.com/DataDog/php-datadogstatsd" | ||
}, | ||
"autoload": { | ||
"classmap": ["libraries/"] | ||
"psr-4": { | ||
"DataDog\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
<?php | ||
|
||
require '../vendor/autoload.php'; | ||
|
||
require '../libraries/datadogstatsd.php'; | ||
|
||
|
||
Datadogstatsd::increment('web.page_views'); | ||
Datadogstatsd::histogram('web.render_time', 15); | ||
Datadogstatsd::set('web.uniques', 3 /* a unique user id */); | ||
Datadogstatsd::service_check('my.service.check', Datadogstatsd::CRITICAL); | ||
use DataDog\DogStatsd; | ||
use DataDog\BatchedDogStatsd; | ||
|
||
$statsd = new DogStatsd(); | ||
$statsd->increment('web.page_views'); | ||
$statsd->histogram('web.render_time', 15); | ||
$statsd->set('web.uniques', 3 /* a unique user id */); | ||
$statsd->service_check('my.service.check', DogStatsd::CRITICAL); | ||
$statsd->event("Event title", array("text"=>"Event text")); | ||
|
||
//All the following metrics will be sent in a single UDP packet to the statsd server | ||
BatchedDatadogstatsd::increment('web.page_views'); | ||
BatchedDatadogstatsd::histogram('web.render_time', 15); | ||
BatchedDatadogstatsd::set('web.uniques', 3 /* a unique user id */); | ||
BatchedDatadogstatsd::flush_buffer(); // Necessary | ||
$batchedStatsd = new BatchedDogStatsd(); | ||
$batchedStatsd->increment('web.page_views'); | ||
$batchedStatsd->histogram('web.render_time', 15); | ||
$batchedStatsd->set('web.uniques', 3 /* a unique user id */); | ||
$batchedStatsd->flush_buffer(); // Necessary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace DataDog; | ||
|
||
class BatchedDogStatsd extends DogStatsd | ||
{ | ||
private static $buffer = array(); | ||
private static $bufferLength = 0; | ||
public static $maxBufferLength = 50; | ||
|
||
public function report($udp_message) | ||
{ | ||
static::$buffer[] = $udp_message; | ||
static::$bufferLength++; | ||
if (static::$bufferLength > static::$maxBufferLength) { | ||
$this->flush_buffer(); | ||
} | ||
} | ||
|
||
public function flush_buffer() | ||
{ | ||
$this->flush(join("\n", static::$buffer)); | ||
static::$buffer = array(); | ||
static::$bufferLength = 0; | ||
} | ||
} |
Oops, something went wrong.