()
| 461 | } |
| 462 | |
| 463 | func 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 | |
| 490 | func ExampleNewConstHistogramWithCreatedTimestamp() { |
| 491 | desc := prometheus.NewDesc( |
nothing calls this directly
no test coverage detected