| 438 | } |
| 439 | |
| 440 | func ExampleBridge() { |
| 441 | b, err := NewBridge(&Config{ |
| 442 | URL: "graphite.example.org:3099", |
| 443 | Gatherer: prometheus.DefaultGatherer, |
| 444 | Prefix: "prefix", |
| 445 | Interval: 15 * time.Second, |
| 446 | Timeout: 10 * time.Second, |
| 447 | ErrorHandling: AbortOnError, |
| 448 | Logger: log.New(os.Stdout, "graphite bridge: ", log.Lshortfile), |
| 449 | }) |
| 450 | if err != nil { |
| 451 | panic(err) |
| 452 | } |
| 453 | |
| 454 | go func() { |
| 455 | // Start something in a goroutine that uses metrics. |
| 456 | }() |
| 457 | |
| 458 | // Push initial metrics to Graphite. Fail fast if the push fails. |
| 459 | if err := b.Push(); err != nil { |
| 460 | panic(err) |
| 461 | } |
| 462 | |
| 463 | // Create a Context to control stopping the Run() loop that pushes |
| 464 | // metrics to Graphite. |
| 465 | ctx, cancel := context.WithCancel(context.Background()) |
| 466 | defer cancel() |
| 467 | |
| 468 | // Start pushing metrics to Graphite in the Run() loop. |
| 469 | b.Run(ctx) |
| 470 | } |