@@ -405,6 +405,35 @@ func ExampleNewConstSummary() {
405
405
// {"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}]}}
406
406
}
407
407
408
+ func ExampleNewConstSummaryWithCreatedTimestamp () {
409
+ desc := prometheus .NewDesc (
410
+ "http_request_duration_seconds" ,
411
+ "A summary of the HTTP request durations." ,
412
+ []string {"code" , "method" },
413
+ prometheus.Labels {"owner" : "example" },
414
+ )
415
+
416
+ // Create a constant summary with created timestamp set
417
+ createdTs := time .Unix (1719670764 , 123 )
418
+ s := prometheus .MustNewConstSummaryWithCreatedTimestamp (
419
+ desc ,
420
+ 4711 , 403.34 ,
421
+ map [float64 ]float64 {0.5 : 42.3 , 0.9 : 323.3 },
422
+ createdTs ,
423
+ "200" , "get" ,
424
+ )
425
+
426
+ // Just for demonstration, let's check the state of the summary by
427
+ // (ab)using its Write method (which is usually only used by Prometheus
428
+ // internally).
429
+ metric := & dto.Metric {}
430
+ s .Write (metric )
431
+ fmt .Println (toNormalizedJSON (metric ))
432
+
433
+ // Output:
434
+ // {"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}],"createdTimestamp":"2024-06-29T14:19:24.000000123Z"}}
435
+ }
436
+
408
437
func ExampleHistogram () {
409
438
temps := prometheus .NewHistogram (prometheus.HistogramOpts {
410
439
Name : "pond_temperature_celsius" ,
@@ -464,12 +493,12 @@ func ExampleNewConstHistogramWithCreatedTimestamp() {
464
493
prometheus.Labels {"owner" : "example" },
465
494
)
466
495
467
- ct := time .Unix (0 , 0 ). UTC ( )
496
+ createdTs := time .Unix (1719670764 , 123 )
468
497
h := prometheus .MustNewConstHistogramWithCreatedTimestamp (
469
498
desc ,
470
499
4711 , 403.34 ,
471
500
map [float64 ]uint64 {25 : 121 , 50 : 2403 , 100 : 3221 , 200 : 4233 },
472
- ct ,
501
+ createdTs ,
473
502
"200" , "get" ,
474
503
)
475
504
@@ -481,7 +510,7 @@ func ExampleNewConstHistogramWithCreatedTimestamp() {
481
510
fmt .Println (toNormalizedJSON (metric ))
482
511
483
512
// 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 "}}
513
+ // {"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":"2024-06-29T14:19:24.000000123Z "}}
485
514
}
486
515
487
516
func ExampleNewConstHistogram_WithExemplar () {
0 commit comments