@@ -405,6 +405,35 @@ func ExampleNewConstSummary() {
405405 // {"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}]}}
406406}
407407
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+
408437func ExampleHistogram () {
409438 temps := prometheus .NewHistogram (prometheus.HistogramOpts {
410439 Name : "pond_temperature_celsius" ,
@@ -456,6 +485,34 @@ func ExampleNewConstHistogram() {
456485 // {"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}]}}
457486}
458487
488+ func ExampleNewConstHistogramWithCreatedTimestamp () {
489+ desc := prometheus .NewDesc (
490+ "http_request_duration_seconds" ,
491+ "A histogram of the HTTP request durations." ,
492+ []string {"code" , "method" },
493+ prometheus.Labels {"owner" : "example" },
494+ )
495+
496+ createdTs := time .Unix (1719670764 , 123 )
497+ h := prometheus .MustNewConstHistogramWithCreatedTimestamp (
498+ desc ,
499+ 4711 , 403.34 ,
500+ map [float64 ]uint64 {25 : 121 , 50 : 2403 , 100 : 3221 , 200 : 4233 },
501+ createdTs ,
502+ "200" , "get" ,
503+ )
504+
505+ // Just for demonstration, let's check the state of the histogram by
506+ // (ab)using its Write method (which is usually only used by Prometheus
507+ // internally).
508+ metric := & dto.Metric {}
509+ h .Write (metric )
510+ fmt .Println (toNormalizedJSON (metric ))
511+
512+ // Output:
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"}}
514+ }
515+
459516func ExampleNewConstHistogram_WithExemplar () {
460517 desc := prometheus .NewDesc (
461518 "http_request_duration_seconds" ,
0 commit comments