| 241 | } |
| 242 | |
| 243 | func 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 | } |