MCPcopy Create free account
hub / github.com/prometheus/client_golang / ExampleAPI_queryRange

Function ExampleAPI_queryRange

api/prometheus/v1/example_test.go:60–89  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

58}
59
60func ExampleAPI_queryRange() {
61 client, err := api.NewClient(api.Config{
62 Address: DemoPrometheusURL,
63 })
64 if err != nil {
65 fmt.Printf("Error creating client: %v\n", err)
66 os.Exit(1)
67 }
68
69 v1api := v1.NewAPI(client)
70 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
71 defer cancel()
72 r := v1.Range{
73 Start: time.Now().Add(-time.Hour),
74 End: time.Now(),
75 Step: time.Minute,
76 }
77 result, warnings, infos, err := v1api.QueryRange(ctx, "rate(prometheus_tsdb_head_samples_appended_total[5m])", r, v1.WithTimeout(5*time.Second))
78 if err != nil {
79 fmt.Printf("Error querying Prometheus: %v\n", err)
80 os.Exit(1)
81 }
82 if len(warnings) > 0 {
83 fmt.Printf("Warnings: %v\n", warnings)
84 }
85 if len(infos) > 0 {
86 fmt.Printf("Infos: %v\n", infos)
87 }
88 fmt.Printf("Result:\n%v\n", result)
89}
90
91type userAgentRoundTripper struct {
92 name string

Callers

nothing calls this directly

Calls 5

QueryRangeMethod · 0.95
NewClientFunction · 0.92
NewAPIFunction · 0.92
WithTimeoutFunction · 0.92
AddMethod · 0.65

Tested by

no test coverage detected