MCPcopy Create free account
hub / github.com/couchbase/cbft / ServeHTTP

Method ServeHTTP

prometheus.go:201–229  ·  view source on GitHub ↗
(w http.ResponseWriter,
	req *http.Request)

Source from the content-addressed store, hash-verified

199}
200
201func (h *PrometheusMetricsHandler) ServeHTTP(w http.ResponseWriter,
202 req *http.Request) {
203 initNsServerCaching(h.mgr)
204
205 rd := getRecentInfo()
206 if rd.err != nil {
207 rest.ShowError(w, req, fmt.Sprintf("could not retrieve defs: %v", rd.err),
208 http.StatusInternalServerError)
209 return
210 }
211
212 w.Header().Set("Cache-Control", "no-cache")
213 w.Header().Set("Content-Type", "text/plain; charset=utf-8")
214
215 stats := gatherTopLevelStats(rd)
216 for k, v := range stats {
217 b, err := json.Marshal(v)
218 if err != nil {
219 rest.ShowError(w, req, fmt.Sprintf("json marshal err: %v", err),
220 http.StatusInternalServerError)
221 return
222 }
223 if typ, ok := prometheusStats[k]; ok {
224 w.Write([]byte(fmt.Sprintf("# TYPE fts_%s %s\n", k, typ)))
225 w.Write(append([]byte("fts_"+k+" "), b...))
226 w.Write(bline)
227 }
228 }
229}

Callers

nothing calls this directly

Calls 6

initNsServerCachingFunction · 0.85
getRecentInfoFunction · 0.85
gatherTopLevelStatsFunction · 0.85
HeaderMethod · 0.80
MarshalMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected