mirror of
https://github.com/zhengkai/orca.git
synced 2026-02-04 16:22:26 +08:00
refactor: metrics
This commit is contained in:
@@ -2,17 +2,19 @@ package metrics
|
||||
|
||||
import "github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
var baseName = `orca_`
|
||||
|
||||
func newCounter(name, help string) prometheus.Counter {
|
||||
return prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Name: name,
|
||||
Name: baseName + name,
|
||||
Help: help,
|
||||
},
|
||||
)
|
||||
}
|
||||
func newSummary(name, help string) prometheus.Summary {
|
||||
return prometheus.NewSummary(prometheus.SummaryOpts{
|
||||
Name: name,
|
||||
Name: baseName + name,
|
||||
Help: help,
|
||||
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
|
||||
})
|
||||
@@ -20,7 +22,27 @@ func newSummary(name, help string) prometheus.Summary {
|
||||
|
||||
func newGauge(name, help string) prometheus.Gauge {
|
||||
return prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Name: name,
|
||||
Name: baseName + name,
|
||||
Help: help,
|
||||
})
|
||||
}
|
||||
|
||||
func newCounterVec(name, help, field string) *prometheus.CounterVec {
|
||||
return prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: baseName + name,
|
||||
Help: help,
|
||||
},
|
||||
[]string{field},
|
||||
)
|
||||
}
|
||||
|
||||
func newGaugeVec(name, help, field string) *prometheus.GaugeVec {
|
||||
return prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: baseName + name,
|
||||
Help: help,
|
||||
},
|
||||
[]string{field},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,27 +2,14 @@ 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`, `文件总上传量`)
|
||||
reqConcurrent = prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Name: `orca_req_concurrent`,
|
||||
Help: `当前并发请求数`,
|
||||
},
|
||||
)
|
||||
errorCount = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: `orca_error_code`,
|
||||
Help: `API 返回报错`,
|
||||
},
|
||||
[]string{`code`},
|
||||
)
|
||||
reqCount = newCounter(`req_count`, `HTTP 请求次数`)
|
||||
reqFailCount = newCounter(`req_fail_count`, `无法响应的 HTTP 请求数`)
|
||||
reqBytes = newCounter(`req_bytes`, `文件总上传量`)
|
||||
reqConcurrent = newGauge(`req_concurrent`, `当前并发请求数`)
|
||||
errorCount = newCounterVec(`error_code`, `API 返回报错`, `code`)
|
||||
)
|
||||
|
||||
// ReqFailCount ...
|
||||
|
||||
@@ -4,24 +4,18 @@ import (
|
||||
"net/http"
|
||||
"project/zj"
|
||||
"strconv"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
limitReq = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: `orca_limit_req_by_model`,
|
||||
Help: `limit request by model`,
|
||||
},
|
||||
[]string{`model`},
|
||||
limitReq = newGaugeVec(
|
||||
`limit_req_by_model`,
|
||||
`limit request by model`,
|
||||
`model`,
|
||||
)
|
||||
limitToken = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: `orca_limit_token_by_model`,
|
||||
Help: `limit token by model`,
|
||||
},
|
||||
[]string{`model`},
|
||||
limitToken = newGaugeVec(
|
||||
`limit_token_by_model`,
|
||||
`limit token by model`,
|
||||
`model`,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package metrics
|
||||
|
||||
var (
|
||||
openaiTime = newSummary(`orca_openai_time`, `openai api time`)
|
||||
openaiTime = newSummary(`openai_time`, `openai api time`)
|
||||
)
|
||||
|
||||
// OpenAITime ...
|
||||
|
||||
@@ -1,35 +1,25 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
rspBytes = newCounter(`orca_rsp_bytes`, `rsp bytes`)
|
||||
rspPromptTokenCount = newCounter(`orca_rsp_prompt_token`, `prompt token`)
|
||||
rspTokenCount = newCounter(`orca_rsp_token`, `token`)
|
||||
rspTokenCachedCount = newCounter(`orca_rsp_token_cached`, `token cached`)
|
||||
rspJSONFailCount = newCounter(`orca_rsp_json_fail`, `json fail`)
|
||||
rspTokenByModel = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: `orca_token_by_model`,
|
||||
Help: `token by model`,
|
||||
},
|
||||
[]string{`model`},
|
||||
rspBytes = newCounter(`rsp_bytes`, `rsp bytes`)
|
||||
rspPromptTokenCount = newCounter(`rsp_prompt_token`, `prompt token`)
|
||||
rspTokenCount = newCounter(`rsp_token`, `token`)
|
||||
rspTokenCachedCount = newCounter(`rsp_token_cached`, `token cached`)
|
||||
rspJSONFailCount = newCounter(`rsp_json_fail`, `json fail`)
|
||||
rspTokenByModel = newCounterVec(
|
||||
`token_by_model`,
|
||||
`token by model`,
|
||||
`model`,
|
||||
)
|
||||
rspTokenByKey = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: `orca_token_by_key`,
|
||||
Help: `openai key`,
|
||||
},
|
||||
[]string{`key`},
|
||||
rspTokenByKey = newCounterVec(
|
||||
`token_by_key`,
|
||||
`openai key`,
|
||||
`key`,
|
||||
)
|
||||
rspTokenByIP = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: `orca_token_by_ip`,
|
||||
Help: `token by ip`,
|
||||
},
|
||||
[]string{`ip`},
|
||||
rspTokenByIP = newCounterVec(
|
||||
`token_by_ip`,
|
||||
`token by ip`,
|
||||
`ip`,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package metrics
|
||||
|
||||
var (
|
||||
vaTime = newSummary(`orca_va_time`, `vertexai api time`)
|
||||
vaTime = newSummary(`va_time`, `vertexai api time`)
|
||||
)
|
||||
|
||||
// VaTime ...
|
||||
|
||||
Reference in New Issue
Block a user