services/docs/metrics.rst

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 .. _services_metrics:
     3 ============================
     4 Metrics Collection Framework
     5 ============================
     7 The ``services/metrics`` directory contains a generic data metrics
     8 collecting and persisting framework for Gecko applications.
    10 Overview
    11 ========
    13 The Metrics framework by itself doesn't do much: it simply provides a
    14 generic mechanism for collecting and persisting data. It is up to users
    15 of this framework to drive collection and do something with the obtained
    16 data. A consumer of this framework is :ref:`firefox_health_report`.
    18 Relationship to Telemetry
    19 -------------------------
    21 Telemetry provides similar features to code in this directory. The two
    22 may be unified in the future.
    24 Usage
    25 =====
    27 To use the code in this directory, import Metrics.jsm. e.g.
    29    Components.utils.import("resource://gre/modules/Metrics.jsm");
    31 This exports a *Metrics* object which holds references to the main JS
    32 types and functions provided by this feature. Read below for what those
    33 types are.
    35 Metrics Types
    36 =============
    38 ``Metrics.jsm`` exports a number of types. They are documented in the
    39 sections below.
    41 Metrics.Provider
    42 ----------------
    44 ``Metrics.Provider`` is an entity that collects and manages data. Providers
    45 are typically domain-specific: if you need to collect a new type of data,
    46 you create a ``Metrics.Provider`` type that does this.
    48 Metrics.Measurement
    49 -------------------
    51 A ``Metrics.Measurement`` represents a collection of related pieces/fields
    52 of data.
    54 All data recorded by the metrics framework is modeled as
    55 ``Metrics.Measurement`` instances. Instances of ``Metrics.Measurement``
    56 are essentially data structure descriptors.
    58 Each ``Metrics.Measurement`` consists of a name and version to identify
    59 itself (and its data) as well as a list of *fields* that this measurement
    60 holds. A *field* is effectively an entry in a data structure. It consists
    61 of a name and strongly enumerated type.
    63 Metrics.Storage
    64 ---------------
    66 This entity is responsible for persisting collected data and state.
    68 It currently uses SQLite to store data, but this detail is abstracted away
    69 in order to facilitate swapping of storage backends.
    71 Metrics.ProviderManager
    72 -----------------------
    74 High-level entity coordinating activity among several ``Metrics.Provider``
    75 instances.
    77 Providers and Measurements
    78 ==========================
    80 The most important types in this framework are ``Metrics.Provider`` and
    81 ``Metrics.Measurement``, henceforth known as ``Provider`` and
    82 ``Measurement``, respectively. As you will see, these two types go
    83 hand in hand.
    85 A ``Provider`` is an entity that *provides* data about a specific subsystem
    86 or feature. They do this by recording data to specific ``Measurement``
    87 types. Both ``Provider`` and ``Measurement`` are abstract base types.
    89 A ``Measurement`` implementation defines a name and version. More
    90 importantly, it also defines its storage requirements and how
    91 previously-stored values are serialized.
    93 Storage allocation is performed by communicating with the SQLite
    94 backend. There is a startup function that tells SQLite what fields the
    95 measurement is recording. The storage backend then registers these in
    96 the database. Internally, this is creating a new primary key for
    97 individual fields so later storage operations can directly reference
    98 these primary keys in order to retrieve data without having to perform
    99 complicated joins.
   101 A ``Provider`` can be thought of as a collection of ``Measurement``
   102 implementations. e.g. an Addons provider may consist of a measurement
   103 for all *current* add-ons as well as a separate measurement for
   104 historical counts of add-ons. A provider's primary role is to take
   105 metrics data and write it to various measurements. This effectively
   106 persists the data to SQLite.
   108 Data is emitted from providers in either a push or pull based mechanism.
   109 In push-based scenarios, the provider likely subscribes to external
   110 events (e.g. observer notifications). An event of interest can occur at
   111 any time. When it does, the provider immediately writes the event of
   112 interest to storage or buffers it for eventual writing. In pull-based
   113 scenarios, the provider is periodically queried and asked to populate
   114 data.
   116 SQLite Storage
   117 ==============
   119 ``Metrics.Storage`` provides an interface for persisting metrics data to a
   120 SQLite database.
   122 The storage API organizes values by fields. A field is a named member of
   123 a ``Measurement`` that has specific type and retention characteristics.
   124 Some example field types include:
   126 * Last text value
   127 * Last numeric value for a given day
   128 * Discrete text values for a given day
   130 See ``storage.jsm`` for more.

mercurial