This commit is contained in:
Zheng Kai
2023-06-06 17:56:14 +08:00
parent 894b62bf29
commit 210c23b633
3 changed files with 25 additions and 4 deletions

View File

@@ -12,6 +12,9 @@ var errSkip = errors.New(`skip`)
// WebHandle ...
func (c *Core) ServeHTTP(w http.ResponseWriter, r *http.Request) {
metrics.ReqConcurrentInc()
defer metrics.ReqConcurrentDec()
p, err := req(w, r)
if err != nil {
if err != errSkip {

View File

@@ -10,6 +10,12 @@ var (
reqCount = newCounter(`orca_req_count`, `HTTP 请求次数`)
reqFailCount = newCounter(`orca_req_fail_count`, `无法响应的 HTTP 请求数`)
reqBytes = newCounter(`orca_req_bytes`, `文件总上传量`)
reqConcurrent = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: `orca_req_concurrent`,
Help: `当前并发请求数`,
},
)
errorCount = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: `orca_error_code`,
@@ -24,6 +30,16 @@ func ReqFailCount() {
reqFailCount.Inc()
}
// ReqConcurrentInc ...
func ReqConcurrentInc() {
reqConcurrent.Inc()
}
// ReqConcurrentDec ...
func ReqConcurrentDec() {
reqConcurrent.Dec()
}
// ReqBytes ...
func ReqBytes(n int) {
reqCount.Inc()

View File

@@ -6,6 +6,8 @@ func init() {
prometheus.MustRegister(reqCount)
prometheus.MustRegister(reqFailCount)
prometheus.MustRegister(reqBytes)
prometheus.MustRegister(reqConcurrent)
prometheus.MustRegister(errorCount)
prometheus.MustRegister(rspBytes)