|
MediaWiki master
|
This is the primary interface for validating metrics definitions, caching defined metrics, and returning metric instances from cache if previously defined. More...
Public Member Functions | |
| __construct (StatsCache $cache, EmitterInterface $emitter, LoggerInterface $logger, ?string $component=null) | |
| StatsFactory builds, configures, and caches Metrics. | |
| flush () | |
| Send all buffered metrics to the target and destroy the cache. | |
| getCounter (string $name) | |
| Makes a new CounterMetric or fetches one from cache. | |
| getGauge (string $name) | |
| Makes a new GaugeMetric or fetches one from cache. | |
| getHistogram (string $name, array $buckets) | |
| Makes a new HistogramMetric from a list of buckets. | |
| getTiming (string $name) | |
| Makes a new TimingMetric or fetches one from cache. | |
| withComponent (string $component) | |
| Returns a new StatsFactory instance prefixed by component. | |
| withStatsdDataFactory (?IBufferingStatsdDataFactory $statsdDataFactory) | |
| This function existed to support the Graphite->Prometheus transition and is no longer needed. | |
Static Public Member Functions | |
| static | newNull () |
| Create a no-op StatsFactory. | |
| static | newUnitTestingHelper () |
| Create a stats helper for use in PHPUnit tests. | |
This is the primary interface for validating metrics definitions, caching defined metrics, and returning metric instances from cache if previously defined.
Definition at line 33 of file StatsFactory.php.
| Wikimedia\Stats\StatsFactory::__construct | ( | StatsCache | $cache, |
| EmitterInterface | $emitter, | ||
| LoggerInterface | $logger, | ||
| ?string | $component = null ) |
StatsFactory builds, configures, and caches Metrics.
Definition at line 45 of file StatsFactory.php.
References Wikimedia\Stats\StatsUtils\normalizeString().
| Wikimedia\Stats\StatsFactory::flush | ( | ) |
Send all buffered metrics to the target and destroy the cache.
Definition at line 147 of file StatsFactory.php.
Referenced by MediaWiki\MediaWikiEntryPoint\emitBufferedStats().
| Wikimedia\Stats\StatsFactory::getCounter | ( | string | $name | ) |
Makes a new CounterMetric or fetches one from cache.
If a collision occurs, returns a NullMetric to suppress exceptions.
| string | $name |
Definition at line 88 of file StatsFactory.php.
| Wikimedia\Stats\StatsFactory::getGauge | ( | string | $name | ) |
Makes a new GaugeMetric or fetches one from cache.
If a collision occurs, returns a NullMetric to suppress exceptions.
| string | $name |
Definition at line 100 of file StatsFactory.php.
| Wikimedia\Stats\StatsFactory::getHistogram | ( | string | $name, |
| array | $buckets ) |
Makes a new HistogramMetric from a list of buckets.
Beware: this is for storing non-time data in histograms, like byte sizes, or time data outside of the range [5ms, 60s].
Avoid changing the bucket list once a metric has been deployed. When bucket list changes are unavoidable, change the metric name and handle the transition in PromQL.
| string | $name | |
| array<int|float> | $buckets |
Definition at line 138 of file StatsFactory.php.
| Wikimedia\Stats\StatsFactory::getTiming | ( | string | $name | ) |
Makes a new TimingMetric or fetches one from cache.
The timing data should be in the range [5ms, 60s]; use ::getHistogram() if you need a different range.
This range limitation is a consequence of the recommended setup with prometheus/statsd_exporter (as dogstatsd target) and Prometheus (as time series database), with statsd_exporter::histogram_buckets set to a 5ms-60s range.
If a collision occurs, returns a NullMetric to suppress exceptions.
| string | $name |
Definition at line 120 of file StatsFactory.php.
|
static |
Create a no-op StatsFactory.
Use this as the default in a service that takes an optional StatsFactory, or as null implementation in PHPUnit tests, where we don't need to send output to an actual network service.
Definition at line 210 of file StatsFactory.php.
|
static |
Create a stats helper for use in PHPUnit tests.
Example:
Definition at line 240 of file StatsFactory.php.
| Wikimedia\Stats\StatsFactory::withComponent | ( | string | $component | ) |
Returns a new StatsFactory instance prefixed by component.
| string | $component |
Definition at line 65 of file StatsFactory.php.
| Wikimedia\Stats\StatsFactory::withStatsdDataFactory | ( | ?IBufferingStatsdDataFactory | $statsdDataFactory | ) |
This function existed to support the Graphite->Prometheus transition and is no longer needed.
Definition at line 74 of file StatsFactory.php.