| 172 | } |
| 173 | |
| 174 | func (p *Producer) Stats() Stats { |
| 175 | if p.writer == nil { |
| 176 | return Stats{} |
| 177 | } |
| 178 | |
| 179 | duration := time.Since(p.startTime) |
| 180 | writerStats := p.writer.Stats() |
| 181 | |
| 182 | p.totalMessages += writerStats.Messages |
| 183 | p.totalErrors += writerStats.Errors |
| 184 | p.totalBytes += writerStats.Bytes |
| 185 | |
| 186 | rate := float64(p.totalMessages) / duration.Seconds() |
| 187 | |
| 188 | return Stats{ |
| 189 | Duration: duration, |
| 190 | TotalMessages: p.totalMessages, |
| 191 | TotalErrors: p.totalErrors, |
| 192 | TotalBytes: p.totalBytes, |
| 193 | Throughput: rate, |
| 194 | } |
| 195 | } |