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

Function ExampleAPI_query

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

Source from the content-addressed store, hash-verified

31const DemoPrometheusURL = "https://demo.prometheus.io:443"
32
33func ExampleAPI_query() {
34 client, err := api.NewClient(api.Config{
35 Address: DemoPrometheusURL,
36 })
37 if err != nil {
38 fmt.Printf("Error creating client: %v\n", err)
39 os.Exit(1)
40 }
41
42 v1api := v1.NewAPI(client)
43 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
44 defer cancel()
45 result, warnings, err := v1api.Query(ctx, "up", time.Now(), v1.WithTimeout(5*time.Second))
46 if err != nil {
47 fmt.Printf("Error querying Prometheus: %v\n", err)
48 os.Exit(1)
49 }
50 if len(warnings) > 0 {
51 fmt.Printf("Warnings: %v\n", warnings)
52 }
53 fmt.Printf("Result:\n%v\n", result)
54}
55
56func ExampleAPI_queryRange() {
57 client, err := api.NewClient(api.Config{

Callers

nothing calls this directly

Calls 4

QueryMethod · 0.95
NewClientFunction · 0.92
NewAPIFunction · 0.92
WithTimeoutFunction · 0.92

Tested by

no test coverage detected