Skip to content

Commit

Permalink
支持 Prometheus metrics 的内容输出格式。
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxiaohui34 committed Sep 15, 2023
1 parent ccb2ff0 commit d82bd2a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions http_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ func (rest *HttpRestProvider) register(web HttpURL, handlerList []HandlerFunc) {
response = results
}
v, _ = json.Marshal(response)
// it works when importing promehttp handler for /metrics.
if web.Uri == "/metrics" {
str := string(v)
str = strings.ReplaceAll(str, "\\\"", "\"")
str = strings.ReplaceAll(str, "\\n", "\r\n")
str = strings.ReplaceAll(str, "\"", "")
fmt.Fprint(w, str)
return
}
w.Write(v)
})
}

0 comments on commit d82bd2a

Please sign in to comment.