MediaWiki REL1_39
Wikimedia\Metrics\MetricsFactory Class Reference

Public Member Functions

 __construct (array $config, LoggerInterface $logger)
 MetricsFactory builds, configures, and caches Metrics.
 
 flush ()
 Send all buffered metrics to the target and destroy the cache.
 
 getCounter (array $config=[])
 Makes a new CounterMetric or fetches one from cache.
 
 getGauge (array $config=[])
 Makes a new GaugeMetric or fetches one from cache.
 
 getTiming (array $config=[])
 Makes a new TimingMetric or fetches one from cache.
 

Static Public Member Functions

static normalizeArray (array $entities)
 Normalize an array of strings.
 
static normalizeString (string $entity)
 Normalize strings to a metrics-compatible format.
 

Protected Member Functions

 send (UDPTransport $transport)
 Render the buffer of samples, group them into payloads, and send them through the provided UDPTransport instance.
 

Detailed Description

Definition at line 40 of file MetricsFactory.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Metrics\MetricsFactory::__construct ( array $config,
LoggerInterface $logger )

MetricsFactory builds, configures, and caches Metrics.

Parameters
array$configassociative array:
  • prefix (string): The prefix applied to all metrics. This could be the service name.
  • target (string): The URI of the statsd/statsd-exporter server.
  • format (string): The output format. See: MetricsFactory::SUPPORTED_OUTPUT_FORMATS
LoggerInterface$logger
Exceptions
UndefinedPrefixException
UnsupportedFormatException

Definition at line 84 of file MetricsFactory.php.

References Wikimedia\Metrics\MetricsFactory\normalizeString().

Member Function Documentation

◆ flush()

Wikimedia\Metrics\MetricsFactory::flush ( )

Send all buffered metrics to the target and destroy the cache.

Definition at line 189 of file MetricsFactory.php.

References Wikimedia\Metrics\MetricsFactory\send().

◆ getCounter()

Wikimedia\Metrics\MetricsFactory::getCounter ( array $config = [])

Makes a new CounterMetric or fetches one from cache.

If a collision occurs, returns a NullMetric to suppress exceptions.

Parameters
array$configassociative array:
  • name: (string) The metric name
  • extension: (string) The extension generating the metric
  • labels: (array) List of metric dimensional instantiations for filters and aggregations
  • sampleRate: (float) Optional sampling rate to apply
Returns
CounterMetric|NullMetric

Definition at line 113 of file MetricsFactory.php.

◆ getGauge()

Wikimedia\Metrics\MetricsFactory::getGauge ( array $config = [])

Makes a new GaugeMetric or fetches one from cache.

If a collision occurs, returns a NullMetric to suppress exceptions.

Parameters
array$configassociative array: name: (string) The metric name. extension: (string) The extension generating the metric. labels: (array) Labels that further identify the metric.
Returns
GaugeMetric|NullMetric

Definition at line 141 of file MetricsFactory.php.

◆ getTiming()

Wikimedia\Metrics\MetricsFactory::getTiming ( array $config = [])

Makes a new TimingMetric or fetches one from cache.

If a collision occurs, returns a NullMetric to suppress exceptions.

Parameters
array$configassociative array:
  • name: (string) The metric name
  • extension: (string) The extension generating the metric
  • labels: (array) List of metric dimensional instantiations for filters and aggregations
  • sampleRate: (float) Optional sampling rate to apply
Returns
TimingMetric|NullMetric

Definition at line 170 of file MetricsFactory.php.

◆ normalizeArray()

static Wikimedia\Metrics\MetricsFactory::normalizeArray ( array $entities)
static

Normalize an array of strings.

Parameters
string[]$entities
Returns
string[]

Definition at line 339 of file MetricsFactory.php.

◆ normalizeString()

static Wikimedia\Metrics\MetricsFactory::normalizeString ( string $entity)
static

Normalize strings to a metrics-compatible format.

Replace any other non-alphanumeric characters with underscores. Eliminate repeated underscores. Trim leading or trailing underscores.

Parameters
string$entity
Returns
string

Definition at line 327 of file MetricsFactory.php.

Referenced by Wikimedia\Metrics\MetricsFactory\__construct().

◆ send()

Wikimedia\Metrics\MetricsFactory::send ( UDPTransport $transport)
protected

Render the buffer of samples, group them into payloads, and send them through the provided UDPTransport instance.

Parameters
UDPTransport$transport

Definition at line 246 of file MetricsFactory.php.

Referenced by Wikimedia\Metrics\MetricsFactory\flush().


The documentation for this class was generated from the following file: