FirefoxOS/Metrics/CustomMetrics: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(Created page with "=Custom Metrics= ==How to Add== ==Information to Identify==")
 
(Added instructions for adding a custom metric.)
Line 1: Line 1:
=Custom Metrics=
=Custom Metrics=
==How to Add==
==How to Add==
To add custom metrics, here is a list of steps:
Add the following to your app (e.g. index.html)
* <script defer src="/shared/js/advanced_telemetry_helper.js"></script>
* <script defer src="/shared/js/advanced_telemetry_helper.js"></script>
Include AdvancedTelemetryHelper in the globals
There are currently three types of metrics that can be used as part of Custom Metrics:
*Counter: This is a simple counter that increments by 1 each time it's called
*Linear: This type of metric creates a linear distributed set of buckets which range between min and max.  You can specify the number of buckets as well as the min and max.
*Exponential: This type of metric creates an exponential distributed set of buckets ranging between min and max.  You can specify the min, max, and buckets.
Counter Metric Usage Example:
  // This creates the histogram counter on this metric called
  // 'mycount'
  var count = new AdvancedTelemetryHelper(ATH.HISTOGRAM_COUNT, 'mycount');
  count.add(); //Increment the count. The count of the histogram is now 1.
  // DO SOMETHING
  count.add(); //Increment the count. The count of the histogram is now 2.
  // Linear Metric Usage Example:
  // This creates a linear histogram called 'mylinear' with minimum
  // of 1 (0 not allowed as a minimum), max of 1000, with 10 buckets.
  var linear = new AdvancedTelemetryHelper(ATH.HISTOGRAM_LINEAR, 'mylinear',
      1, 1000, 10);
  // This adds the value 15 to the histogram 'mylinear'
  linear.add(15);
  // DO SOMETHING
  // This adds to the existing histogram a value of 800.
  linear.add(800); // The histogram now has two values, one in the 15 bucket
                    // and one in the bucket that holds the value 800
  Exponential Metric Usage Example:
  // This creates an exponential histogram called 'myexp' with minimum
  // of 1 (0 not allowed as a minimum), max of 1000, with 10 buckets.
  var exp = new AdvancedTelemetryHelper(ATH.HISTOGRAM_EXPONENTIAL, 'myexp',
      1, 1000, 10);
  // This adds the value 15 to the histogram 'myexp'
  exp.add(15);
  // DO SOMETHING
  // This adds to the existing histogram a value of 800.
  exp.add(800); // The histogram now has two values, one in the 15 bucket
                // and one in the bucket that holds the value 800
==Information to Identify==
==Information to Identify==

Revision as of 19:16, 4 November 2015

Custom Metrics

How to Add

To add custom metrics, here is a list of steps:

Add the following to your app (e.g. index.html)

  • <script defer src="/shared/js/advanced_telemetry_helper.js"></script>
  • <script defer src="/shared/js/advanced_telemetry_helper.js"></script>

Include AdvancedTelemetryHelper in the globals

There are currently three types of metrics that can be used as part of Custom Metrics:

  • Counter: This is a simple counter that increments by 1 each time it's called
  • Linear: This type of metric creates a linear distributed set of buckets which range between min and max. You can specify the number of buckets as well as the min and max.
  • Exponential: This type of metric creates an exponential distributed set of buckets ranging between min and max. You can specify the min, max, and buckets.

Counter Metric Usage Example:

 // This creates the histogram counter on this metric called
 // 'mycount'
 var count = new AdvancedTelemetryHelper(ATH.HISTOGRAM_COUNT, 'mycount');
 count.add(); //Increment the count. The count of the histogram is now 1.
 // DO SOMETHING
 count.add(); //Increment the count. The count of the histogram is now 2.
 // Linear Metric Usage Example:
 // This creates a linear histogram called 'mylinear' with minimum
 // of 1 (0 not allowed as a minimum), max of 1000, with 10 buckets.
 var linear = new AdvancedTelemetryHelper(ATH.HISTOGRAM_LINEAR, 'mylinear',
     1, 1000, 10);
 // This adds the value 15 to the histogram 'mylinear'
 linear.add(15);
 // DO SOMETHING
 // This adds to the existing histogram a value of 800.
 linear.add(800); // The histogram now has two values, one in the 15 bucket
                   // and one in the bucket that holds the value 800

 Exponential Metric Usage Example:
 // This creates an exponential histogram called 'myexp' with minimum
 // of 1 (0 not allowed as a minimum), max of 1000, with 10 buckets.
 var exp = new AdvancedTelemetryHelper(ATH.HISTOGRAM_EXPONENTIAL, 'myexp',
     1, 1000, 10);
 // This adds the value 15 to the histogram 'myexp'
 exp.add(15);
 // DO SOMETHING
 // This adds to the existing histogram a value of 800.
 exp.add(800); // The histogram now has two values, one in the 15 bucket
               // and one in the bucket that holds the value 800

Information to Identify