metrics

This package provides a metrics abstraction layer for Jaeger.

Motivation:

Jaeger leverages various metrics libraries (like go-kit, tally and expvar) for different use-cases. The metrics package serves as a central hub, abstracting away the underlying implementations to provide a unified interface for consuming and publishing metrics.

Organization:

The metrics package is structured into several subpackages:

  • multi: This subpackage defines interfaces for collecting metrics from multiple sources.
  • counter: Implements the metrics.Counter interface.
  • gauge: Implements the metrics.Gauge interface.
  • timer: Implements the metrics.Timer interface.
  • histogram: Implements the metrics.Histogram interface.
  • expvar: Provides an implementation of the metrics.Factory interface using the expvar package.
  • go-kit: Provides an implementation of the metrics.Factory interface using the go-kit metrics package.
  • tally: Provides an implementation of the metrics.Factory interface using the tally metrics package.
  • metricstest: Contains test utilities for the metrics package.
  • adapters: Provides adapters for different metrics libraries.
  • keys: Defines functions for generating unique keys for metrics.

Key Classes:

  • Factory: The Factory interface defines methods for creating metrics.
  • Counter: The Counter interface defines methods for incrementing a counter.
  • Gauge: The Gauge interface defines methods for updating a gauge.
  • Timer: The Timer interface defines methods for recording timing data.
  • Histogram: The Histogram interface defines methods for recording histogram data.

Examples:

Example Usage of Factory:

package main
          
          import (
            "github.com/uber/jaeger-lib/metrics"
          )
          
          func main() {
            factory := metrics.NewFactory(100)
            counter := factory.Counter(metrics.Options{
              Name: "my_counter",
            })
            counter.Inc(1)
          }
          

Example Usage of Counter:

package main
          
          import (
            "github.com/uber/jaeger-lib/metrics"
          )
          
          func main() {
            factory := metrics.NewFactory(100)
            counter := factory.Counter(metrics.Options{
              Name: "my_counter",
            })
            counter.Inc(1)
          }
          

Example Usage of Gauge:

package main
          
          import (
            "github.com/uber/jaeger-lib/metrics"
          )
          
          func main() {
            factory := metrics.NewFactory(100)
            gauge := factory.Gauge(metrics.Options{
              Name: "my_gauge",
            })
            gauge.Update(1)
          }
          

Example Usage of Timer:

package main
          
          import (
            "github.com/uber/jaeger-lib/metrics"
            "time"
          )
          
          func main() {
            factory := metrics.NewFactory(100)
            timer := factory.Timer(metrics.TimerOptions{
              Name: "my_timer",
            })
            timer.Record(10 * time.Millisecond)
          }
          

Example Usage of Histogram:

package main
          
          import (
            "github.com/uber/jaeger-lib/metrics"
          )
          
          func main() {
            factory := metrics.NewFactory(100)
            histogram := factory.Histogram(metrics.HistogramOptions{
              Name: "my_histogram",
              Buckets: []float64{10, 20, 30},
            })
            histogram.Record(25)
          }
          

Key Points:

  • The metrics package provides a comprehensive abstraction layer for working with metrics in Jaeger.
  • It supports multiple underlying metrics libraries, allowing for flexibility and customization.
  • The metrics.Factory interface serves as the entry point for creating metrics.
  • The Counter, Gauge, Timer and Histogram interfaces define methods for interacting with different metric types.

References:


          ## Top-Level Directory Explanations
          
          <a class='local-link directory-link' data-ref="metrics/" href="#metrics/">metrics/</a> - This directory contains the metrics implementation for the Jaeger Tracing library.
          
          <a class='local-link directory-link' data-ref="metrics/adapters/" href="#metrics/adapters/">metrics/adapters/</a> - This subdirectory contains the various metric adapters for different backends.
          
          <a class='local-link directory-link' data-ref="metrics/expvar/" href="#metrics/expvar/">metrics/expvar/</a> - This subdirectory contains the implementation for exposing metrics as HTTP endpoints using the expvar package.
          
          <a class='local-link directory-link' data-ref="metrics/fork/" href="#metrics/fork/">metrics/fork/</a> - This subdirectory contains the implementation for forking metrics between processes.
          
          <a class='local-link directory-link' data-ref="metrics/go-kit/" href="#metrics/go-kit/">metrics/go-kit/</a> - This subdirectory contains the Go-Kit integration for the Jaeger Tracing library.
          
          <a class='local-link directory-link' data-ref="metrics/go-kit/expvar/" href="#metrics/go-kit/expvar/">metrics/go-kit/expvar/</a> - This subdirectory contains the expvar implementation for the Go-Kit integration.
          
          <a class='local-link directory-link' data-ref="metrics/go-kit/influx/" href="#metrics/go-kit/influx/">metrics/go-kit/influx/</a> - This subdirectory contains the InfluxDB implementation for the Go-Kit integration.
          
          <a class='local-link directory-link' data-ref="metrics/metricstest/" href="#metrics/metricstest/">metrics/metricstest/</a> - This subdirectory contains the testing implementation for the metrics.
          
          <a class='local-link directory-link' data-ref="metrics/multi/" href="#metrics/multi/">metrics/multi/</a> - This subdirectory contains the implementation for collecting metrics from multiple sources.
          
          <a class='local-link directory-link' data-ref="metrics/prometheus/" href="#metrics/prometheus/">metrics/prometheus/</a> - This subdirectory contains the Prometheus implementation for the Jaeger Tracing library.
          
          <a class='local-link directory-link' data-ref="metrics/tally/" href="#metrics/tally/">metrics/tally/</a> - This subdirectory contains the implementation for counting metrics using the tally package.