23use Liuggio\StatsdClient\Entity\StatsdData;
24use Liuggio\StatsdClient\Entity\StatsdDataInterface;
25use Liuggio\StatsdClient\Factory\StatsdDataFactory;
56 parent::__construct();
57 $this->prefix = $prefix;
69 public function timing( $key, $time ) {
70 if ( !$this->enabled ) {
73 $this->buffer[] = [ $key, $time, StatsdDataInterface::STATSD_METRIC_TIMING ];
81 public function gauge( $key, $value ) {
82 if ( !$this->enabled ) {
85 $this->buffer[] = [ $key, $value, StatsdDataInterface::STATSD_METRIC_GAUGE ];
93 public function set( $key, $value ) {
94 if ( !$this->enabled ) {
97 $this->buffer[] = [ $key, $value, StatsdDataInterface::STATSD_METRIC_SET ];
106 if ( !$this->enabled ) {
109 $this->buffer[] = [ $key, 1, StatsdDataInterface::STATSD_METRIC_COUNT ];
118 if ( !$this->enabled ) {
121 $this->buffer[] = [ $key, -1, StatsdDataInterface::STATSD_METRIC_COUNT ];
130 if ( !$this->enabled ) {
133 $this->buffer[] = [ $key, $delta, StatsdDataInterface::STATSD_METRIC_COUNT ];
152 private static function normalizeMetricKey( $key ) {
153 $key = strtr( $key, [
'::' =>
'.' ] );
154 $key = preg_replace(
'/[^a-zA-Z0-9.]+/',
'_', $key );
155 $key = trim( $key,
'_.' );
156 return strtr( $key, [
'..' =>
'.' ] );
160 $key, $value = 1, $metric = StatsdDataInterface::STATSD_METRIC_COUNT
162 $entity = $this->produceStatsdDataEntity();
163 if ( $key !==
null ) {
164 $key = self::normalizeMetricKey(
"{$this->prefix}.{$key}" );
165 $entity->setKey( $key );
167 if ( $value !==
null ) {
168 $entity->setValue( $value );
170 if ( $metric !==
null ) {
171 $entity->setMetric( $metric );
190 foreach ( $this->buffer as [ $key, $val, $metric ] ) {
192 if ( $metric === StatsdDataInterface::STATSD_METRIC_COUNT && !$val ) {
209 return count( $this->buffer );
MediaWiki adaption of StatsdDataFactory that provides buffering and metric prefixing.
hasData()
Check whether this data factory has any buffered data.
produceStatsdData( $key, $value=1, $metric=StatsdDataInterface::STATSD_METRIC_COUNT)
updateCount( $key, $delta)
clearData()
Clear all buffered data from the factory.
getDataCount()
Return the number of buffered statsd data entries.
setEnabled( $enabled)
Set collection enable status.
MediaWiki adaptation of StatsdDataFactory that provides buffering functionality.