verification/internal/controllers/admin/prometheus/prometheus.go

55 lines
1.6 KiB
Go
Raw Normal View History

2024-12-09 20:51:26 +00:00
package prometheus
import (
"gitea.pena/PenaSide/verification/internal/controllers/admin/verification_admin"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
)
type Prometheus struct {
verificationAdmin *verification_admin.VerifyAdminController
metrics prometheusRegistry
}
type prometheusRegistry struct {
totalBytes prometheus.Counter // Общее количество загруженной памяти
totalTime prometheus.Counter // Общее затраченное время на 1 загрузку
totalUploads prometheus.Counter // Количество всего загрузок файлов
}
func NewPrometheus(verificationAdmin *verification_admin.VerifyAdminController) *Prometheus {
registry := prometheusRegistry{
totalBytes: prometheus.NewCounter(prometheus.CounterOpts{
Name: "s3_total_uploaded_bytes",
Help: "Total memory loaded in bytes to S3",
}),
totalTime: prometheus.NewCounter(prometheus.CounterOpts{
Name: "s3_total_upload_time_ns",
Help: "Total time spent downloading files to S3",
}),
totalUploads: prometheus.NewCounter(prometheus.CounterOpts{
Name: "s3_total_upload_count",
Help: "Number of total file downloads to S3",
}),
}
prometheus.MustRegister(
registry.totalBytes,
registry.totalTime,
registry.totalUploads,
)
return &Prometheus{
verificationAdmin: verificationAdmin,
metrics: registry,
}
}
func (receiver *Prometheus) Metrics(w http.ResponseWriter, r *http.Request) {
//receiver.updateMetrics()
handler := promhttp.Handler()
handler.ServeHTTP(w, r)
}