MCPcopy
hub / github.com/prometheus/client_golang / ExampleSummary

Function ExampleSummary

prometheus/examples_test.go:323–345  ·  prometheus/examples_test.go::ExampleSummary
()

Source from the content-addressed store, hash-verified

321}
322
323func ExampleSummary() {
324 temps := prometheus.NewSummary(prometheus.SummaryOpts{
325 Name: "pond_temperature_celsius",
326 Help: "The temperature of the frog pond.",
327 Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
328 })
329
330 // Simulate some observations.
331 for i := 0; i < 1000; i++ {
332 temps.Observe(30 + math.Floor(120*math.Sin(float64(i)*0.1))/10)
333 }
334
335 // Just for demonstration, let's check the state of the summary by
336 // (ab)using its Write method (which is usually only used by Prometheus
337 // internally).
338 metric := &dto.Metric{}
339 temps.Write(metric)
340
341 fmt.Println(toNormalizedJSON(sanitizeMetric(metric)))
342
343 // Output:
344 // {"summary":{"sampleCount":"1000","sampleSum":29969.50000000001,"quantile":[{"quantile":0.5,"value":31.1},{"quantile":0.9,"value":41.3},{"quantile":0.99,"value":41.9}],"createdTimestamp":"1970-01-01T00:00:10Z"}}
345}
346
347func ExampleSummaryVec() {
348 temps := prometheus.NewSummaryVec(

Callers

nothing calls this directly

Calls 6

ObserveMethod · 0.95
NewSummaryFunction · 0.92
toNormalizedJSONFunction · 0.85
sanitizeMetricFunction · 0.85
WriteMethod · 0.65
PrintlnMethod · 0.65

Tested by

no test coverage detected