mirror of
https://github.com/zhengkai/orca.git
synced 2026-02-04 15:12:26 +08:00
feat: metrics api cost time
This commit is contained in:
@@ -37,7 +37,10 @@ func (pr *row) fetchRemote() (ab []byte, err error) {
|
|||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
// Timeout: 30 * time.Second,
|
// Timeout: 30 * time.Second,
|
||||||
}
|
}
|
||||||
|
t := time.Now()
|
||||||
rsp, err := client.Do(req)
|
rsp, err := client.Do(req)
|
||||||
|
costMs := uint32(time.Since(t) / time.Millisecond)
|
||||||
|
metrics.OpenAITime(costMs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(b, "client.Do fail: %s\n", err.Error())
|
fmt.Fprintf(b, "client.Do fail: %s\n", err.Error())
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -21,4 +21,7 @@ func init() {
|
|||||||
|
|
||||||
prometheus.MustRegister(limitReq)
|
prometheus.MustRegister(limitReq)
|
||||||
prometheus.MustRegister(limitToken)
|
prometheus.MustRegister(limitToken)
|
||||||
|
|
||||||
|
prometheus.MustRegister(openaiTime)
|
||||||
|
prometheus.MustRegister(vaTime)
|
||||||
}
|
}
|
||||||
|
|||||||
10
server/src/metrics/openai.go
Normal file
10
server/src/metrics/openai.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package metrics
|
||||||
|
|
||||||
|
var (
|
||||||
|
openaiTime = newSummary(`orca_openai_time`, `openai api time`)
|
||||||
|
)
|
||||||
|
|
||||||
|
// OpenAITime ...
|
||||||
|
func OpenAITime(ms uint32) {
|
||||||
|
openaiTime.Observe(float64(ms))
|
||||||
|
}
|
||||||
10
server/src/metrics/va.go
Normal file
10
server/src/metrics/va.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package metrics
|
||||||
|
|
||||||
|
var (
|
||||||
|
vaTime = newSummary(`orca_va_time`, `vertexai api time`)
|
||||||
|
)
|
||||||
|
|
||||||
|
// VaTime ...
|
||||||
|
func VaTime(ms uint32) {
|
||||||
|
vaTime.Observe(float64(ms))
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"project/metrics"
|
||||||
"project/pb"
|
"project/pb"
|
||||||
"project/util"
|
"project/util"
|
||||||
"time"
|
"time"
|
||||||
@@ -168,6 +169,7 @@ func loadChat(k chatKey) (*ChatRsp, error) {
|
|||||||
Raw: rsp,
|
Raw: rsp,
|
||||||
CostMs: uint32(time.Since(t) / time.Millisecond),
|
CostMs: uint32(time.Since(t) / time.Millisecond),
|
||||||
}
|
}
|
||||||
|
metrics.VaTime(r.CostMs)
|
||||||
|
|
||||||
answer := &pb.VaChatRsp{}
|
answer := &pb.VaChatRsp{}
|
||||||
answer.Content, err = getChatVal(rsp)
|
answer.Content, err = getChatVal(rsp)
|
||||||
|
|||||||
Reference in New Issue
Block a user