mirror of
https://github.com/wgh136/nysoure.git
synced 2025-12-16 07:51:14 +00:00
53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
package stat
|
|
|
|
import (
|
|
prom "github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
var (
|
|
RequestCount = prom.NewCounterVec(
|
|
prom.CounterOpts{
|
|
Name: "http_requests_total",
|
|
Help: "Total number of HTTP requests",
|
|
},
|
|
[]string{"path", "status"},
|
|
)
|
|
RegisterCount = prom.NewCounterVec(
|
|
prom.CounterOpts{
|
|
Name: "register_requests_total",
|
|
Help: "Total number of registration requests",
|
|
},
|
|
[]string{},
|
|
)
|
|
DownloadCount = prom.NewCounterVec(
|
|
prom.CounterOpts{
|
|
Name: "download_requests_total",
|
|
Help: "Total number of download requests",
|
|
},
|
|
[]string{},
|
|
)
|
|
)
|
|
|
|
func init() {
|
|
prom.MustRegister(RequestCount)
|
|
prom.MustRegister(RegisterCount)
|
|
prom.MustRegister(DownloadCount)
|
|
}
|
|
|
|
func RecordRequest(method, path string, status string) {
|
|
if status == "404" {
|
|
// Aggregate all 404s under a single label
|
|
path = "NOT_FOUND"
|
|
}
|
|
path = method + " " + path
|
|
RequestCount.WithLabelValues(path, status).Inc()
|
|
}
|
|
|
|
func RecordRegister() {
|
|
RegisterCount.WithLabelValues().Inc()
|
|
}
|
|
|
|
func RecordDownload() {
|
|
DownloadCount.WithLabelValues().Inc()
|
|
}
|