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

Function ExampleAPI_query

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

Source from the content-addressed store, hash-verified

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