Documentation
¶
Index ¶
- func BusinessMetricsMiddleware(collector MetricsCollector, config *MetricsConfig) gin.HandlerFunc
- func MetricsHandler(collector MetricsCollector) gin.HandlerFunc
- func MetricsMiddleware(collector MetricsCollector, config *MetricsConfig) gin.HandlerFunc
- type BusinessEvent
- type InMemoryMetricsCollector
- func (imc *InMemoryMetricsCollector) GetStats() map[string]interface{}
- func (imc *InMemoryMetricsCollector) RecordBusinessEvent(eventType, tenantID string, metadata map[string]interface{})
- func (imc *InMemoryMetricsCollector) RecordCounter(name string, labels map[string]string, value float64)
- func (imc *InMemoryMetricsCollector) RecordError(errorType, tenantID, service string)
- func (imc *InMemoryMetricsCollector) RecordGauge(name string, labels map[string]string, value float64)
- func (imc *InMemoryMetricsCollector) RecordHTTPDuration(method, path string, duration time.Duration)
- func (imc *InMemoryMetricsCollector) RecordHTTPRequest(method, path, status string, duration time.Duration, tenantID string)
- func (imc *InMemoryMetricsCollector) RecordHTTPStatus(method, path, status string)
- func (imc *InMemoryMetricsCollector) RecordHistogram(name string, labels map[string]string, value float64)
- func (imc *InMemoryMetricsCollector) RecordSecurityThreatDetected(threatType, severity, tenantID, userID string)
- func (imc *InMemoryMetricsCollector) RecordSecurityValidationFailed(validationType, tenantID, reason string)
- type MetricsCollector
- type MetricsConfig
- type PrometheusExporter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BusinessMetricsMiddleware ¶
func BusinessMetricsMiddleware(collector MetricsCollector, config *MetricsConfig) gin.HandlerFunc
BusinessMetricsMiddleware middleware para métricas de negocio
func MetricsHandler ¶
func MetricsHandler(collector MetricsCollector) gin.HandlerFunc
MetricsHandler handler para exponer métricas
func MetricsMiddleware ¶
func MetricsMiddleware(collector MetricsCollector, config *MetricsConfig) gin.HandlerFunc
MetricsMiddleware middleware para recolección de métricas
Types ¶
type BusinessEvent ¶
type BusinessEvent struct {
Type string `json:"type"`
TenantID string `json:"tenant_id"`
Timestamp time.Time `json:"timestamp"`
Metadata map[string]interface{} `json:"metadata"`
}
BusinessEvent representa un evento de negocio
type InMemoryMetricsCollector ¶
type InMemoryMetricsCollector struct {
// contains filtered or unexported fields
}
InMemoryMetricsCollector implementación en memoria para desarrollo/testing
func NewInMemoryMetricsCollector ¶
func NewInMemoryMetricsCollector(config *MetricsConfig, logger *logrus.Logger) *InMemoryMetricsCollector
NewInMemoryMetricsCollector crea un nuevo recolector en memoria
func (*InMemoryMetricsCollector) GetStats ¶
func (imc *InMemoryMetricsCollector) GetStats() map[string]interface{}
GetStats retorna todas las estadísticas
func (*InMemoryMetricsCollector) RecordBusinessEvent ¶
func (imc *InMemoryMetricsCollector) RecordBusinessEvent(eventType, tenantID string, metadata map[string]interface{})
RecordBusinessEvent registra un evento de negocio
func (*InMemoryMetricsCollector) RecordCounter ¶
func (imc *InMemoryMetricsCollector) RecordCounter(name string, labels map[string]string, value float64)
RecordCounter registra un contador
func (*InMemoryMetricsCollector) RecordError ¶
func (imc *InMemoryMetricsCollector) RecordError(errorType, tenantID, service string)
RecordError registra un error
func (*InMemoryMetricsCollector) RecordGauge ¶
func (imc *InMemoryMetricsCollector) RecordGauge(name string, labels map[string]string, value float64)
RecordGauge registra un gauge
func (*InMemoryMetricsCollector) RecordHTTPDuration ¶
func (imc *InMemoryMetricsCollector) RecordHTTPDuration(method, path string, duration time.Duration)
RecordHTTPDuration registra la duración de una request HTTP
func (*InMemoryMetricsCollector) RecordHTTPRequest ¶
func (imc *InMemoryMetricsCollector) RecordHTTPRequest(method, path, status string, duration time.Duration, tenantID string)
RecordHTTPRequest registra una request HTTP
func (*InMemoryMetricsCollector) RecordHTTPStatus ¶
func (imc *InMemoryMetricsCollector) RecordHTTPStatus(method, path, status string)
RecordHTTPStatus registra el status code de una response HTTP
func (*InMemoryMetricsCollector) RecordHistogram ¶
func (imc *InMemoryMetricsCollector) RecordHistogram(name string, labels map[string]string, value float64)
RecordHistogram registra un histograma
func (*InMemoryMetricsCollector) RecordSecurityThreatDetected ¶
func (imc *InMemoryMetricsCollector) RecordSecurityThreatDetected(threatType, severity, tenantID, userID string)
RecordSecurityThreatDetected registra una amenaza de seguridad detectada
func (*InMemoryMetricsCollector) RecordSecurityValidationFailed ¶
func (imc *InMemoryMetricsCollector) RecordSecurityValidationFailed(validationType, tenantID, reason string)
RecordSecurityValidationFailed registra una validación de seguridad fallida
type MetricsCollector ¶
type MetricsCollector interface {
// HTTP metrics
RecordHTTPRequest(method, path, status string, duration time.Duration, tenantID string)
RecordHTTPDuration(method, path string, duration time.Duration)
RecordHTTPStatus(method, path, status string)
// Business metrics
RecordBusinessEvent(eventType, tenantID string, metadata map[string]interface{})
RecordCounter(name string, labels map[string]string, value float64)
RecordGauge(name string, labels map[string]string, value float64)
RecordHistogram(name string, labels map[string]string, value float64)
// Error metrics
RecordError(errorType, tenantID, service string)
RecordSecurityThreatDetected(threatType, severity, tenantID, userID string)
RecordSecurityValidationFailed(validationType, tenantID, reason string)
}
MetricsCollector interfaz para recolección de métricas
type MetricsConfig ¶
type MetricsConfig struct {
// Metric collection settings
EnableRequestMetrics bool
EnableResponseMetrics bool
EnableDurationMetrics bool
EnablePathMetrics bool
EnableMethodMetrics bool
EnableStatusMetrics bool
EnableTenantMetrics bool
// Path normalization
NormalizePaths bool
PathPatterns map[string]string // Regex patterns to normalize paths
// Filtering
SkipPaths []string
SkipMethods []string
// Buckets for histogram metrics
DurationBuckets []float64
// Business metrics
EnableBusinessMetrics bool
BusinessEventTypes []string
}
MetricsConfig configuración del middleware de métricas
func DefaultMetricsConfig ¶
func DefaultMetricsConfig() *MetricsConfig
DefaultMetricsConfig retorna configuración por defecto
type PrometheusExporter ¶
type PrometheusExporter struct {
// contains filtered or unexported fields
}
PrometheusExporter implementación para exportar a Prometheus Esta sería una implementación más completa en producción
func NewPrometheusExporter ¶
func NewPrometheusExporter(collector MetricsCollector, config *MetricsConfig, logger *logrus.Logger) *PrometheusExporter
NewPrometheusExporter crea un nuevo exportador de Prometheus
func (*PrometheusExporter) Handler ¶
func (pe *PrometheusExporter) Handler() gin.HandlerFunc
Handler retorna un handler para métricas de Prometheus