rebound/ssh/stats.go

44 lines
849 B
Go
Raw Normal View History

2023-09-24 20:21:44 +02:00
package ssh
import (
"io"
"forge.cadoles.com/wpetit/rebound/stat"
)
const (
StatTotalOpenedTunnels = "total_opened_tunnels"
StatTotalTxBytes = "total_tx_bytes"
StatTotalRxBytes = "total_rx_bytes"
)
type instrumentedWriter struct {
name string
stats *stat.Store
internal io.Writer
}
// Write implements io.Writer.
func (w *instrumentedWriter) Write(p []byte) (n int, err error) {
n, err = w.internal.Write(p)
w.stats.Add(w.name, float64(n), 0)
return n, err
}
var _ io.Writer = &instrumentedWriter{}
type instrumentedReader struct {
name string
stats *stat.Store
internal io.Reader
}
// Read implements io.Reader.
func (w *instrumentedReader) Read(p []byte) (n int, err error) {
n, err = w.internal.Read(p)
w.stats.Add(w.name, float64(n), 0)
return n, err
}
var _ io.Reader = &instrumentedReader{}