Documentation ¶
Index ¶
- Constants
- Variables
- func RandomString(n int) string
- type Appender
- type Collector
- func (c *Collector) Add(r *http.Request) error
- func (c *Collector) Close() error
- func (c *Collector) Collect(h http.Handler) http.Handler
- func (c *Collector) Hit(hit *Hit) error
- func (c *Collector) Report(extra interface{}) http.Handler
- func (c *Collector) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (c *Collector) Stats() (*Stats, *Stats, error)
- type Frame
- type GeoFinder
- type Hit
- type Option
- type Row
- type Stats
Constants ¶
const ( // Mobile device type Mobile = "mobile" // Desktop device type Desktop = "desktop" )
Variables ¶
var ( // MaxPathLength is the longest possible URI or event name length. MaxPathLength = 200 // MaxRefLength is the longest possible referrer length. Typically, domain // names are no longer than 63 bytes. MaxRefLength = 64 // MaxCountryLength is the longest possible country code. Nullitics uses ISO // codes, so 2 bytes should be enough. MaxCountryLength = 2 )
var ( // IPHeaders are request headers, containing the real user IP address IPHeaders = []string{"X-Real-IP", "X-Forwarded-For"} // MobileUAs are user-agent substrings, typical only for mobile devices MobileUAs = []string{"iPhone", "iPad", "Android"} // MobileBreakpoint is the maximum screen width for mobile devices, 992px is taken from Bootstrap. MobileBreakpoint = 992 // SkipSubdomains is a list of common subdomains to skip in referrers SkipSubdomains = []string{"www.", "www1.", "www2.", "www3.", "www4.", "m.", "l.", "lm.", "i.", "old."} // BotAgents is a list of substrings commonly met in bot/crawler User-Agent strings BotAgents = []string{"bot", "crawler", "spider", "spyder", "search", "worm", "fetch", "nutch", "http://", "https://"} )
var Now = time.Now
Now is a timestamp generator. It is made public so that the caller could mock it or replace with their own implementation.
var ( // ReportTemplate is a http/template.Template for the default dashboard UI. // Feel free to customize it to your own needs by providing the {{extra_head}}, // {{header}} or {{footer}} sections. ReportTemplate = template.Must(template.ParseFS(report, "report/*.*", "report/components/*.*")) )
Functions ¶
func RandomString ¶
RandomString is a helper utility to generate random string IDs, salts etc.
Types ¶
type Appender ¶
type Appender struct {
// contains filtered or unexported fields
}
Appender is an append-only log writer.
func NewAppender ¶
NewAppender creates an Appender for the given log filename. It may optionally truncate the log file before using it.
type Collector ¶
Collector is an abstracton that records Hits and provides collected Stats.
func (*Collector) Collect ¶
Collect is a middleware that wraps an existing handler and collects every hit/request.
func (*Collector) Report ¶
Report returns a handler that renders the dashboard report for the collected stats
type Frame ¶
type Frame struct { Rows []Row // contains filtered or unexported fields }
Frame is a matrix-shaped data frame, used to store time series of named integer values.
func (*Frame) Grow ¶
Grow resizes all the rows of the frame to the given width. Same width will be also applied to the new rows that will be created in this frame.
type GeoFinder ¶
GeoFinder is an interface, that can find the country ISO code by the IP address.
var GeoDB GeoFinder
GeoDB is a file location for a GeoLite CSV database. By default the location is set to $GEODB environment variable, but can be changed if needed.
type Hit ¶
type Hit struct { Timestamp time.Time URI string Session string Ref string Country string Device string }
Hit is a basic data type describing a single page visit or event.
type Option ¶
type Option func(c *Collector)
Option is a function option data type for Collector.
func BlacklistPrefix ¶
BlacklistPrefix ignores certain URIs by prefix.
type Row ¶
Row is a single record for names time series in the stats data frame. Row has a unique name and a series of integer values, one for each time slot of the data frame.
type Stats ¶
type Stats struct { Start time.Time Interval time.Duration URIs Frame Sessions Frame Refs Frame Countries Frame Devices Frame }
Stats is an aggregated data from the various site-related statistics over a given time period.
func ParseAppendLog ¶
ParseAppendLog read the log file, assuming the timestamps are in the given time zone, and returns a Stats object with hourly precision.
func ParseStatsCSV ¶
ParseStatsCSV returns a Stats instance from the given CSV text string.