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 themetrics.Counter
interface.gauge
: Implements themetrics.Gauge
interface.timer
: Implements themetrics.Timer
interface.histogram
: Implements themetrics.Histogram
interface.expvar
: Provides an implementation of themetrics.Factory
interface using theexpvar
package.go-kit
: Provides an implementation of themetrics.Factory
interface using thego-kit
metrics package.tally
: Provides an implementation of themetrics.Factory
interface using thetally
metrics package.metricstest
: Contains test utilities for themetrics
package.adapters
: Provides adapters for different metrics libraries.keys
: Defines functions for generating unique keys for metrics.
Key Classes:
Factory
: TheFactory
interface defines methods for creating metrics.Counter
: TheCounter
interface defines methods for incrementing a counter.Gauge
: TheGauge
interface defines methods for updating a gauge.Timer
: TheTimer
interface defines methods for recording timing data.Histogram
: TheHistogram
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
andHistogram
interfaces define methods for interacting with different metric types.
References:
- README.md
- Gopkg.toml
- metrics/multi/multi.go
- metrics/counter.go
- metrics/gauge.go
- metrics/expvar/factory_test.go
- metrics/tally/metrics.go
- metrics/go-kit/factory.go
- metrics/metricstest/local.go
- metrics/factory.go
- metrics/go-kit/metrics.go
- metrics/timer.go
- metrics/adapters/factory_test.go
- metrics/histogram.go
- metrics/keys.go
## 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.