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

Function ExampleAPI_queryRange

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

Source from the content-addressed store, hash-verified

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