MCPcopy
hub / github.com/prometheus/client_golang / ExampleNewConstSummary

Function ExampleNewConstSummary

prometheus/examples_test.go:383–408  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

381}
382
383func ExampleNewConstSummary() {
384 desc := prometheus.NewDesc(
385 "http_request_duration_seconds",
386 "A summary of the HTTP request durations.",
387 []string{"code", "method"},
388 prometheus.Labels{"owner": "example"},
389 )
390
391 // Create a constant summary from values we got from a 3rd party telemetry system.
392 s := prometheus.MustNewConstSummary(
393 desc,
394 4711, 403.34,
395 map[float64]float64{0.5: 42.3, 0.9: 323.3},
396 "200", "get",
397 )
398
399 // Just for demonstration, let's check the state of the summary by
400 // (ab)using its Write method (which is usually only used by Prometheus
401 // internally).
402 metric := &dto.Metric{}
403 s.Write(metric)
404 fmt.Println(toNormalizedJSON(metric))
405
406 // Output:
407 // {"label":[{"name":"code","value":"200"},{"name":"method","value":"get"},{"name":"owner","value":"example"}],"summary":{"sampleCount":"4711","sampleSum":403.34,"quantile":[{"quantile":0.5,"value":42.3},{"quantile":0.9,"value":323.3}]}}
408}
409
410func ExampleNewConstSummaryWithCreatedTimestamp() {
411 desc := prometheus.NewDesc(

Callers

nothing calls this directly

Calls 5

NewDescFunction · 0.92
MustNewConstSummaryFunction · 0.92
toNormalizedJSONFunction · 0.85
WriteMethod · 0.65
PrintlnMethod · 0.65

Tested by

no test coverage detected