| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| package usage |
|
|
| import ( |
| "fmt" |
| "strings" |
|
|
| "github.com/prometheus/client_golang/prometheus" |
| "github.com/prometheus/client_golang/prometheus/promauto" |
| ) |
|
|
| type Metrics struct { |
| |
| OperationTotal *prometheus.CounterVec |
| OperationLatency *prometheus.HistogramVec |
|
|
| |
| ResourceCount *prometheus.GaugeVec |
| UploadedFileSize prometheus.Gauge |
| } |
|
|
| func NewMetrics(reg prometheus.Registerer, moduleName string) *Metrics { |
| moduleName = fmt.Sprintf("weaviate_%s", strings.ReplaceAll(strings.ToLower(moduleName), "-", "_")) |
| return &Metrics{ |
| OperationTotal: promauto.With(reg).NewCounterVec( |
| prometheus.CounterOpts{ |
| Name: moduleName + "_operations_total", |
| Help: "Total number of " + moduleName + " operations", |
| }, |
| []string{"operation", "status"}, |
| ), |
| OperationLatency: prometheus.NewHistogramVec( |
| prometheus.HistogramOpts{ |
| Name: moduleName + "_operation_latency_seconds", |
| Help: "Latency of usage operations in seconds", |
| Buckets: prometheus.DefBuckets, |
| }, |
| []string{"operation"}, |
| ), |
| ResourceCount: promauto.With(reg).NewGaugeVec( |
| prometheus.GaugeOpts{ |
| Name: moduleName + "_resource_count", |
| Help: "Number of resources tracked by " + moduleName, |
| }, |
| []string{"resource_type"}, |
| ), |
| UploadedFileSize: promauto.With(reg).NewGauge( |
| prometheus.GaugeOpts{ |
| Name: moduleName + "_uploaded_file_size_bytes", |
| Help: "Size of the last uploaded usage file in bytes", |
| }, |
| ), |
| } |
| } |
|
|