events

package
v0.0.0-...-c160ba3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Domain    = "domain"
	Referer   = "referer"
	Path      = "path"
	EventName = "name"
	EntryPage = "entry_page"
	ExitPage  = "exit_page"
	UserID    = "user_id"
	SessionID = "session_id"
)
View Source
const Day = 24 * time.Hour
View Source
const Month = 30 * Day

Variables

View Source
var BounceRate = prometheus.NewCounterVec(
	prometheus.CounterOpts{
		Name: "bounce_rate",
		Help: "Counts a single page view",
	},
	[]string{
		Domain,
		SessionID,
		Referer,
		EntryPage,
	},
)
View Source
var Custom = prometheus.NewCounterVec(
	prometheus.CounterOpts{
		Name: string(customEvent),
		Help: "Counts events",
	},
	[]string{
		EventName,
		Domain,
		UserID,
		Referer,
		Path,
	},
)
View Source
var VisitDuration = prometheus.NewHistogramVec(
	prometheus.HistogramOpts{
		Name: "visit_duration",
		Help: "Tracks how long a visitor stays on a page",
	},
	[]string{
		Domain,
		SessionID,
		Referer,
		EntryPage,
		ExitPage,
	},
)
View Source
var Visitors = prometheus.NewGaugeVec(
	prometheus.GaugeOpts{
		Name: string(visitors),
		Help: "Tracks site visitors",
	},
	[]string{
		Domain,
		UserID,
		Referer,
		Path,
	},
)
View Source
var Visits = prometheus.NewGaugeVec(
	prometheus.GaugeOpts{
		Name: "visits",
		Help: "Counts a number of events per session",
	},
	[]string{
		Domain,
		SessionID,
		Referer,
		EntryPage,
		ExitPage,
	},
)

Functions

func GroupBy

func GroupBy(q string, labels ...string) string

func InstantQuery

func InstantQuery(ctx context.Context, req *QueryRequest) (*promql.Result, error)

func Now

func Now() time.Time

func RangeQuery

func RangeQuery(ctx context.Context, req *QueryRangeRequest) (*promql.Result, error)

func Record

func Record(ctx context.Context, e *models.Event)

func RecordSession

func RecordSession(s *models.Session)

func SetupQuery

func SetupQuery(ctx context.Context, log *zap.Logger, read remote.ReadClient) context.Context

func WriteLoop

func WriteLoop(ctx context.Context, write remote.WriteClient, flush time.Duration)

Types

type Engine

type Engine struct {
	Queryable storage.Queryable
	Engine    *promql.Engine
}

type Period

type Period uint
const (
	Realtime Period = iota
	Current
	ADay
	AWeek
	AMonth
	AFixedMonth //30 days
	HalfAYear
	AYear
)

func (Period) String

func (p Period) String() string

type Query

type Query struct {
	Series    string
	Range     TimeRange
	Period    Period
	Interrval time.Duration
	Filters   map[string]*labels.Matcher
}

func QueryFrom

func QueryFrom(period Period, nowFunc func() time.Time) *Query

func (*Query) Domain

func (q *Query) Domain(domain string) *Query

func (*Query) Equal

func (q *Query) Equal(name, value string) *Query

func (*Query) IsNotPage

func (q *Query) IsNotPage(page string) *Query

func (*Query) IsPage

func (q *Query) IsPage(page string) *Query

func (*Query) MatchName

func (q *Query) MatchName(name string) *Query

func (*Query) MatchPage

func (q *Query) MatchPage(page string) *Query

func (*Query) Name

func (q *Query) Name(name string) *Query

func (*Query) NameInList

func (q *Query) NameInList(names ...string) *Query

func (*Query) NotEqual

func (q *Query) NotEqual(name, value string) *Query

func (*Query) NotMatchPage

func (q *Query) NotMatchPage(page string) *Query

func (*Query) NotRe

func (q *Query) NotRe(name, value string) *Query

func (*Query) PageInList

func (q *Query) PageInList(pages ...string) *Query

func (*Query) PageNotInList

func (q *Query) PageNotInList(pages ...string) *Query

func (*Query) Re

func (q *Query) Re(name, value string) *Query

func (*Query) Request

func (q *Query) Request(modifirer ...func(string) string) QueryRangeRequest

func (*Query) Write

func (q *Query) Write(b *bytes.Buffer)

type QueryRangeRequest

type QueryRangeRequest struct {
	Start, End time.Time
	Query      string
	Step       time.Duration
}

func CurrentVisitorsQuery

func CurrentVisitorsQuery(site *models.Site, nowFunc func() time.Time) QueryRangeRequest

func PageViewQuery

func PageViewQuery(site *models.Site, period Period, nowFunc func() time.Time) QueryRangeRequest

func (*QueryRangeRequest) Validate

func (q *QueryRangeRequest) Validate() error

type QueryRequest

type QueryRequest struct {
	Timestamp time.Time
	Query     string
}

type TimeRange

type TimeRange struct {
	Start, End time.Time
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL