()
| 345 | } |
| 346 | |
| 347 | func ExampleSummaryVec() { |
| 348 | temps := prometheus.NewSummaryVec( |
| 349 | prometheus.SummaryOpts{ |
| 350 | Name: "pond_temperature_celsius", |
| 351 | Help: "The temperature of the frog pond.", |
| 352 | Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, |
| 353 | }, |
| 354 | []string{"species"}, |
| 355 | ) |
| 356 | |
| 357 | // Simulate some observations. |
| 358 | for i := 0; i < 1000; i++ { |
| 359 | temps.WithLabelValues("litoria-caerulea").Observe(30 + math.Floor(120*math.Sin(float64(i)*0.1))/10) |
| 360 | temps.WithLabelValues("lithobates-catesbeianus").Observe(32 + math.Floor(100*math.Cos(float64(i)*0.11))/10) |
| 361 | } |
| 362 | |
| 363 | // Create a Summary without any observations. |
| 364 | temps.WithLabelValues("leiopelma-hochstetteri") |
| 365 | |
| 366 | // Just for demonstration, let's check the state of the summary vector |
| 367 | // by registering it with a custom registry and then let it collect the |
| 368 | // metrics. |
| 369 | reg := prometheus.NewRegistry() |
| 370 | reg.MustRegister(temps) |
| 371 | |
| 372 | metricFamilies, err := reg.Gather() |
| 373 | if err != nil || len(metricFamilies) != 1 { |
| 374 | panic("unexpected behavior of custom test registry") |
| 375 | } |
| 376 | |
| 377 | fmt.Println(toNormalizedJSON(sanitizeMetricFamily(metricFamilies[0]))) |
| 378 | |
| 379 | // Output: |
| 380 | // {"name":"pond_temperature_celsius","help":"The temperature of the frog pond.","type":"SUMMARY","metric":[{"label":[{"name":"species","value":"leiopelma-hochstetteri"}],"summary":{"sampleCount":"0","sampleSum":0,"quantile":[{"quantile":0.5,"value":"NaN"},{"quantile":0.9,"value":"NaN"},{"quantile":0.99,"value":"NaN"}],"createdTimestamp":"1970-01-01T00:00:10Z"}},{"label":[{"name":"species","value":"lithobates-catesbeianus"}],"summary":{"sampleCount":"1000","sampleSum":31956.100000000017,"quantile":[{"quantile":0.5,"value":32.4},{"quantile":0.9,"value":41.4},{"quantile":0.99,"value":41.9}],"createdTimestamp":"1970-01-01T00:00:10Z"}},{"label":[{"name":"species","value":"litoria-caerulea"}],"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"}}]} |
| 381 | } |
| 382 | |
| 383 | func ExampleNewConstSummary() { |
| 384 | desc := prometheus.NewDesc( |
nothing calls this directly
no test coverage detected