NewCounter returns a new Counter stats object. If a Counter stats object with the same name already exists it is returned.
(name string)
| 326 | // NewCounter returns a new Counter stats object. |
| 327 | // If a Counter stats object with the same name already exists it is returned. |
| 328 | func NewCounter(name string) *Counter { |
| 329 | c := &Counter{ |
| 330 | total: atomic.NewInt64(0), |
| 331 | rate: atomic.NewFloat64(0), |
| 332 | resetTime: time.Now(), |
| 333 | } |
| 334 | existing := expvar.Get(statsPrefix + name) |
| 335 | if existing != nil { |
| 336 | if c, ok := existing.(*Counter); ok { |
| 337 | return c |
| 338 | } |
| 339 | panic(fmt.Sprintf("%v is set to a non-Counter value", name)) |
| 340 | } |
| 341 | expvar.Publish(statsPrefix+name, c) |
| 342 | return c |
| 343 | } |
| 344 | |
| 345 | func (c *Counter) updateRate() { |
| 346 | total := c.total.Load() |