@@ -456,6 +456,34 @@ func ExampleNewConstHistogram() {
456
456
// {"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}]}}
457
457
}
458
458
459
+ func ExampleNewConstHistogramWithCreatedTimestamp () {
460
+ desc := prometheus .NewDesc (
461
+ "http_request_duration_seconds" ,
462
+ "A histogram of the HTTP request durations." ,
463
+ []string {"code" , "method" },
464
+ prometheus.Labels {"owner" : "example" },
465
+ )
466
+
467
+ ct := time .Unix (0 , 0 ).UTC ()
468
+ h := prometheus .MustNewConstHistogramWithCreatedTimestamp (
469
+ desc ,
470
+ 4711 , 403.34 ,
471
+ map [float64 ]uint64 {25 : 121 , 50 : 2403 , 100 : 3221 , 200 : 4233 },
472
+ ct ,
473
+ "200" , "get" ,
474
+ )
475
+
476
+ // Just for demonstration, let's check the state of the histogram by
477
+ // (ab)using its Write method (which is usually only used by Prometheus
478
+ // internally).
479
+ metric := & dto.Metric {}
480
+ h .Write (metric )
481
+ fmt .Println (toNormalizedJSON (metric ))
482
+
483
+ // Output:
484
+ // {"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}],"createdTimestamp":"1970-01-01T00:00:00Z"}}
485
+ }
486
+
459
487
func ExampleNewConstHistogram_WithExemplar () {
460
488
desc := prometheus .NewDesc (
461
489
"http_request_duration_seconds" ,
0 commit comments