Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPStats ¶
type HTTPStats struct { PID *expvar.Int Invoked *expvar.String InvokedUnix *expvar.Int Uptime *UptimeVar TimeTotal *expvar.Float RequestErrorsTotal *expvar.Int RequestsTotal *expvar.Int BytesInTotal *expvar.Int BytesOutTotal *expvar.Int StatusTotal *expvar.Map History History // contains filtered or unexported fields }
HTTPStats holds the state of the current recorder middleware.
func New ¶
func New(namespace string, histOpts *HistoryOptions) *HTTPStats
New creates a new middleware http stat recorder. Note that because httpstat uses expvar to track data, expvar variables can only be created ONCE, with the same namespace. If you know you are only using one invokation of httpstat, leave namespace blank. Otherwise use it to identify which thing it is recording (e.g. auth, frontend, etc).
histOpts are options which you can use to enable history snapshots (see History.Elems(), and HistoryElem) which can be used to track historical records on how the request count and similar is increasing over time. History is disabled by default as it has an almost negligible performance hit. Make sure if History is being used, that HTTPStats.Close() is called when closing the server.
func (*HTTPStats) Close ¶
func (s *HTTPStats) Close()
Close is required if using History, it will close the goroutine which manages taking snapshots. Should only be called once.
func (*HTTPStats) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface, allowing all httpstats expvars that match the configured namespace of the current HTTPStats, are returned in JSON form.
func (*HTTPStats) Record ¶
Record is the handler wrapper method used to invoke tracking of all child handlers. Note that this should be invoked early in the handler chain, otherwise the handlers invoked before this, will not be recorded/tracked. Also note that if one of the children handlers writes to the ResponseWriter after the handler is returned (e.g. from a goroutine), the time and bytes written will not be updated after the handler returns.
func (*HTTPStats) ServeHTTP ¶
func (s *HTTPStats) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP is a way of invoking/showing the JSON version of httpstats without mounting an expvar endpoint (e.g. if you don't want all of the other expvar stats). If you mount /debug/vars via expvar, this isn't needed.
type History ¶
type History struct { Opts HistoryOptions // contains filtered or unexported fields }
History holds the previous historical elements, and options for how long and how much to store.
func (*History) Elems ¶
func (h *History) Elems() []HistoryElem
Elems returns the list previous history iterations.
type HistoryElem ¶
type HistoryElem struct { Born time.Time TimeTotal float64 TimeDiff float64 RequestErrors int64 RequestsTotal int64 RequestsDiff int64 RPS int64 }
HistoryElem is a snapshot of the http stats from a previous point of time.
type HistoryOptions ¶
type HistoryOptions struct { // Enabled enables history collection. If history isn't needed, you may // want to disable it to improve performance. Enabled bool // MaxResolution is how far back you would like to store in history. For // example, a MaxResolution of 5 minutes means any datapoints older than // 5 minutes, will be truncated from the snapshot list. Defaults to 5 // minutes. MaxResolution time.Duration // Resolution is the time between each snapshot. If your resolution is // 10 seconds and MaxResolution is 5 minutes, that would be (5*60)/10 (or // 30) datapoints. Defaults to 5 seconds. Resolution time.Duration }
HistoryOptions define a set of options for how many history snapshots to store, and when they should expire.
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 to. Written() bool // BytesWritten returns the amount of bytes written to the response body. BytesWritten() int }
ResponseWriter is a custom implementation of the http.ResponseWriter interface.
func NewResponseRecorder ¶
func NewResponseRecorder(w http.ResponseWriter) ResponseWriter
NewResponseRecorder returns a new instance of a responseRecorder.