Documentation
¶
Index ¶
- Constants
- func AssertMetricDoesNotExist(t any, collector metrics.Metrics, name string, opts ...metrics.MetricOption)
- func AssertMetricExists(t any, collector metrics.Metrics, name string, opts ...metrics.MetricOption)
- func AssertMetricValue(t any, collector metrics.Metrics, name string, expected float64, ...)
- func GetMetricsInstance(container shared.Container) (shared.Metrics, error)
- func MetricsMiddleware(collector metricsutil.Metrics) func(next http.Handler) http.Handler
- func RegisterMetricsCollector(container shared.Container, config *CollectorConfig) error
- func RegisterMetricsEndpoints(router shared.Router, collector metricsutil.Metrics, config *EndpointConfig, ...) error
- func ValidateExportFormat(data []byte, format metrics.ExportFormat) error
- func WaitForMetricValue(collector metrics.Metrics, name string, expected float64, ...) error
- type CollectorConfig
- type CollectorStats
- type CounterData
- type EndpointConfig
- type ExporterConfig
- type GaugeData
- type HTTPMetricsProvider
- type HistogramData
- type IntegrationTestEnvironment
- type MetricDetailProvider
- type Metrics
- type MetricsDataGenerator
- type MetricsEndpointHandler
- type MetricsTestFixture
- type MockCounter
- func (c *MockCounter) Add(value float64)
- func (c *MockCounter) AddCallCount() int
- func (c *MockCounter) Dec()
- func (c *MockCounter) Get() float64
- func (c *MockCounter) Inc()
- func (c *MockCounter) IncCallCount() int
- func (c *MockCounter) Name() string
- func (c *MockCounter) Reset() error
- func (c *MockCounter) Tags() map[string]string
- func (c *MockCounter) WasResetCalled() bool
- func (c *MockCounter) WithLabels(labels map[string]string) shared.Counter
- type MockCustomCollector
- func (c *MockCustomCollector) Collect() map[string]any
- func (c *MockCustomCollector) CollectCallCount() int
- func (c *MockCustomCollector) IsEnabled() bool
- func (c *MockCustomCollector) Name() string
- func (c *MockCustomCollector) Reset() error
- func (c *MockCustomCollector) SetMetric(key string, value any)
- func (c *MockCustomCollector) WasResetCalled() bool
- type MockExporter
- func (e *MockExporter) Export(metrics map[string]any) ([]byte, error)
- func (e *MockExporter) ExportCallCount() int
- func (e *MockExporter) Format() string
- func (e *MockExporter) SetExportData(data []byte)
- func (e *MockExporter) SetExportError(err error)
- func (e *MockExporter) Stats() metrics.ExporterStats
- type MockGauge
- func (g *MockGauge) Add(value float64)
- func (g *MockGauge) Dec()
- func (g *MockGauge) Get() float64
- func (g *MockGauge) Inc()
- func (g *MockGauge) Name() string
- func (g *MockGauge) Reset() error
- func (g *MockGauge) Set(value float64)
- func (g *MockGauge) SetCallCount() int
- func (g *MockGauge) Tags() map[string]string
- func (g *MockGauge) WasResetCalled() bool
- func (g *MockGauge) WithLabels(labels map[string]string) shared.Gauge
- type MockHistogram
- func (h *MockHistogram) GetBuckets() map[float64]uint64
- func (h *MockHistogram) GetCount() uint64
- func (h *MockHistogram) GetMean() float64
- func (h *MockHistogram) GetPercentile(percentile float64) float64
- func (h *MockHistogram) GetSum() float64
- func (h *MockHistogram) Name() string
- func (h *MockHistogram) Observe(value float64)
- func (h *MockHistogram) ObserveCallCount() int
- func (h *MockHistogram) ObserveDuration(start time.Time)
- func (h *MockHistogram) Reset() error
- func (h *MockHistogram) Tags() map[string]string
- func (h *MockHistogram) WasResetCalled() bool
- func (h *MockHistogram) WithLabels(labels map[string]string) shared.Histogram
- type MockMetricsCollector
- func (m *MockMetricsCollector) Counter(name string, opts ...metrics.MetricOption) metrics.Counter
- func (m *MockMetricsCollector) Dependencies() []string
- func (m *MockMetricsCollector) Export(format metrics.ExportFormat) ([]byte, error)
- func (m *MockMetricsCollector) ExportToFile(format metrics.ExportFormat, filename string) error
- func (m *MockMetricsCollector) Gauge(name string, opts ...metrics.MetricOption) metrics.Gauge
- func (m *MockMetricsCollector) GetCollectors() []metrics.CustomCollector
- func (m *MockMetricsCollector) GetMetrics() map[string]any
- func (m *MockMetricsCollector) GetMetricsByTag(tagKey, tagValue string) map[string]any
- func (m *MockMetricsCollector) GetMetricsByType(metricType metrics.MetricType) map[string]any
- func (m *MockMetricsCollector) GetStats() metrics.CollectorStats
- func (m *MockMetricsCollector) Health(ctx context.Context) error
- func (m *MockMetricsCollector) Histogram(name string, opts ...metrics.MetricOption) metrics.Histogram
- func (m *MockMetricsCollector) Name() string
- func (m *MockMetricsCollector) RegisterCollector(collector metrics.CustomCollector) error
- func (m *MockMetricsCollector) Reload(config *shared.MetricsConfig) error
- func (m *MockMetricsCollector) Reset() error
- func (m *MockMetricsCollector) ResetMetric(name string) error
- func (m *MockMetricsCollector) SetExportData(format metrics.ExportFormat, data []byte)
- func (m *MockMetricsCollector) SetExportError(err error)
- func (m *MockMetricsCollector) SetHealthCheckError(err error)
- func (m *MockMetricsCollector) Start(ctx context.Context) error
- func (m *MockMetricsCollector) Stop(ctx context.Context) error
- func (m *MockMetricsCollector) Timer(name string, opts ...metrics.MetricOption) metrics.Timer
- func (m *MockMetricsCollector) UnregisterCollector(name string) error
- func (m *MockMetricsCollector) WasResetCalled() bool
- func (m *MockMetricsCollector) WasResetMetricCalled(name string) bool
- type MockTimer
- func (t *MockTimer) Get() time.Duration
- func (t *MockTimer) GetCount() uint64
- func (t *MockTimer) GetMax() time.Duration
- func (t *MockTimer) GetMean() time.Duration
- func (t *MockTimer) GetMin() time.Duration
- func (t *MockTimer) GetPercentile(percentile float64) time.Duration
- func (t *MockTimer) Name() string
- func (t *MockTimer) Record(duration time.Duration)
- func (t *MockTimer) RecordCallCount() int
- func (t *MockTimer) Reset()
- func (t *MockTimer) Tags() map[string]string
- func (t *MockTimer) Time() func()
- func (t *MockTimer) WasResetCalled() bool
- type PerformanceResult
- type PerformanceTestRunner
- type RegisteredMetric
- type Registry
- type RegistryConfig
- type StorageConfig
- type TimerData
Constants ¶
const CollectorKey = shared.MetricsCollectorKey
const MetricsKey = shared.MetricsKey
Variables ¶
This section is empty.
Functions ¶
func AssertMetricDoesNotExist ¶
func AssertMetricDoesNotExist(t any, collector metrics.Metrics, name string, opts ...metrics.MetricOption)
AssertMetricDoesNotExist asserts that a metric does not exist.
func AssertMetricExists ¶
func AssertMetricExists(t any, collector metrics.Metrics, name string, opts ...metrics.MetricOption)
AssertMetricExists asserts that a metric exists.
func AssertMetricValue ¶
func AssertMetricValue(t any, collector metrics.Metrics, name string, expected float64, opts ...metrics.MetricOption)
AssertMetricValue asserts that a metric has the expected value.
func GetMetricsInstance ¶
GetMetricsInstance retrieves the metrics collector from DI container.
func MetricsMiddleware ¶
MetricsMiddleware creates middleware for collecting HTTP metricsutil.
func RegisterMetricsCollector ¶
func RegisterMetricsCollector(container shared.Container, config *CollectorConfig) error
RegisterMetricsCollector registers the metrics collector directly with DI container.
func RegisterMetricsEndpoints ¶
func RegisterMetricsEndpoints(router shared.Router, collector metricsutil.Metrics, config *EndpointConfig, logger logger.Logger) error
RegisterMetricsEndpoints registers metrics endpoints with a router.
func ValidateExportFormat ¶
func ValidateExportFormat(data []byte, format metrics.ExportFormat) error
ValidateExportFormat validates that export format is valid.
Types ¶
type CollectorConfig ¶
type CollectorConfig = shared.MetricsConfig
CollectorConfig contains configuration for the metrics collector.
func DefaultCollectorConfig ¶
func DefaultCollectorConfig() *CollectorConfig
DefaultCollectorConfig returns default collector configuration.
type CollectorStats ¶
type CollectorStats = metrics.CollectorStats
CollectorStats contains statistics about the metrics collector.
type CounterData ¶
CounterData holds counter test data.
type EndpointConfig ¶
type EndpointConfig struct {
Enabled bool `json:"enabled" yaml:"enabled"`
PrefixPath string `json:"prefix_path" yaml:"prefix_path"`
MetricsPath string `json:"metrics_path" yaml:"metrics_path"`
HealthPath string `json:"health_path" yaml:"health_path"`
StatsPath string `json:"stats_path" yaml:"stats_path"`
EnableCORS bool `json:"enable_cors" yaml:"enable_cors"`
RequireAuth bool `json:"require_auth" yaml:"require_auth"`
CacheDuration time.Duration `json:"cache_duration" yaml:"cache_duration"`
}
EndpointConfig contains configuration for metrics endpoints.
type ExporterConfig ¶
type ExporterConfig = shared.MetricsExporterConfig[map[string]any]
ExporterConfig contains configuration for exporters.
type HTTPMetricsProvider ¶ added in v1.2.0
type HTTPMetricsProvider interface {
// HTTPMiddleware returns middleware that automatically records HTTP request metrics.
// Returns nil if HTTP metrics are not enabled.
HTTPMiddleware() func(http.Handler) http.Handler
}
HTTPMetricsProvider is implemented by metrics collectors that can provide HTTP middleware for automatic request tracking.
type HistogramData ¶
type IntegrationTestEnvironment ¶
type IntegrationTestEnvironment struct {
Collector metrics.Metrics
Registry Registry
Exporters map[metrics.ExportFormat]metrics.Exporter
Logger logger.Logger
// contains filtered or unexported fields
}
IntegrationTestEnvironment provides a complete integration test environment.
func NewIntegrationTestEnvironment ¶
func NewIntegrationTestEnvironment(useRealImplementations bool) *IntegrationTestEnvironment
NewIntegrationTestEnvironment creates a new integration test environment.
func (*IntegrationTestEnvironment) Cleanup ¶
func (e *IntegrationTestEnvironment) Cleanup()
Cleanup cleans up the integration test environment.
func (*IntegrationTestEnvironment) RunFullIntegrationTest ¶
func (e *IntegrationTestEnvironment) RunFullIntegrationTest() error
RunFullIntegrationTest runs a complete integration test.
func (*IntegrationTestEnvironment) Setup ¶
func (e *IntegrationTestEnvironment) Setup() error
Setup sets up the integration test environment.
type MetricDetailProvider ¶ added in v1.2.0
type MetricDetailProvider interface {
// GetMetric returns a named metric from the registry.
// The returned value can be type-asserted to Counter, Gauge, Histogram, or Timer.
GetMetric(name string) any
// GetCollector returns a named custom collector.
GetCollector(name string) metrics.CustomCollector
}
MetricDetailProvider is implemented by metrics collectors that expose individual metric objects for detailed introspection (metadata, exemplars, etc.).
type Metrics ¶
Metrics defines the interface for metrics collection.
func New ¶
func New(config *CollectorConfig, logger logger.Logger) Metrics
New creates a new metrics collector.
func NewNoOpMetrics ¶
func NewNoOpMetrics() Metrics
NewNoOpMetrics creates a no-op metrics collector that implements the full Metrics interface but performs no actual metric collection or storage. Useful for testing, benchmarking, or when metrics are disabled.
type MetricsDataGenerator ¶
type MetricsDataGenerator struct {
// contains filtered or unexported fields
}
MetricsDataGenerator generates test metrics data.
func NewMetricsDataGenerator ¶
func NewMetricsDataGenerator(seed int64) *MetricsDataGenerator
NewMetricsDataGenerator creates a new data generator.
func (*MetricsDataGenerator) GenerateCounterData ¶
func (g *MetricsDataGenerator) GenerateCounterData(count int) []CounterData
GenerateCounterData generates counter test data.
func (*MetricsDataGenerator) GenerateGaugeData ¶
func (g *MetricsDataGenerator) GenerateGaugeData(count int) []GaugeData
GenerateGaugeData generates gauge test data.
func (*MetricsDataGenerator) GenerateHistogramData ¶
func (g *MetricsDataGenerator) GenerateHistogramData(count int) []HistogramData
GenerateHistogramData generates histogram test data.
func (*MetricsDataGenerator) GenerateTimerData ¶
func (g *MetricsDataGenerator) GenerateTimerData(count int) []TimerData
GenerateTimerData generates timer test data.
type MetricsEndpointHandler ¶
type MetricsEndpointHandler struct {
// contains filtered or unexported fields
}
MetricsEndpointHandler handles metrics endpoint requests.
func NewMetricsEndpointHandler ¶
func NewMetricsEndpointHandler(collector shared.Metrics, config *EndpointConfig, logger logger.Logger) *MetricsEndpointHandler
NewMetricsEndpointHandler creates a new metrics endpoint handler.
func (*MetricsEndpointHandler) RegisterEndpoints ¶
func (h *MetricsEndpointHandler) RegisterEndpoints(r shared.Router) error
RegisterEndpoints registers metrics endpoints with the router.
type MetricsTestFixture ¶
type MetricsTestFixture struct {
Collector *MockMetricsCollector
Registry Registry
Exporters map[metrics.ExportFormat]metrics.Exporter
Logger logger.Logger
// contains filtered or unexported fields
}
MetricsTestFixture provides a complete test environment for metrics.
func NewMetricsTestFixture ¶
func NewMetricsTestFixture() *MetricsTestFixture
NewMetricsTestFixture creates a new test fixture.
func (*MetricsTestFixture) Cleanup ¶
func (f *MetricsTestFixture) Cleanup()
Cleanup cleans up the test fixture.
func (*MetricsTestFixture) Context ¶
func (f *MetricsTestFixture) Context() context.Context
Context returns the test context.
func (*MetricsTestFixture) CreateTestMetrics ¶
func (f *MetricsTestFixture) CreateTestMetrics()
CreateTestMetrics creates a set of test metrics.
func (*MetricsTestFixture) StartCollector ¶
func (f *MetricsTestFixture) StartCollector() error
StartCollector starts the mock collector.
type MockCounter ¶
type MockCounter struct {
// contains filtered or unexported fields
}
MockCounter implements Counter interface.
func NewMockCounter ¶
func NewMockCounter(name string, tags map[string]string) *MockCounter
func (*MockCounter) Add ¶
func (c *MockCounter) Add(value float64)
func (*MockCounter) AddCallCount ¶
func (c *MockCounter) AddCallCount() int
func (*MockCounter) Dec ¶
func (c *MockCounter) Dec()
func (*MockCounter) Get ¶
func (c *MockCounter) Get() float64
func (*MockCounter) Inc ¶
func (c *MockCounter) Inc()
func (*MockCounter) IncCallCount ¶
func (c *MockCounter) IncCallCount() int
func (*MockCounter) Name ¶
func (c *MockCounter) Name() string
func (*MockCounter) Reset ¶
func (c *MockCounter) Reset() error
func (*MockCounter) Tags ¶
func (c *MockCounter) Tags() map[string]string
func (*MockCounter) WasResetCalled ¶
func (c *MockCounter) WasResetCalled() bool
func (*MockCounter) WithLabels ¶
func (c *MockCounter) WithLabels(labels map[string]string) shared.Counter
type MockCustomCollector ¶
type MockCustomCollector struct {
// contains filtered or unexported fields
}
MockCustomCollector implements CustomCollector interface.
func NewMockCustomCollector ¶
func NewMockCustomCollector(name string) *MockCustomCollector
func (*MockCustomCollector) Collect ¶
func (c *MockCustomCollector) Collect() map[string]any
func (*MockCustomCollector) CollectCallCount ¶
func (c *MockCustomCollector) CollectCallCount() int
func (*MockCustomCollector) IsEnabled ¶
func (c *MockCustomCollector) IsEnabled() bool
func (*MockCustomCollector) Name ¶
func (c *MockCustomCollector) Name() string
func (*MockCustomCollector) Reset ¶
func (c *MockCustomCollector) Reset() error
func (*MockCustomCollector) SetMetric ¶
func (c *MockCustomCollector) SetMetric(key string, value any)
func (*MockCustomCollector) WasResetCalled ¶
func (c *MockCustomCollector) WasResetCalled() bool
type MockExporter ¶
type MockExporter struct {
// contains filtered or unexported fields
}
MockExporter implements Exporter interface.
func NewMockExporter ¶
func NewMockExporter(format string) *MockExporter
func (*MockExporter) ExportCallCount ¶
func (e *MockExporter) ExportCallCount() int
func (*MockExporter) Format ¶
func (e *MockExporter) Format() string
func (*MockExporter) SetExportData ¶
func (e *MockExporter) SetExportData(data []byte)
func (*MockExporter) SetExportError ¶
func (e *MockExporter) SetExportError(err error)
func (*MockExporter) Stats ¶
func (e *MockExporter) Stats() metrics.ExporterStats
type MockGauge ¶
type MockGauge struct {
// contains filtered or unexported fields
}
MockGauge implements Gauge interface.
func (*MockGauge) SetCallCount ¶
func (*MockGauge) WasResetCalled ¶
type MockHistogram ¶
type MockHistogram struct {
// contains filtered or unexported fields
}
MockHistogram implements Histogram interface.
func NewMockHistogram ¶
func NewMockHistogram(name string, tags map[string]string) *MockHistogram
func (*MockHistogram) GetBuckets ¶
func (h *MockHistogram) GetBuckets() map[float64]uint64
func (*MockHistogram) GetCount ¶
func (h *MockHistogram) GetCount() uint64
func (*MockHistogram) GetMean ¶
func (h *MockHistogram) GetMean() float64
func (*MockHistogram) GetPercentile ¶
func (h *MockHistogram) GetPercentile(percentile float64) float64
func (*MockHistogram) GetSum ¶
func (h *MockHistogram) GetSum() float64
func (*MockHistogram) Name ¶
func (h *MockHistogram) Name() string
func (*MockHistogram) Observe ¶
func (h *MockHistogram) Observe(value float64)
func (*MockHistogram) ObserveCallCount ¶
func (h *MockHistogram) ObserveCallCount() int
func (*MockHistogram) ObserveDuration ¶
func (h *MockHistogram) ObserveDuration(start time.Time)
func (*MockHistogram) Reset ¶
func (h *MockHistogram) Reset() error
func (*MockHistogram) Tags ¶
func (h *MockHistogram) Tags() map[string]string
func (*MockHistogram) WasResetCalled ¶
func (h *MockHistogram) WasResetCalled() bool
func (*MockHistogram) WithLabels ¶
func (h *MockHistogram) WithLabels(labels map[string]string) shared.Histogram
type MockMetricsCollector ¶
MockMetricsCollector implements MetricsCollector interface for testing.
func NewMockMetricsCollector ¶
func NewMockMetricsCollector() *MockMetricsCollector
NewMockMetricsCollector creates a new mock metrics collector.
func (*MockMetricsCollector) Counter ¶
func (m *MockMetricsCollector) Counter(name string, opts ...metrics.MetricOption) metrics.Counter
Counter creates or retrieves a counter metric.
func (*MockMetricsCollector) Dependencies ¶
func (m *MockMetricsCollector) Dependencies() []string
func (*MockMetricsCollector) Export ¶
func (m *MockMetricsCollector) Export(format metrics.ExportFormat) ([]byte, error)
Export functionality.
func (*MockMetricsCollector) ExportToFile ¶
func (m *MockMetricsCollector) ExportToFile(format metrics.ExportFormat, filename string) error
func (*MockMetricsCollector) Gauge ¶
func (m *MockMetricsCollector) Gauge(name string, opts ...metrics.MetricOption) metrics.Gauge
func (*MockMetricsCollector) GetCollectors ¶
func (m *MockMetricsCollector) GetCollectors() []metrics.CustomCollector
func (*MockMetricsCollector) GetMetrics ¶
func (m *MockMetricsCollector) GetMetrics() map[string]any
GetMetrics returns all collected metrics.
func (*MockMetricsCollector) GetMetricsByTag ¶
func (m *MockMetricsCollector) GetMetricsByTag(tagKey, tagValue string) map[string]any
func (*MockMetricsCollector) GetMetricsByType ¶
func (m *MockMetricsCollector) GetMetricsByType(metricType metrics.MetricType) map[string]any
func (*MockMetricsCollector) GetStats ¶
func (m *MockMetricsCollector) GetStats() metrics.CollectorStats
GetStats returns collector statistics.
func (*MockMetricsCollector) Health ¶
func (m *MockMetricsCollector) Health(ctx context.Context) error
func (*MockMetricsCollector) Histogram ¶
func (m *MockMetricsCollector) Histogram(name string, opts ...metrics.MetricOption) metrics.Histogram
func (*MockMetricsCollector) Name ¶
func (m *MockMetricsCollector) Name() string
Name returns the service name.
func (*MockMetricsCollector) RegisterCollector ¶
func (m *MockMetricsCollector) RegisterCollector(collector metrics.CustomCollector) error
RegisterCollector registers a custom collector.
func (*MockMetricsCollector) Reload ¶
func (m *MockMetricsCollector) Reload(config *shared.MetricsConfig) error
func (*MockMetricsCollector) Reset ¶
func (m *MockMetricsCollector) Reset() error
Reset resets all collected metrics.
func (*MockMetricsCollector) ResetMetric ¶
func (m *MockMetricsCollector) ResetMetric(name string) error
func (*MockMetricsCollector) SetExportData ¶
func (m *MockMetricsCollector) SetExportData(format metrics.ExportFormat, data []byte)
func (*MockMetricsCollector) SetExportError ¶
func (m *MockMetricsCollector) SetExportError(err error)
func (*MockMetricsCollector) SetHealthCheckError ¶
func (m *MockMetricsCollector) SetHealthCheckError(err error)
SetHealthCheckError sets the health check error for testing.
func (*MockMetricsCollector) Start ¶
func (m *MockMetricsCollector) Start(ctx context.Context) error
func (*MockMetricsCollector) Timer ¶
func (m *MockMetricsCollector) Timer(name string, opts ...metrics.MetricOption) metrics.Timer
func (*MockMetricsCollector) UnregisterCollector ¶
func (m *MockMetricsCollector) UnregisterCollector(name string) error
func (*MockMetricsCollector) WasResetCalled ¶
func (m *MockMetricsCollector) WasResetCalled() bool
func (*MockMetricsCollector) WasResetMetricCalled ¶
func (m *MockMetricsCollector) WasResetMetricCalled(name string) bool
type MockTimer ¶
type MockTimer struct {
// contains filtered or unexported fields
}
MockTimer implements Timer interface.
func (*MockTimer) GetPercentile ¶
func (*MockTimer) RecordCallCount ¶
func (*MockTimer) WasResetCalled ¶
type PerformanceResult ¶
type PerformanceResult struct {
Operations int64 `json:"operations"`
Duration time.Duration `json:"duration"`
Workers int `json:"workers"`
OpsPerSecond float64 `json:"ops_per_second"`
OpsPerWorker float64 `json:"ops_per_worker"`
}
PerformanceResult contains performance test results.
type PerformanceTestRunner ¶
type PerformanceTestRunner struct {
// contains filtered or unexported fields
}
PerformanceTestRunner runs performance tests on metrics.
func NewPerformanceTestRunner ¶
func NewPerformanceTestRunner(collector metrics.Metrics, duration time.Duration, workers int) *PerformanceTestRunner
NewPerformanceTestRunner creates a new performance test runner.
func (*PerformanceTestRunner) RunCounterTest ¶
func (r *PerformanceTestRunner) RunCounterTest() PerformanceResult
RunCounterTest runs a performance test on counters.
func (*PerformanceTestRunner) RunGaugeTest ¶
func (r *PerformanceTestRunner) RunGaugeTest() PerformanceResult
RunGaugeTest runs a performance test on gauges.
func (*PerformanceTestRunner) RunHistogramTest ¶
func (r *PerformanceTestRunner) RunHistogramTest() PerformanceResult
RunHistogramTest runs a performance test on histograms.
func (*PerformanceTestRunner) RunTimerTest ¶
func (r *PerformanceTestRunner) RunTimerTest() PerformanceResult
RunTimerTest runs a performance test on timers.
type RegisteredMetric ¶
type RegisteredMetric struct {
Name string `json:"name"`
Type metrics.MetricType `json:"type"`
Tags map[string]string `json:"tags"`
Metric any `json:"-"`
Metadata *metrics.MetricMetadata `json:"metadata"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
AccessCount int64 `json:"access_count"`
LastAccess time.Time `json:"last_access"`
// contains filtered or unexported fields
}
RegisteredMetric represents a registered metric with metadata.
func (*RegisteredMetric) GetValue ¶
func (rm *RegisteredMetric) GetValue() any
GetValue returns the current value of the metric. For counters, the value is wrapped with type metadata so exporters can distinguish counters from gauges (both are scalar float64 values).
func (*RegisteredMetric) UpdateAccess ¶
func (rm *RegisteredMetric) UpdateAccess()
UpdateAccess updates access statistics.
type Registry ¶
type Registry interface {
// Metric creation and retrieval
GetOrCreateCounter(name string, opts ...metrics.MetricOption) metrics.Counter
GetOrCreateGauge(name string, opts ...metrics.MetricOption) metrics.Gauge
GetOrCreateHistogram(name string, opts ...metrics.MetricOption) metrics.Histogram
GetOrCreateTimer(name string, opts ...metrics.MetricOption) metrics.Timer
// Metric retrieval
GetMetric(name string, tags map[string]string) any
GetAllMetrics() map[string]any
GetMetricsByType(metricType metrics.MetricType) map[string]any
GetMetricsByTag(tagKey, tagValue string) map[string]any
GetMetricsByNamePattern(pattern string) map[string]any
// Metric management
RegisterMetric(name string, metric any, metricType metrics.MetricType, opts ...metrics.MetricOption) error
UnregisterMetric(name string, opts ...metrics.MetricOption) error
ResetMetric(name string) error
Reset() error
// Statistics
Count() int
GetRegisteredMetrics() []*RegisteredMetric
GetMetricMetadata(name string, tags map[string]string) *metrics.MetricMetadata
// Lifecycle
Start() error
Stop() error
}
Registry manages metric storage and retrieval.
func NewRegistryWithConfig ¶
func NewRegistryWithConfig(config *RegistryConfig) Registry
NewRegistryWithConfig creates a new metrics registry with custom configuration.
type RegistryConfig ¶
type RegistryConfig struct {
MaxMetrics int `json:"max_metrics" yaml:"max_metrics"`
CleanupInterval time.Duration `json:"cleanup_interval" yaml:"cleanup_interval"`
EnableIndexing bool `json:"enable_indexing" yaml:"enable_indexing"`
}
RegistryConfig contains configuration for the registry.
func DefaultRegistryConfig ¶
func DefaultRegistryConfig() *RegistryConfig
DefaultRegistryConfig returns default registry configuration.
type StorageConfig ¶
type StorageConfig = shared.MetricsStorageConfig[map[string]any]
StorageConfig contains storage configuration.