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

Function ExampleAPI_series

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

Source from the content-addressed store, hash-verified

241}
242
243func ExampleAPI_series() {
244 client, err := api.NewClient(api.Config{
245 Address: DemoPrometheusURL,
246 })
247 if err != nil {
248 fmt.Printf("Error creating client: %v\n", err)
249 os.Exit(1)
250 }
251
252 v1api := v1.NewAPI(client)
253 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
254 defer cancel()
255 lbls, warnings, err := v1api.Series(ctx, []string{
256 "{__name__=~\"scrape_.+\",job=\"node\"}",
257 "{__name__=~\"scrape_.+\",job=\"prometheus\"}",
258 }, time.Now().Add(-time.Hour), time.Now())
259 if err != nil {
260 fmt.Printf("Error querying Prometheus: %v\n", err)
261 os.Exit(1)
262 }
263 if len(warnings) > 0 {
264 fmt.Printf("Warnings: %v\n", warnings)
265 }
266 fmt.Println("Result:")
267 for _, lbl := range lbls {
268 fmt.Println(lbl)
269 }
270}

Callers

nothing calls this directly

Calls 5

SeriesMethod · 0.95
NewClientFunction · 0.92
NewAPIFunction · 0.92
AddMethod · 0.65
PrintlnMethod · 0.65

Tested by

no test coverage detected