Documentation ¶
Index ¶
- type IServerStats
- type ResponseTime
- type ResponseTimeGraph
- type ResponseTimeGraphCollection
- type ResponseTimePrecision
- type ServerStats
- func (s *ServerStats) GetAverageResponseTimeGraph(precision ResponseTimePrecision) ResponseTimeGraphCollection
- func (s *ServerStats) Handler(ctx echo.Context) error
- func (s *ServerStats) Middleware(next echo.HandlerFunc) echo.HandlerFunc
- func (s *ServerStats) NewMiddlewareWithTimeTracking() echo.MiddlewareFunc
- type ServerStatsOptions
- type StatsByDay
- type StatsByDayCollection
- type StatsByHour
- type StatsByHourCollection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IServerStats ¶
type IServerStats interface { GetAverageResponseTimeGraph(precision ResponseTimePrecision) ResponseTimeGraphCollection Handler(ctx echo.Context) error Middleware(next echo.HandlerFunc) echo.HandlerFunc }
IServerStats defines an interface for capturing and retrieving server statistics
type ResponseTime ¶
ResponseTime is used to track how much time a request took to execute, and what time (of day) it happened
type ResponseTimeGraph ¶
type ResponseTimeGraph struct { AverageResponseTimeInNanoseconds int64 `json:"averageResponseTimeInNanoseconds"` AverageResponseTimeInMicroseconds int64 `json:"averageResponseTimeInMicroseconds"` AverageExecutionTimeMilliseconds int64 `json:"averageExecutionTimeMilliseconds"` Time string `json:"time"` }
ResponseTimeGraph reports average response times for a given date/time
type ResponseTimeGraphCollection ¶
type ResponseTimeGraphCollection []*ResponseTimeGraph
ResponseTimeGraphCollection is a collection of ResponseTimeGraph structs
type ResponseTimePrecision ¶
type ResponseTimePrecision int
ResponseTimePrecision describes how granular to report response times
const ( // PrecisionHour reports responses times averaged by hour PrecisionHour ResponseTimePrecision = 1 // PrecisionDay reports respose times averaged by day PrecisionDay ResponseTimePrecision = 2 // PrecisionMonth reports response times averaged by month PrecisionMonth ResponseTimePrecision = 3 )
type ServerStats ¶
type ServerStats struct { AverageFreeSystemMemory *ring.Ring AverageMemoryUsage *ring.Ring CustomStats map[string]interface{} `json:"customStats"` Uptime time.Time `json:"uptime"` RequestCount uint64 `json:"requestCount"` ResponseTimes *ring.Ring StatsByDayCollection StatsByDayCollection Statuses map[string]int `json:"statuses"` sync.RWMutex // contains filtered or unexported fields }
ServerStats tracks general server statistics. This includes information about uptime, response times and counts, and requests counts broken down by HTTP status code. ServerStats is thread-safe due to a write lock on requests, and a read lock on reads
func NewServerStats ¶
func NewServerStats(customMiddleware func(ctx echo.Context, serverStats *ServerStats)) *ServerStats
NewServerStats creates a new ServerStats object
func NewServerStatsWithOptions ¶ added in v4.3.0
func NewServerStatsWithOptions(options ServerStatsOptions, customMiddleware func(ctx echo.Context, serverStats *ServerStats)) *ServerStats
func (*ServerStats) GetAverageResponseTimeGraph ¶
func (s *ServerStats) GetAverageResponseTimeGraph(precision ResponseTimePrecision) ResponseTimeGraphCollection
GetAverageResponseTimeGraph returns an array of response time objects. The precision specifies at what interval you wish to get data for. For example, passing Hour gets you response times averaged by hour. Passing Day gets you response times averaged by day
func (*ServerStats) Handler ¶
func (s *ServerStats) Handler(ctx echo.Context) error
Handler is an endpoint handler you can plug into your application to return stat data
func (*ServerStats) Middleware ¶
func (s *ServerStats) Middleware(next echo.HandlerFunc) echo.HandlerFunc
Middleware is used to capture request and response stats. This is designed to be used with the Echo framework
func (*ServerStats) NewMiddlewareWithTimeTracking ¶ added in v4.3.0
func (s *ServerStats) NewMiddlewareWithTimeTracking() echo.MiddlewareFunc
NewMiddlewareWithTimeTracking returns a middleware that tracks stats by day and hour. You provide it a pointer to a StatsByDayCollection and this will update stats grouped by day (starting at midnight) and hour.
TODO: Perhaps keep the statsByDayCollection in ServerStats locally. cause otherwise this ain't working
type ServerStatsOptions ¶ added in v4.3.0
type StatsByDay ¶ added in v4.3.0
type StatsByDay struct { Date time.Time `json:"date"` HourlyStats StatsByHourCollection `json:"hourlyStats"` }
func NewStatsByDay ¶ added in v4.3.0
func NewStatsByDay(date time.Time) *StatsByDay
type StatsByDayCollection ¶ added in v4.3.0
type StatsByDayCollection []*StatsByDay
type StatsByHour ¶ added in v4.3.0
type StatsByHour struct { Hour int `json:"hour"` AverageFreeMemory uint64 `json:"averageFreeMemory"` AverageFreeMemoryPretty string `json:"averageFreeMemoryPretty"` AverageMemoryUsage uint64 `json:"averageMemoryUsage"` AverageMemoryUsagePretty string `json:"averageMemoryUsagePretty"` AverageResponseTimeInNanoseconds int64 `json:"averageResponseTimeInNanoseconds"` AverageResponseTimeInMicroseconds int64 `json:"averageResponseTimeInMicroseconds"` AverageResponseTimeInMilliseconds int64 `json:"averageResponseTimeInMilliseconds"` CustomStats map[string]interface{} `json:"customStats"` RequestCount uint64 `json:"requestCount"` Statuses map[string]int `json:"statuses"` sync.RWMutex `json:"-"` }
func NewStatsByHour ¶ added in v4.3.0
func NewStatsByHour(hour int) *StatsByHour
func (*StatsByHour) Calculate ¶ added in v4.3.0
func (sbh *StatsByHour) Calculate(s *ServerStats)
type StatsByHourCollection ¶ added in v4.3.0
type StatsByHourCollection []*StatsByHour