Documentation
¶
Overview ¶
Package metrics provides backend-agnostic service instrumentation.
Services record metrics through Client or the Processor interface. Concrete exporters live in pkg/metrics/processors/* and register themselves at init, following the same plugin pattern used by pkg/fastlog.
Index ¶
- func NormalizeTags(tags []string) []string
- func Register(kind string, factory Factory)
- func RegisteredProcessors() []string
- func SetDefault(c *Client)
- func TagSet(tags []string) string
- type Client
- func (c *Client) Close() error
- func (c *Client) Count(name string, value int64, tags []string) error
- func (c *Client) CounterHandle(name string, tags []string) (Counter, error)
- func (c *Client) Distribution(name string, value float64, tags []string) error
- func (c *Client) DistributionHandle(name string, tags []string) (Observer, error)
- func (c *Client) Gauge(name string, value float64, tags []string) error
- func (c *Client) GaugeHandle(name string, tags []string) (Gauge, error)
- type Config
- type Counter
- type DefaultHandle
- type Factory
- type Gauge
- type HandleProvider
- type Observer
- type Processor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalizeTags ¶
NormalizeTags returns a stable copy of tags suitable for processors.
func RegisteredProcessors ¶
func RegisteredProcessors() []string
RegisteredProcessors returns all registered processor names.
func SetDefault ¶
func SetDefault(c *Client)
SetDefault stores the process-wide metrics client for service-specific instrumentation.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client fans metric calls out to configured processors.
func Default ¶
func Default() *Client
Default returns the process-wide metrics client, or nil when metrics are disabled.
func New ¶
New creates a metrics client from configured processors. Returns nil if cfg is not enabled.
func (*Client) CounterHandle ¶ added in v1.2.5
CounterHandle resolves one counter handle for the metric, covering every configured processor. See HandleProvider.
func (*Client) Distribution ¶
Distribution records a distribution metric.
func (*Client) DistributionHandle ¶ added in v1.2.5
DistributionHandle resolves one distribution handle for the metric, covering every configured processor. See HandleProvider.
type Config ¶
type Config struct {
Processors []string `env:"_PROCESSORS" envDefault:"prometheus"`
}
Config holds backend-agnostic metrics configuration.
Environment:
- METRICS_PROCESSORS defaults to prometheus.
func GetEnvConfig ¶
GetEnvConfig reads metrics configuration from environment variables. Default prefix is METRICS. Processor-specific packages own their own env config.
func PrometheusOnly ¶ added in v1.2.1
PrometheusOnly returns a config that uses Prometheus for every enabled metrics setup.
func (Config) EnabledProcessors ¶
EnabledProcessors returns the configured processors.
type Counter ¶ added in v1.2.5
type Counter = interface{ Add(value int64) }
Counter, Gauge and Observer are resolved metric handles: a caller resolves one through HandleProvider at wiring time and records through it afterwards, so turning a (name, tags) tuple back into a backend child metric happens once instead of on every record. On a data path that records the same bounded set of tuples forever, that is the difference between a hashed cache lookup per record and an increment.
They are aliases to interface literals rather than defined types, and that is load-bearing. A consumer pinned to a release of this module that predates HandleProvider cannot name metrics.Counter, but it can declare the identical literal locally and assert the capability structurally, because Go matches method signatures on type identity and a defined type is never identical to any other type. The aliases are therefore what let a consumer use handles when the linked version provides them and keep using Count/Gauge/Distribution when it does not, without bumping its pin in lockstep with this addition. Do not turn them into defined types.
type DefaultHandle ¶
type DefaultHandle struct {
// contains filtered or unexported fields
}
DefaultHandle restores a package-level metrics default and closes its client.
func InstallDefault ¶
func InstallDefault(c *Client) *DefaultHandle
InstallDefault installs a process-wide metrics default with an explicit close path.
func (*DefaultHandle) Client ¶
func (h *DefaultHandle) Client() *Client
Client returns the installed default client.
func (*DefaultHandle) Close ¶
func (h *DefaultHandle) Close() error
Close restores the previous default client and closes the installed client.
type Gauge ¶ added in v1.2.5
type Gauge = interface{ Set(value float64) }
Counter, Gauge and Observer are resolved metric handles: a caller resolves one through HandleProvider at wiring time and records through it afterwards, so turning a (name, tags) tuple back into a backend child metric happens once instead of on every record. On a data path that records the same bounded set of tuples forever, that is the difference between a hashed cache lookup per record and an increment.
They are aliases to interface literals rather than defined types, and that is load-bearing. A consumer pinned to a release of this module that predates HandleProvider cannot name metrics.Counter, but it can declare the identical literal locally and assert the capability structurally, because Go matches method signatures on type identity and a defined type is never identical to any other type. The aliases are therefore what let a consumer use handles when the linked version provides them and keep using Count/Gauge/Distribution when it does not, without bumping its pin in lockstep with this addition. Do not turn them into defined types.
type HandleProvider ¶ added in v1.2.5
type HandleProvider interface {
CounterHandle(name string, tags []string) (Counter, error)
GaugeHandle(name string, tags []string) (Gauge, error)
DistributionHandle(name string, tags []string) (Observer, error)
}
HandleProvider is the optional capability of resolving a metric handle before recording. It is deliberately not part of Processor: a processor that does not implement it keeps recording through Count, Gauge and Distribution, so implementing it stays opt-in per backend and callers detect support with a type assertion. A returned handle must be safe for concurrent use and stays valid for the life of the processor.
type Observer ¶ added in v1.2.5
type Observer = interface{ Observe(value float64) }
Counter, Gauge and Observer are resolved metric handles: a caller resolves one through HandleProvider at wiring time and records through it afterwards, so turning a (name, tags) tuple back into a backend child metric happens once instead of on every record. On a data path that records the same bounded set of tuples forever, that is the difference between a hashed cache lookup per record and an increment.
They are aliases to interface literals rather than defined types, and that is load-bearing. A consumer pinned to a release of this module that predates HandleProvider cannot name metrics.Counter, but it can declare the identical literal locally and assert the capability structurally, because Go matches method signatures on type identity and a defined type is never identical to any other type. The aliases are therefore what let a consumer use handles when the linked version provides them and keep using Count/Gauge/Distribution when it does not, without bumping its pin in lockstep with this addition. Do not turn them into defined types.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package all imports every in-tree metrics processor so each processor registers with the default metrics registry through its init hook.
|
Package all imports every in-tree metrics processor so each processor registers with the default metrics registry through its init hook. |
|
processors
|
|