monitoring

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Function execution metrics
	FunctionExecutionCount = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "service_layer_function_executions_total",
			Help: "The total number of function executions",
		},
		[]string{"function_id", "user_id", "status"},
	)

	FunctionExecutionDuration = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "service_layer_function_execution_duration_seconds",
			Help:    "Function execution duration in seconds",
			Buckets: prometheus.ExponentialBuckets(0.001, 2, 15),
		},
		[]string{"function_id", "user_id"},
	)

	FunctionMemoryUsage = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "service_layer_function_memory_usage_bytes",
			Help:    "Function memory usage in bytes",
			Buckets: prometheus.ExponentialBuckets(1024*1024, 2, 10),
		},
		[]string{"function_id", "user_id"},
	)

	// Secret management metrics
	SecretOperationsCount = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "service_layer_secret_operations_total",
			Help: "The total number of secret operations",
		},
		[]string{"user_id", "operation", "status"},
	)

	SecretCount = promauto.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "service_layer_secrets_count",
			Help: "The number of secrets stored per user",
		},
		[]string{"user_id"},
	)

	// TEE metrics
	TEEAttestationCount = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "service_layer_tee_attestations_total",
			Help: "The total number of TEE attestation operations",
		},
		[]string{"status"},
	)

	TEEAttestationDuration = promauto.NewHistogram(
		prometheus.HistogramOpts{
			Name:    "service_layer_tee_attestation_duration_seconds",
			Help:    "TEE attestation duration in seconds",
			Buckets: prometheus.ExponentialBuckets(0.01, 2, 10),
		},
	)

	// API metrics
	APIRequestsCount = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "service_layer_api_requests_total",
			Help: "The total number of API requests",
		},
		[]string{"path", "method", "status"},
	)

	APIRequestDuration = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "service_layer_api_request_duration_seconds",
			Help:    "API request duration in seconds",
			Buckets: prometheus.ExponentialBuckets(0.001, 2, 15),
		},
		[]string{"path", "method"},
	)

	// Health metrics
	SystemUptime = promauto.NewCounter(
		prometheus.CounterOpts{
			Name: "service_layer_uptime_seconds_total",
			Help: "The total uptime of the service layer in seconds",
		},
	)

	DatabaseConnections = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: "service_layer_database_connections",
			Help: "The number of active database connections",
		},
	)

	BlockchainConnections = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: "service_layer_blockchain_connections",
			Help: "The number of active blockchain node connections",
		},
	)

	// Gas bank metrics
	GasBankBalance = promauto.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "service_layer_gas_bank_balance",
			Help: "The current balance of the gas bank",
		},
		[]string{"asset"},
	)

	GasBankTransactionsCount = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "service_layer_gas_bank_transactions_total",
			Help: "The total number of gas bank transactions",
		},
		[]string{"operation", "status"},
	)

	// Error metrics
	ErrorsCount = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "service_layer_errors_total",
			Help: "The total number of errors",
		},
		[]string{"component", "error_type"},
	)

	// System resource metrics
	SystemCPUUsage = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: "service_layer_system_cpu_usage",
			Help: "The CPU usage of the service layer",
		},
	)

	SystemMemoryUsage = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: "service_layer_system_memory_bytes",
			Help: "The memory usage of the service layer in bytes",
		},
	)

	SystemGoroutines = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: "service_layer_goroutines",
			Help: "The number of goroutines",
		},
	)
)

Functions

func RecordAPIRequest

func RecordAPIRequest(path, method, status string, durationSeconds float64)

RecordAPIRequest records metrics for an API request

func RecordError

func RecordError(component, errorType string)

RecordError records an error

func RecordFunctionExecution

func RecordFunctionExecution(functionID, userID string, durationSeconds float64, memoryBytes float64, status string)

RecordFunctionExecution records metrics for a function execution

func RecordGasBankTransaction

func RecordGasBankTransaction(operation, status string)

RecordGasBankTransaction records a gas bank transaction

func RecordSecretOperation

func RecordSecretOperation(userID string, operation string, status string)

RecordSecretOperation records metrics for a secret operation

func RecordTEEAttestation

func RecordTEEAttestation(durationSeconds float64, status string)

RecordTEEAttestation records metrics for a TEE attestation

func UpdateBlockchainConnections

func UpdateBlockchainConnections(connections int)

UpdateBlockchainConnections updates the active blockchain connections metric

func UpdateDatabaseConnections

func UpdateDatabaseConnections(connections int)

UpdateDatabaseConnections updates the active database connections metric

func UpdateGasBankBalance

func UpdateGasBankBalance(asset string, balance float64)

UpdateGasBankBalance updates the gas bank balance

func UpdateSecretCount

func UpdateSecretCount(userID string, count int)

UpdateSecretCount updates the count of secrets for a user

func UpdateSystemMetrics

func UpdateSystemMetrics(cpuUsage, memoryBytes float64, goroutines int)

UpdateSystemMetrics updates system resource metrics

Types

type MetricsCollector

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

MetricsCollector regularly collects and updates system metrics like memory usage, goroutines count, and other process stats. This should be a runnable service that the main app can start.

func NewMetricsCollector

func NewMetricsCollector(cfg *config.MonitoringConfig, log *logger.Logger) (*MetricsCollector, error)

NewMetricsCollector creates a new metrics collector

func (*MetricsCollector) Start

func (mc *MetricsCollector) Start() error

Start begins collecting metrics

func (*MetricsCollector) Stop

func (mc *MetricsCollector) Stop()

Stop halts the metrics collection

type Service

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

Service provides a centralized way to manage monitoring components

func NewService

func NewService(cfg *config.MonitoringConfig, log *logger.Logger) (*Service, error)

NewService creates a new monitoring service

func (*Service) Metrics

func (s *Service) Metrics() *MetricsCollector

Metrics provides access to the metrics collector

func (*Service) Registry

func (s *Service) Registry() *prometheus.Registry

Registry returns the Prometheus registry for registering additional metrics

func (*Service) Start

func (s *Service) Start() error

Start initializes and starts all monitoring components

func (*Service) Stop

func (s *Service) Stop()

Stop gracefully shuts down all monitoring components

Jump to

Keyboard shortcuts

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