5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 use Liuggio\StatsdClient\Factory\StatsdDataFactory
;
26 * A factory for application metric data.
28 * This class prepends a context-specific prefix to each metric key and keeps
29 * a reference to each constructed metric in an internal array buffer.
33 class BufferingStatsdDataFactory
extends StatsdDataFactory
{
34 protected $buffer = array();
36 public function __construct( $prefix ) {
37 parent
::__construct();
38 $this->prefix
= $prefix;
41 public function produceStatsdData( $key, $value = 1, $metric = self
::STATSD_METRIC_COUNT
) {
42 $this->buffer
[] = $entity = $this->produceStatsdDataEntity();
43 if ( $key !== null ) {
44 $prefixedKey = ltrim( $this->prefix
. '.' . $key, '.' );
45 $entity->setKey( $prefixedKey );
47 if ( $value !== null ) {
48 $entity->setValue( $value );
50 if ( $metric !== null ) {
51 $entity->setMetric( $metric );
56 public function getBuffer() {