/
referer_domain_period.go
71 lines (61 loc) · 1.46 KB
/
referer_domain_period.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package teastats
import (
"github.com/TeaWeb/code/tealogs/accesslogs"
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps"
"net/url"
"strings"
)
// 来源域名统计
type RefererDomainPeriodFilter struct {
CounterFilter
}
func (this *RefererDomainPeriodFilter) Name() string {
return "来源域名统计"
}
func (this *RefererDomainPeriodFilter) Codes() []string {
return []string{
"referer.domain.second",
"referer.domain.minute",
"referer.domain.hour",
"referer.domain.day",
"referer.domain.week",
"referer.domain.month",
"referer.domain.year",
}
}
func (this *RefererDomainPeriodFilter) Indexes() []string {
return []string{"domain"}
}
func (this *RefererDomainPeriodFilter) Start(queue *Queue, code string) {
if queue == nil {
logs.Println("stat queue should be specified for '" + code + "'")
return
}
this.queue = queue
this.queue.Index(this.Indexes())
this.StartFilter(code, code[strings.LastIndex(code, ".")+1:])
}
func (this *RefererDomainPeriodFilter) Filter(accessLog *accesslogs.AccessLog) {
referer := accessLog.GetHeader("Referer")
if len(referer) == 0 {
return
}
uri, err := url.Parse(referer)
if err != nil {
return
}
domain := uri.Host
contentType := accessLog.SentContentType()
if !strings.HasPrefix(contentType, "text/html") {
return
}
this.ApplyFilter(accessLog, map[string]string{
"domain": domain,
}, maps.Map{
"count": 1,
})
}
func (this *RefererDomainPeriodFilter) Stop() {
this.StopFilter()
}