package stats
import "github.com/thoas/stats"
Index ¶
- type Data
- type Label
- type Option
- func WithRecorder(recorder ResponseWriter) Option
- func WithSize(size int) Option
- func WithStatusCode(statusCode int) Option
- type Options
- type ResponseWriter
- type Stats
- func New() *Stats
- func (mw *Stats) Begin(w http.ResponseWriter) (time.Time, ResponseWriter)
- func (mw *Stats) Close()
- func (mw *Stats) Data() *Data
- func (mw *Stats) End(start time.Time, opts ...Option)
- func (mw *Stats) Handler(h http.Handler) http.Handler
- func (mw *Stats) MeasureSince(key string, start time.Time)
- func (mw *Stats) MeasureSinceWithLabels(key string, start time.Time, labels []Label)
- func (mw *Stats) ResetResponseCounts()
- func (mw *Stats) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
Types ¶
type Data ¶
type Data struct { Pid int `json:"pid"` Hostname string `json:"hostname"` UpTime string `json:"uptime"` UpTimeSec float64 `json:"uptime_sec"` Time string `json:"time"` TimeUnix int64 `json:"unixtime"` StatusCodeCount map[string]int `json:"status_code_count"` TotalStatusCodeCount map[string]int `json:"total_status_code_count"` Count int `json:"count"` TotalCount int `json:"total_count"` TotalResponseTime string `json:"total_response_time"` TotalResponseTimeSec float64 `json:"total_response_time_sec"` TotalResponseSize int64 `json:"total_response_size"` AverageResponseSize int64 `json:"average_response_size"` AverageResponseTime string `json:"average_response_time"` AverageResponseTimeSec float64 `json:"average_response_time_sec"` TotalMetricsCounts map[string]int `json:"total_metrics_counts"` AverageMetricsTimers map[string]float64 `json:"average_metrics_timers"` }
Data serializable structure
type Label ¶
Label data structure
type Option ¶
type Option func(*Options)
Option represents a stats option.
func WithRecorder ¶
func WithRecorder(recorder ResponseWriter) Option
WithRecorder sets the recorder to use in stats.
func WithSize ¶
WithSize sets the size to use in stats.
func WithStatusCode ¶
WithStatusCode sets the status code to use in stats.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options are stats options.
func (Options) Size ¶
Size returns the response size.
func (Options) StatusCode ¶
StatusCode returns the response status code.
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter http.Flusher // Status returns the status code of the response or 0 if the response has not been written. Status() int // Written returns whether or not the ResponseWriter has been written. Written() bool // Size returns the size of the response body. Size() int // Before allows for a function to be called before the ResponseWriter has been written to. This is // useful for setting headers or any other operations that must happen before a response has been written. Before(func(ResponseWriter)) }
func NewRecorderResponseWriter ¶
func NewRecorderResponseWriter(w http.ResponseWriter, statusCode int) ResponseWriter
type Stats ¶
type Stats struct { Hostname string Uptime time.Time Pid int ResponseCounts map[string]int TotalResponseCounts map[string]int TotalResponseTime time.Time TotalResponseSize int64 MetricsCounts map[string]int MetricsTimers map[string]time.Time // contains filtered or unexported fields }
Stats data structure
func New ¶
func New() *Stats
New constructs a new Stats structure
func (*Stats) Begin ¶
func (mw *Stats) Begin(w http.ResponseWriter) (time.Time, ResponseWriter)
Begin starts a recorder
func (*Stats) Close ¶
func (mw *Stats) Close()
func (*Stats) Data ¶
Data returns the data serializable structure
func (*Stats) End ¶
End closes the recorder with a specific status
func (*Stats) Handler ¶
Handler is a MiddlewareFunc makes Stats implement the Middleware interface.
func (*Stats) MeasureSince ¶
MeasureSince method for execution time recording
func (*Stats) MeasureSinceWithLabels ¶
MeasureSinceWithLabels method for execution time recording with custom labels
func (*Stats) ResetResponseCounts ¶
func (mw *Stats) ResetResponseCounts()
ResetResponseCounts reset the response counts
func (*Stats) ServeHTTP ¶
func (mw *Stats) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
ServeHTTP: Negroni compatible interface
Source Files ¶
options.go recorder.go stats.go
Directories ¶
Path | Synopsis |
---|---|
examples | |
examples/beego | |
examples/gin-gonic | |
examples/go-chi | |
examples/gocraft | |
examples/goji | |
examples/httprouter | |
examples/martini | |
examples/negroni | |
examples/nethttp |
- Version
- v0.0.0-20190407194641-965cb2de1678 (latest)
- Published
- Apr 7, 2019
- Platform
- js/wasm
- Imports
- 7 packages
- Last checked
- 3 weeks ago –
Tools for package owners.