metrics

package
v0.1.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheCollector

type CacheCollector struct {
	// contains filtered or unexported fields
}

CacheCollector wraps Redis client with metrics

func NewCacheCollector

func NewCacheCollector(client *redis.Client, collector CacheMetricsCollector) *CacheCollector

NewCacheCollector creates a cache collector wrapper

func (*CacheCollector) Del

func (c *CacheCollector) Del(ctx context.Context, keys ...string) *redis.IntCmd

Del wraps Redis DEL with metrics

func (*CacheCollector) Get

func (c *CacheCollector) Get(ctx context.Context, key string) *redis.StringCmd

Get wraps Redis GET with metrics

func (*CacheCollector) GetClient

func (c *CacheCollector) GetClient() *redis.Client

GetClient returns the underlying Redis client

func (*CacheCollector) HDel

func (c *CacheCollector) HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd

HDel wraps Redis HDEL with metrics

func (*CacheCollector) HGet

func (c *CacheCollector) HGet(ctx context.Context, key, field string) *redis.StringCmd

HGet wraps Redis HGET with metrics

func (*CacheCollector) HSet

func (c *CacheCollector) HSet(ctx context.Context, key string, values ...any) *redis.IntCmd

HSet wraps Redis HSET with metrics

func (*CacheCollector) Ping

Ping wraps Redis PING with metrics

func (*CacheCollector) PoolStats

func (c *CacheCollector) PoolStats() *redis.PoolStats

PoolStats returns pool statistics and updates metrics

func (*CacheCollector) Set

func (c *CacheCollector) Set(ctx context.Context, key string, value any, expiration time.Duration) *redis.StatusCmd

Set wraps Redis SET with metrics

type CacheMetricsCollector

type CacheMetricsCollector interface {
	RedisCommand(command string, err error)
}

CacheMetricsCollector for Redis cache operations

type Collector

type Collector interface {
	DBQuery(duration time.Duration, err error)
	DBTransaction(err error)
	DBConnections(count int)
	RedisCommand(command string, err error)
	RedisConnections(count int)
	MongoOperation(operation string, err error)
	SearchQuery(engine string, err error)
	SearchIndex(engine, operation string)
	MQPublish(system string, err error)
	MQConsume(system string, err error)
	HealthCheck(component string, healthy bool)
}

Collector interface for data layer metrics

type DataCollector

type DataCollector struct {
	// contains filtered or unexported fields
}

DataCollector collects data layer metrics

func NewDataCollector

func NewDataCollector(batchSize int) *DataCollector

NewDataCollector creates a new data collector with memory storage

func NewDataCollectorWithRedis

func NewDataCollectorWithRedis(client *redis.Client, keyPrefix string, retention time.Duration, batchSize int) *DataCollector

NewDataCollectorWithRedis creates a new data collector with Redis storage

func (*DataCollector) Close

func (c *DataCollector) Close() error

Close closes the collector and flushes remaining metrics

func (*DataCollector) DBConnections

func (c *DataCollector) DBConnections(count int)

DBConnections records database connection count

func (*DataCollector) DBQuery

func (c *DataCollector) DBQuery(duration time.Duration, err error)

DBQuery records database query metrics

func (*DataCollector) DBTransaction

func (c *DataCollector) DBTransaction(err error)

DBTransaction records database transaction metrics

func (*DataCollector) GetStats

func (c *DataCollector) GetStats() map[string]any

GetStats returns current statistics

func (*DataCollector) HealthCheck

func (c *DataCollector) HealthCheck(component string, healthy bool)

HealthCheck records health check metrics

func (*DataCollector) MQConsume

func (c *DataCollector) MQConsume(system string, err error)

MQConsume records message queue consume metrics

func (*DataCollector) MQPublish

func (c *DataCollector) MQPublish(system string, err error)

MQPublish records message queue publish metrics

func (*DataCollector) MongoOperation

func (c *DataCollector) MongoOperation(operation string, err error)

MongoOperation records MongoDB operation metrics

func (*DataCollector) RedisCommand

func (c *DataCollector) RedisCommand(command string, err error)

RedisCommand records Redis command metrics

func (*DataCollector) RedisConnections

func (c *DataCollector) RedisConnections(count int)

RedisConnections records Redis connection count

func (*DataCollector) SearchIndex

func (c *DataCollector) SearchIndex(engine, operation string)

SearchIndex records search index operation metrics

func (*DataCollector) SearchQuery

func (c *DataCollector) SearchQuery(engine string, err error)

SearchQuery records search query metrics

type ExtensionCollector

type ExtensionCollector interface {
	DBQuery(duration time.Duration, err error)
	DBTransaction(err error)
	DBConnections(count int)
	RedisCommand(command string, err error)
	RedisConnections(count int)
	MongoOperation(operation string, err error)
	SearchQuery(engine string, err error)
	SearchIndex(engine, operation string)
	MQPublish(system string, err error)
	MQConsume(system string, err error)
	HealthCheck(component string, healthy bool)
}

ExtensionCollector interface from extension layer

type ExtensionCollectorAdapter

type ExtensionCollectorAdapter struct {
	// contains filtered or unexported fields
}

ExtensionCollectorAdapter adapts extension metrics collector to data layer interface

func NewExtensionCollectorAdapter

func NewExtensionCollectorAdapter(collector ExtensionCollector) *ExtensionCollectorAdapter

NewExtensionCollectorAdapter creates adapter for extension collector

func (*ExtensionCollectorAdapter) DBConnections

func (a *ExtensionCollectorAdapter) DBConnections(count int)

func (*ExtensionCollectorAdapter) DBQuery

func (a *ExtensionCollectorAdapter) DBQuery(duration time.Duration, err error)

Implement data layer Collector interface

func (*ExtensionCollectorAdapter) DBTransaction

func (a *ExtensionCollectorAdapter) DBTransaction(err error)

func (*ExtensionCollectorAdapter) HealthCheck

func (a *ExtensionCollectorAdapter) HealthCheck(component string, healthy bool)

func (*ExtensionCollectorAdapter) MQConsume

func (a *ExtensionCollectorAdapter) MQConsume(system string, err error)

func (*ExtensionCollectorAdapter) MQPublish

func (a *ExtensionCollectorAdapter) MQPublish(system string, err error)

func (*ExtensionCollectorAdapter) MongoOperation

func (a *ExtensionCollectorAdapter) MongoOperation(operation string, err error)

func (*ExtensionCollectorAdapter) RedisCommand

func (a *ExtensionCollectorAdapter) RedisCommand(command string, err error)

func (*ExtensionCollectorAdapter) RedisConnections

func (a *ExtensionCollectorAdapter) RedisConnections(count int)

func (*ExtensionCollectorAdapter) SearchIndex

func (a *ExtensionCollectorAdapter) SearchIndex(engine, operation string)

func (*ExtensionCollectorAdapter) SearchQuery

func (a *ExtensionCollectorAdapter) SearchQuery(engine string, err error)

type HealthChecker

type HealthChecker interface {
	Check(ctx context.Context) error
	Name() string
}

HealthChecker interface for health checking

type HealthMonitor

type HealthMonitor struct {
	// contains filtered or unexported fields
}

HealthMonitor monitors data layer component health

func NewHealthMonitor

func NewHealthMonitor(collector Collector) *HealthMonitor

NewHealthMonitor creates a new health monitor

func (*HealthMonitor) CheckAll

func (h *HealthMonitor) CheckAll(ctx context.Context) map[string]bool

CheckAll performs health check on all registered components

func (*HealthMonitor) CheckComponent

func (h *HealthMonitor) CheckComponent(ctx context.Context, name string) bool

CheckComponent checks a specific component

func (*HealthMonitor) RegisterComponent

func (h *HealthMonitor) RegisterComponent(checker HealthChecker)

RegisterComponent registers a component for health monitoring

type Labels

type Labels map[string]string

Labels for metric categorization

type MemoryStorage

type MemoryStorage struct {
	// contains filtered or unexported fields
}

MemoryStorage stores metrics in memory

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

NewMemoryStorage creates a new memory storage

func (*MemoryStorage) Close

func (m *MemoryStorage) Close() error

Close closes the memory storage

func (*MemoryStorage) Query

func (m *MemoryStorage) Query(query QueryRequest) ([]Metric, error)

Query queries metrics from memory

func (*MemoryStorage) Store

func (m *MemoryStorage) Store(metrics []Metric) error

Store stores metrics in memory

type Metric

type Metric struct {
	Type      string    `json:"type"`
	Value     int64     `json:"value"`
	Labels    Labels    `json:"labels"`
	Timestamp time.Time `json:"timestamp"`
}

Metric represents a data layer metric

type NoOpCollector

type NoOpCollector struct{}

NoOpCollector implements Collector with no-op methods

func (NoOpCollector) DBConnections

func (NoOpCollector) DBConnections(int)

func (NoOpCollector) DBQuery

func (NoOpCollector) DBQuery(time.Duration, error)

func (NoOpCollector) DBTransaction

func (NoOpCollector) DBTransaction(error)

func (NoOpCollector) HealthCheck

func (NoOpCollector) HealthCheck(string, bool)

func (NoOpCollector) MQConsume

func (NoOpCollector) MQConsume(string, error)

func (NoOpCollector) MQPublish

func (NoOpCollector) MQPublish(string, error)

func (NoOpCollector) MongoOperation

func (NoOpCollector) MongoOperation(string, error)

func (NoOpCollector) RedisCommand

func (NoOpCollector) RedisCommand(string, error)

func (NoOpCollector) RedisConnections

func (NoOpCollector) RedisConnections(int)

func (NoOpCollector) SearchIndex

func (NoOpCollector) SearchIndex(string, string)

func (NoOpCollector) SearchQuery

func (NoOpCollector) SearchQuery(string, error)

type QueryRequest

type QueryRequest struct {
	Type      string    `json:"type"`
	StartTime time.Time `json:"start_time"`
	EndTime   time.Time `json:"end_time"`
	Labels    Labels    `json:"labels"`
	Limit     int       `json:"limit"`
}

QueryRequest for querying metrics

type RedisStorage

type RedisStorage struct {
	// contains filtered or unexported fields
}

RedisStorage stores metrics in Redis

func NewRedisStorage

func NewRedisStorage(client *redis.Client, keyPrefix string, retention time.Duration) *RedisStorage

NewRedisStorage creates a new Redis storage

func (*RedisStorage) Close

func (r *RedisStorage) Close() error

Close closes the Redis storage

func (*RedisStorage) Query

func (r *RedisStorage) Query(query QueryRequest) ([]Metric, error)

Query queries metrics from Redis

func (*RedisStorage) Store

func (r *RedisStorage) Store(metrics []Metric) error

Store stores metrics in Redis

type Storage

type Storage interface {
	Store(metrics []Metric) error
	Query(query QueryRequest) ([]Metric, error)
	Close() error
}

Storage interface for metrics persistence

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL