1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-17 18:06:15 -05:00
v2fly/app/dispatcher/stats.go
刘志龙 af0120e771
Add traffic stat of every request in access log (#642)
* Add traffic stat of every request in access log

* Fix: record pointer may be null

* Clarify the data unit in access log
2021-01-30 01:47:13 +08:00

33 lines
583 B
Go

// +build !confonly
package dispatcher
import (
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
"v2ray.com/core/features/stats"
)
type SizeStatWriter struct {
Counter stats.Counter
Writer buf.Writer
Record *int64
}
func (w *SizeStatWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
bufLen := int64(mb.Len())
if w.Record != nil {
*w.Record += bufLen
}
w.Counter.Add(bufLen)
return w.Writer.WriteMultiBuffer(mb)
}
func (w *SizeStatWriter) Close() error {
return common.Close(w.Writer)
}
func (w *SizeStatWriter) Interrupt() {
common.Interrupt(w.Writer)
}