The metrics utility for offchain-sdk.
types.go defines the interface for the supported metrics methods.
By specifying the configuration, the metrics can be emitted via Datadog and/or Prometheus. Please see the following subsections for detailed configurations.
The first step is adding a section in your config file. See following subsection for details. The source code defining those configs can be found in config.go.
-
Enabled
: Set totrue
to enable metrics emission to Datadog. -
StatsdAddr
: The address of the Datadog StatsD client. This is needed if the metrics should be emitted from Datadog. -
Namespace
: This will appear as theNamespace
tag in Datadog.
metrics.go implements the Datadog version of the supported metrics methods
defined in types.go. All implementations are simple wrappers around the native methods
provided by the Datadog statsd
client.
The first step is to add a section in your config file. The source code defining these configs can be found in config.go.
-
Enabled
: Set to true to enable metrics emission to Prometheus. -
Namespace
andSubsystem
: These fields will be added as prefixes to the metrics name. For example, ifNamespace
isapp
andSubsystem
isapi
, then the full metrics name ofrequest_success
will beapp_api_request_success
. -
HistogramBucketCount
: The number of buckets used for Histogram typed metrics. Default is 10.- Note: Each bucket represents an observation that Prometheus scrapes. Therefore, it's recommended to keep the number of buckets within a manageable scale, typically in the tens.
Different from Datadog, Prometheus only provides 4 basic metrics type. As a result, metrics.go implements the metrics methods defined in type.go using these four basic Prometheus metrics. The following subsection documents the methods with implementation notes. For more information on the four basic Prometheus metrics, please see here.
-
Gauge
: This method wraps theGauge
metrics of Prometheus. -
Decr
andIncr
: Implemented using theGauge
metrics of Prometheus. -
Count
: This method wraps theCount
metrics of Prometheus. Note that after deployment or instance restart,Count
will reset to 0. This is by design in Prometheus. -
IncMonotonic
andError
: Implemented using theCount
metrics of Prometheus. -
Histogram
: This method wraps theHistogram
metrics of Prometheus with linear buckets.- Note: The maximum value covered is determined by the product of BucketCount and the rate parameter.
- TODO: Support different types of buckets beyond linear buckets in future implementations.
-
Time
andLatency
: Implemented using theSummary
metrics of Prometheus, with pre-defined quantile observations: p50, p90, and p99.