23use Liuggio\StatsdClient\StatsdClient;
24use Liuggio\StatsdClient\Entity\StatsdData;
25use Liuggio\StatsdClient\Entity\StatsdDataInterface;
61 if ( fnmatch( $pattern, $item->getKey(), FNM_NOESCAPE ) ) {
62 $item->setSampleRate( $item->getSampleRate() * $rate );
82 public function send( $data, $sampleRate = 1 ) {
83 if ( !is_array( $data ) ) {
89 foreach ( $data as $item ) {
90 if ( !( $item instanceof StatsdDataInterface ) ) {
91 throw new InvalidArgumentException(
92 'SamplingStatsdClient does not accept stringified messages' );
100 $data = array_map(
'strval', $data );
103 if ( $this->getReducePacket() ) {
104 $data = $this->reduceCount( $data );
110 $fp = $this->getSender()->open();
114 foreach ( $data as $message ) {
115 $written += $this->getSender()->write( $fp, $message );
117 $this->getSender()->close( $fp );
118 }
catch ( Exception
$e ) {
133 $mt_rand_max = mt_getrandmax();
134 foreach ( $data as $item ) {
135 $samplingRate = $item->getSampleRate();
136 if ( $samplingRate <= 0.0 || $samplingRate > 1.0 ) {
137 throw new LogicException(
'Sampling rate shall be within ]0, 1]' );
140 $samplingRate === 1 ||
141 ( mt_rand() / $mt_rand_max <= $samplingRate )
153 if ( !$this->getFailSilently() ) {
A statsd client that applies the sampling rate to the data items before sending them.
setSamplingRates(array $samplingRates)
Sampling rates as an associative array of patterns and rates.
send( $data, $sampleRate=1)
Send the metrics over UDP Sample the metrics according to their sample rate and send the remaining on...
throwException(Exception $exception)
@inheritDoc
sampleData( $data)
Throw away some of the data according to the sample rate.
appendSampleRate( $data, $sampleRate=1)
Sets sampling rate for all items in $data.
returning false will NOT prevent logging $e
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))