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

Function ExampleNewConstHistogram

prometheus/examples_test.go:463–488  ·  prometheus/examples_test.go::ExampleNewConstHistogram
()

Source from the content-addressed store, hash-verified

461}
462
463func ExampleNewConstHistogram() {
464 desc := prometheus.NewDesc(
465 "http_request_duration_seconds",
466 "A histogram of the HTTP request durations.",
467 []string{"code", "method"},
468 prometheus.Labels{"owner": "example"},
469 )
470
471 // Create a constant histogram from values we got from a 3rd party telemetry system.
472 h := prometheus.MustNewConstHistogram(
473 desc,
474 4711, 403.34,
475 map[float64]uint64{25: 121, 50: 2403, 100: 3221, 200: 4233},
476 "200", "get",
477 )
478
479 // Just for demonstration, let's check the state of the histogram by
480 // (ab)using its Write method (which is usually only used by Prometheus
481 // internally).
482 metric := &dto.Metric{}
483 h.Write(metric)
484 fmt.Println(toNormalizedJSON(metric))
485
486 // Output:
487 // {"label":[{"name":"code","value":"200"},{"name":"method","value":"get"},{"name":"owner","value":"example"}],"histogram":{"sampleCount":"4711","sampleSum":403.34,"bucket":[{"cumulativeCount":"121","upperBound":25},{"cumulativeCount":"2403","upperBound":50},{"cumulativeCount":"3221","upperBound":100},{"cumulativeCount":"4233","upperBound":200}]}}
488}
489
490func ExampleNewConstHistogramWithCreatedTimestamp() {
491 desc := prometheus.NewDesc(

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected