Stats returns a snapshot of the writer stats since the last time the method was called, or since the writer was created if it is called for the first time. A typical use of this method is to spawn a goroutine that will periodically call Stats on a kafka writer and report the metrics to a stats coll
()
| 876 | // call Stats on a kafka writer and report the metrics to a stats collection |
| 877 | // system. |
| 878 | func (w *Writer) Stats() WriterStats { |
| 879 | stats := w.stats() |
| 880 | return WriterStats{ |
| 881 | Dials: stats.dials.snapshot(), |
| 882 | Writes: stats.writes.snapshot(), |
| 883 | Messages: stats.messages.snapshot(), |
| 884 | Bytes: stats.bytes.snapshot(), |
| 885 | Errors: stats.errors.snapshot(), |
| 886 | DialTime: stats.dialTime.snapshotDuration(), |
| 887 | BatchTime: stats.batchTime.snapshotDuration(), |
| 888 | BatchQueueTime: stats.batchQueueTime.snapshotDuration(), |
| 889 | WriteTime: stats.writeTime.snapshotDuration(), |
| 890 | WaitTime: stats.waitTime.snapshotDuration(), |
| 891 | Retries: stats.retries.snapshot(), |
| 892 | BatchSize: stats.batchSize.snapshot(), |
| 893 | BatchBytes: stats.batchSizeBytes.snapshot(), |
| 894 | MaxAttempts: int64(w.maxAttempts()), |
| 895 | WriteBackoffMin: w.writeBackoffMin(), |
| 896 | WriteBackoffMax: w.writeBackoffMax(), |
| 897 | MaxBatchSize: int64(w.batchSize()), |
| 898 | BatchTimeout: w.batchTimeout(), |
| 899 | ReadTimeout: w.readTimeout(), |
| 900 | WriteTimeout: w.writeTimeout(), |
| 901 | RequiredAcks: int64(w.RequiredAcks), |
| 902 | Async: w.Async, |
| 903 | Topic: w.Topic, |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | func (w *Writer) chooseTopic(msg Message) (string, error) { |
| 908 | // w.Topic and msg.Topic are mutually exclusive, meaning only 1 must be set |