mirror of
https://github.com/wgh136/nysoure.git
synced 2025-12-16 15:51:14 +00:00
feat: prometheus
This commit is contained in:
52
server/stat/stat.go
Normal file
52
server/stat/stat.go
Normal file
@@ -0,0 +1,52 @@
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user