Manual:Stats

The Metrics library (added in MW 1.38) attempts to better define the interface for generating metrics in MediaWiki.

API Docs on doc.wikimedia.org

Configuration
The global configuration is in  and can be overridden in.


 * is the output format all metrics will be rendered to.
 * Default  which disables metrics rendering.
 * Supported options are,  ,
 * See  for an up-to-date list of options.
 * is the URI the metrics will be forwarded to. E.g.
 * Default  which disables sending metrics.
 * is the prefix which will be applied to all generated metrics. Is required. Default.

Metric Types
The supported metric types are:
 * CounterMetric
 * An only-ever-incrementing counter.
 * Great for tracking rates.
 * Implements  and
 * GaugeMetric
 * A settable value.
 * Implements
 * TimingMetric
 * Observes timing data.
 * When the backend is configured to do so, histograms of timing metrics are generated.
 * Implements

Requesting a Metric
Use a getter to get a metric from the.

Each metric instance requires configuration via an associative array with these fields:


 * The metric name.
 * Should be unique to the extension.
 * Case sensitive.
 * All non-alphanumerics are replaced with underscores.
 * The extension name that defined the metric. For example, metrics defined in MediaWiki core would use.
 * Optional set of metric labels that define metric dimensions or more specific datapoints nested under the metric.
 * Case sensitive.
 * All non-alphanumerics are replaced with underscores.
 * An optional sampling rate to apply to the metric.
 * Takes a float between  (send no metrics) and   (send all metrics)
 * Default:

Example Usage
Let's create a counter for tracking each time a function is called:

StatsD Namespace Formatting
StatsD is supported by this metrics library but the format is by design not free-form. It is assembled following this pattern:

For example: would output:

mediawiki.my_extension.function_calls.save.Draft

Cardinality
Generally speaking, high cardinality metrics present challenges for service operators and consumers of metrics data. It is recommended to avoid using unbound values in labels or names.

Some examples of high-cardinality data:
 * IDs and UUIDs
 * Usernames
 * IP Addresses
 * User agents

Much has been written on the subject of Cardinality in metrics. I encourage you to search the web to learn more.