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

Function ExampleAPI_queryRange

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

Source from the content-addressed store, hash-verified

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