mirror of
https://github.com/zhengkai/orca.git
synced 2026-02-13 03:02:25 +08:00
up
This commit is contained in:
26
server/src/metrics/alias.go
Normal file
26
server/src/metrics/alias.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package metrics
|
||||
|
||||
import "github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
func newCounter(name, help string) prometheus.Counter {
|
||||
return prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Name: name,
|
||||
Help: help,
|
||||
},
|
||||
)
|
||||
}
|
||||
func newSummary(name, help string) prometheus.Summary {
|
||||
return prometheus.NewSummary(prometheus.SummaryOpts{
|
||||
Name: name,
|
||||
Help: help,
|
||||
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
|
||||
})
|
||||
}
|
||||
|
||||
func newGauge(name, help string) prometheus.Gauge {
|
||||
return prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Name: name,
|
||||
Help: help,
|
||||
})
|
||||
}
|
||||
37
server/src/metrics/http.go
Normal file
37
server/src/metrics/http.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
reqCount = newCounter(`orca_req_count`, `HTTP 请求次数`)
|
||||
reqFailCount = newCounter(`orca_req_fail_count`, `无法响应的 HTTP 请求数`)
|
||||
reqBytes = newCounter(`orca_req_bytes`, `文件总上传量`)
|
||||
errorCount = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: `orca_error_code`,
|
||||
Help: `API 返回报错`,
|
||||
},
|
||||
[]string{`code`},
|
||||
)
|
||||
)
|
||||
|
||||
// ReqFailCount ...
|
||||
func ReqFailCount() {
|
||||
reqFailCount.Inc()
|
||||
}
|
||||
|
||||
// ReqBytes ...
|
||||
func ReqBytes(n int) {
|
||||
reqCount.Inc()
|
||||
reqBytes.Add(float64(n))
|
||||
}
|
||||
|
||||
// ErrorCount ...
|
||||
func ErrorCount(code int32) {
|
||||
c := strconv.Itoa(int(code))
|
||||
errorCount.WithLabelValues(c).Inc()
|
||||
}
|
||||
10
server/src/metrics/init.go
Normal file
10
server/src/metrics/init.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package metrics
|
||||
|
||||
import "github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(reqCount)
|
||||
prometheus.MustRegister(reqFailCount)
|
||||
prometheus.MustRegister(reqBytes)
|
||||
prometheus.MustRegister(errorCount)
|
||||
}
|
||||
Reference in New Issue
Block a user