MediaWiki  master
CounterMetric.php
Go to the documentation of this file.
1 <?php
27 declare( strict_types=1 );
28 
30 
32 
40  private const TYPE_INDICATOR = 'c';
41 
43  private $metricUtils;
44 
53  public function __construct( array $config, MetricUtils $metricUtils ) {
54  $metricUtils->validateConfig( $config );
55  $metricUtils->setTypeIndicator( $this::TYPE_INDICATOR );
56  $this->metricUtils = $metricUtils;
57  }
58 
64  public function validateLabels( array $labels = [] ) {
65  $this->metricUtils->validateLabels( $labels );
66  }
67 
71  public function increment( array $labels = [] ): void {
72  $this->incrementBy( 1, $labels );
73  }
74 
79  public function incrementBy( int $value, array $labels = [] ): void {
80  $this->validateLabels( $labels );
81  $this->metricUtils->addSample( new Sample( [
82  'labels' => MetricsFactory::normalizeArray( $labels ),
83  'value' => $value
84  ] ) );
85  }
86 
90  public function render(): array {
91  return $this->metricUtils->render();
92  }
93 }
Wikimedia\Metrics\CounterMetric\incrementBy
incrementBy(int $value, array $labels=[])
Definition: CounterMetric.php:79
Wikimedia\Metrics\CounterMetric
Definition: CounterMetric.php:31
Wikimedia\Metrics\CounterMetric\validateLabels
validateLabels(array $labels=[])
Validate provided labels.
Definition: CounterMetric.php:64
Wikimedia\Metrics\CounterMetric\__construct
__construct(array $config, MetricUtils $metricUtils)
Definition: CounterMetric.php:53
Wikimedia\Metrics\MetricsFactory\normalizeArray
static normalizeArray(array $entities)
Normalize an array of strings.
Definition: MetricsFactory.php:339
Wikimedia\Metrics\MetricUtils
Definition: MetricUtils.php:37
Wikimedia\Metrics\CounterMetric\$metricUtils
MetricUtils $metricUtils
Definition: CounterMetric.php:33
Wikimedia\Metrics\Sample
Definition: Sample.php:31
Wikimedia\Metrics\CounterMetric\render
render()
Definition: CounterMetric.php:90
Wikimedia\Metrics\MetricUtils\validateConfig
validateConfig( $config)
Definition: MetricUtils.php:75
Wikimedia\Metrics
Definition: CounterMetric.php:29
Wikimedia\Metrics\MetricUtils\setTypeIndicator
setTypeIndicator(string $typeIndicator)
Sets the StatsD protocol type indicator.
Definition: MetricUtils.php:96
Wikimedia\Metrics\CounterMetric\increment
increment(array $labels=[])
Definition: CounterMetric.php:71