()
| 437 | } |
| 438 | |
| 439 | func ExampleHistogram() { |
| 440 | temps := prometheus.NewHistogram(prometheus.HistogramOpts{ |
| 441 | Name: "pond_temperature_celsius", |
| 442 | Help: "The temperature of the frog pond.", // Sorry, we can't measure how badly it smells. |
| 443 | Buckets: prometheus.LinearBuckets(20, 5, 5), // 5 buckets, each 5 centigrade wide. |
| 444 | }) |
| 445 | |
| 446 | // Simulate some observations. |
| 447 | for i := 0; i < 1000; i++ { |
| 448 | temps.Observe(30 + math.Floor(120*math.Sin(float64(i)*0.1))/10) |
| 449 | } |
| 450 | |
| 451 | // Just for demonstration, let's check the state of the histogram by |
| 452 | // (ab)using its Write method (which is usually only used by Prometheus |
| 453 | // internally). |
| 454 | metric := &dto.Metric{} |
| 455 | temps.Write(metric) |
| 456 | |
| 457 | fmt.Println(toNormalizedJSON(sanitizeMetric(metric))) |
| 458 | |
| 459 | // Output: |
| 460 | // {"histogram":{"sampleCount":"1000","sampleSum":29969.50000000001,"bucket":[{"cumulativeCount":"192","upperBound":20},{"cumulativeCount":"366","upperBound":25},{"cumulativeCount":"501","upperBound":30},{"cumulativeCount":"638","upperBound":35},{"cumulativeCount":"816","upperBound":40}],"createdTimestamp":"1970-01-01T00:00:10Z"}} |
| 461 | } |
| 462 | |
| 463 | func ExampleNewConstHistogram() { |
| 464 | desc := prometheus.NewDesc( |
nothing calls this directly
no test coverage detected