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