Documentation
¶
Overview ¶
Package metrics provides backend-agnostic service instrumentation.
New code should create clients from explicit registries and pass the resulting Recorder or *Client through application composition:
import "github.com/InsideGallery/core/metrics"
registry := metrics.NewRegistry()
client, err := metrics.NewFromOptions(metrics.Options{Service: "api", Registry: registry})
Prefer Recorder, Metric, RecordResult, NewRegistry, NewWithRegistry, and InstallDefault when a scoped compatibility default is still needed.
Compatibility: Register, RegisteredProcessors, SetDefault, Default, and New remain available for existing package-level wiring. New code should avoid hidden process state and pass clients explicitly.
Index ¶
- func NormalizeTags(tags []string) []string
- func Register(kind string, factory Factory)deprecated
- func RegisteredProcessors() []stringdeprecated
- func SetDefault(c *Client)deprecated
- 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) CountMetric(ctx context.Context, metric Metric) (RecordResult, error)
- func (c *Client) Distribution(name string, value float64, tags []string) error
- func (c *Client) DistributionMetric(ctx context.Context, metric Metric) (RecordResult, error)
- func (c *Client) Gauge(name string, value float64, tags []string) error
- func (c *Client) GaugeMetric(ctx context.Context, metric Metric) (RecordResult, error)
- func (c *Client) HealthCheck() error
- type Config
- type DefaultHandle
- type DefaultRegistryHandle
- type Factory
- type HealthChecker
- type Metric
- type Options
- type Processor
- type RecordResult
- type Recorder
- type Registry
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
deprecated
func RegisteredProcessors() []string
RegisteredProcessors returns all registered processor names.
Deprecated: use Registry.RegisteredProcessors on an explicit registry.
func SetDefault
deprecated
func SetDefault(c *Client)
SetDefault stores the process-wide metrics client for service-specific instrumentation.
Deprecated: pass *Client explicitly or use InstallDefault for a scoped compatibility default.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client fans metric calls out to configured processors.
func NewFromOptions ¶
NewFromOptions creates a metrics client from core-owned options.
func NewWithRegistry ¶
NewWithRegistry creates a metrics client from an explicit processor registry.
func (*Client) CountMetric ¶
CountMetric records a count metric through the core-owned Recorder contract.
func (*Client) Distribution ¶
Distribution records a distribution metric.
func (*Client) DistributionMetric ¶
Distribution records a distribution metric through the core-owned Recorder contract.
func (*Client) GaugeMetric ¶
GaugeMetric records a gauge metric through the core-owned Recorder contract.
func (*Client) HealthCheck ¶
HealthCheck verifies all processors that expose a health check.
type Config ¶
type Config struct {
Processors []string `env:"_PROCESSORS" envDefault:"prometheus"`
}
Config holds backend-agnostic metrics configuration.
func GetEnvConfig ¶
GetEnvConfig reads metrics configuration from environment variables. Default prefix is METRICS. Processor-specific packages own their own env config.
func (Config) EnabledProcessors ¶
EnabledProcessors returns the configured processors.
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 DefaultRegistryHandle ¶
type DefaultRegistryHandle struct {
// contains filtered or unexported fields
}
DefaultRegistryHandle restores a previous package-level processor registry.
func InstallDefaultRegistry ¶
func InstallDefaultRegistry(registry *Registry) *DefaultRegistryHandle
InstallDefaultRegistry installs a scoped package-level processor registry.
func (*DefaultRegistryHandle) Close ¶
func (h *DefaultRegistryHandle) Close() error
Close restores the previous package-level processor registry.
type HealthChecker ¶
type HealthChecker interface {
HealthCheck() error
}
HealthChecker is implemented by processors that can verify exporter health.
type Processor ¶
type Processor interface {
Close() error
Count(name string, value int64, tags []string) error
Gauge(name string, value float64, tags []string) error
Distribution(name string, value float64, tags []string) error
}
Processor records metrics for one concrete backend.
type RecordResult ¶
RecordResult describes a completed metric recording operation.
type Recorder ¶
type Recorder interface {
CountMetric(ctx context.Context, metric Metric) (RecordResult, error)
GaugeMetric(ctx context.Context, metric Metric) (RecordResult, error)
DistributionMetric(ctx context.Context, metric Metric) (RecordResult, error)
Close() error
HealthCheck() error
}
Recorder is the core-owned metrics boundary for application code.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry owns metrics processor factories for explicit application composition.
func DefaultRegistry ¶
func DefaultRegistry() *Registry
DefaultRegistry returns the package-level compatibility processor registry.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates an isolated metrics processor registry.
func (*Registry) New ¶
New creates a metrics client from this registry and configured processors. Returns nil if cfg is not enabled.
func (*Registry) RegisteredProcessors ¶
RegisteredProcessors returns all processor names registered on this registry.
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
|
|