feat: metrics api cost time

This commit is contained in:
Zheng Kai
2023-09-04 16:42:50 +08:00
parent fb96717e94
commit b187d44ee0
5 changed files with 28 additions and 0 deletions

View File

@@ -37,7 +37,10 @@ func (pr *row) fetchRemote() (ab []byte, err error) {
client := &http.Client{
// Timeout: 30 * time.Second,
}
t := time.Now()
rsp, err := client.Do(req)
costMs := uint32(time.Since(t) / time.Millisecond)
metrics.OpenAITime(costMs)
if err != nil {
fmt.Fprintf(b, "client.Do fail: %s\n", err.Error())
return

View File

@@ -21,4 +21,7 @@ func init() {
prometheus.MustRegister(limitReq)
prometheus.MustRegister(limitToken)
prometheus.MustRegister(openaiTime)
prometheus.MustRegister(vaTime)
}

View 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
View 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))
}

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"project/metrics"
"project/pb"
"project/util"
"time"
@@ -168,6 +169,7 @@ func loadChat(k chatKey) (*ChatRsp, error) {
Raw: rsp,
CostMs: uint32(time.Since(t) / time.Millisecond),
}
metrics.VaTime(r.CostMs)
answer := &pb.VaChatRsp{}
answer.Content, err = getChatVal(rsp)