package metrics import ( "time" "github.com/prometheus/client_golang/prometheus" ) var ( httpRequestDuration = prometheus.NewHistogramVec( prometheus.HistogramOpts{ Name: "http_request_duration_seconds", Help: "HTTP request duration in seconds", }, []string{"method", "endpoint", "status_code"}, ) dbQueryDuration = prometheus.NewHistogramVec( prometheus.HistogramOpts{ Name: "db_query_duration_seconds", Help: "Database query duration in seconds", }, []string{"operation"}, ) batchInsertRows = prometheus.NewHistogram( prometheus.HistogramOpts{ Name: "batch_insert_rows", Help: "Number of rows inserted per batch", }, ) cacheHits = prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "cache_hits_total", Help: "Total number of cache hits", }, []string{"key"}, ) ) func init() { prometheus.MustRegister(httpRequestDuration, dbQueryDuration, batchInsertRows, cacheHits) } func RecordHTTPRequest(method, endpoint, statusCode string, duration time.Duration) { httpRequestDuration.WithLabelValues(method, endpoint, statusCode).Observe(duration.Seconds()) } func RecordDatabaseQuery(operation string, duration time.Duration) { dbQueryDuration.WithLabelValues(operation).Observe(duration.Seconds()) } func RecordBatchInsert(rowCount int, duration time.Duration) { batchInsertRows.Observe(float64(rowCount)) } func RecordCacheHit(key string, duration time.Duration) { cacheHits.WithLabelValues(key).Inc() }