Skip to content

Commit

Permalink
增加oss上传度量
Browse files Browse the repository at this point in the history
  • Loading branch information
曹鑫 committed Sep 28, 2020
1 parent 36b92c3 commit fda026a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions api/oss/oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func Route(engine *gin.Engine) {
"code": http.StatusBadRequest,
"message": constant.InvalidArgument,
})
metrics.UploadCount.WithLabelValues("failure", "bad_request").Inc()
return
}
files := form.File["file[]"]
Expand All @@ -61,12 +62,14 @@ func Route(engine *gin.Engine) {
if err != nil {
items[i].Status = false
logger.L.Error(err)
metrics.UploadCount.WithLabelValues("failure", "server_error").Inc()
continue
}
val, err := ioutil.ReadAll(f)
if err != nil {
items[i].Status = false
logger.L.Error(err)
metrics.UploadCount.WithLabelValues("failure", "server_error").Inc()
continue
}
h := md5.New()
Expand All @@ -79,8 +82,10 @@ func Route(engine *gin.Engine) {
if err != nil {
items[i].Status = false
logger.L.Error(err)
metrics.UploadCount.WithLabelValues("failure", "server_error").Inc()
continue
}
metrics.UploadCount.WithLabelValues("success", "disk").Inc()
items[i].Oid = string(key)
}
c.JSON(http.StatusOK,
Expand Down
9 changes: 7 additions & 2 deletions component/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ var (
ObjectCurrentCount prometheus.Gauge
PutCount *prometheus.GaugeVec
GetCount *prometheus.GaugeVec
DownloadCount *prometheus.GaugeVec
DownloadCount *prometheus.GaugeVec
UploadCount *prometheus.GaugeVec
)

func init() {
Expand All @@ -28,8 +29,12 @@ func init() {
}, []string{"status", "source"})
DownloadCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "oss_download_count",
Help: "下载操作数",
Help: "download操作数",
}, []string{"status", "source"})
UploadCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "oss_upload_count",
Help: "upload操作数",
}, []string{"status"})
prometheus.MustRegister(ObjectCurrentCount, PutCount, GetCount)
}

Expand Down

0 comments on commit fda026a

Please sign in to comment.