Documentation
¶
Index ¶
- func IsPageView(entry *LogEntry) bool
- func IsStaticResource(uri string) bool
- func ParseSyslog(msg []byte) (string, []byte)
- func ParseUA(rawUA string) (browser, os string)
- func SpiderName(ua string) string
- type Aggregator
- func (a *Aggregator) DrainDetailStats() (detailsByDate map[string]map[string]*SiteDetailSnapshot, commit func())
- func (a *Aggregator) DrainErrors() (entries []*ErrorEntry, commit func())
- func (a *Aggregator) DrainSnapshot() (snapshotsByDate map[string]map[string]*SiteSnapshot, commit func())
- func (a *Aggregator) Realtime() RealtimeStats
- func (a *Aggregator) Record(entry *LogEntry)
- func (a *Aggregator) Reset()
- func (a *Aggregator) SiteStats() map[string]*SiteSnapshot
- type ClientCount
- type ErrorEntry
- type HourSnapshot
- type IPCount
- type Listener
- type LogEntry
- type RealtimeStats
- type SiteDetailSnapshot
- type SiteSnapshot
- type URICount
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsStaticResource ¶
IsStaticResource 判定 URI 是否为静态资源(js/css/图片/字体等)
func ParseSyslog ¶
ParseSyslog 从 syslog 消息中提取 tag 和 JSON 体 格式: <PRI>MMM DD HH:MM:SS tag: JSON(nohostname 模式下无主机名)
Types ¶
type Aggregator ¶
type Aggregator struct {
// 可配置上限
ErrBufMaxSize int // 错误缓冲最大条目数,默认 10000
UVMaxKeys int // 每站每天 UV 去重 set 上限,默认 1000000
IPMaxKeys int // 每站每天 IP 去重 set 上限,默认 500000
DetailMaxKeys int // 详细统计(蜘蛛/客户端/IP/URI)每站每天最大条目数,默认 50000
BodyEnabled bool // 是否记录错误请求体,默认 false
// contains filtered or unexported fields
}
Aggregator 内存聚合器,将日志条目聚合为站点统计快照
func (*Aggregator) DrainDetailStats ¶
func (a *Aggregator) DrainDetailStats() (detailsByDate map[string]map[string]*SiteDetailSnapshot, commit func())
DrainDetailStats 导出详细统计增量(蜘蛛/客户端/IP/URI) 返回 commit 函数,调用方写库成功后必须调用 commit 来清空计数器
func (*Aggregator) DrainErrors ¶
func (a *Aggregator) DrainErrors() (entries []*ErrorEntry, commit func())
DrainErrors 取出错误缓冲快照 返回 commit 函数,写库成功后调用以移除已消费的条目
func (*Aggregator) DrainSnapshot ¶
func (a *Aggregator) DrainSnapshot() (snapshotsByDate map[string]map[string]*SiteSnapshot, commit func())
DrainSnapshot 返回自上次 drain 以来的增量快照 返回 commit 函数,调用方写库成功后必须调用 commit 来消费已快照的增量 若写库失败不调用 commit,数据保留在内存中,下次 drain 会再次包含
func (*Aggregator) Realtime ¶
func (a *Aggregator) Realtime() RealtimeStats
Realtime 返回最近一段时间的实时流量和 RPS
func (*Aggregator) SiteStats ¶
func (a *Aggregator) SiteStats() map[string]*SiteSnapshot
SiteStats 返回各站点自上次刷新以来的未刷新增量(用于实时展示叠加到 DB 数据上)
type ErrorEntry ¶
type ErrorEntry struct {
Site string
URI string
Method string
IP string
UA string
Body string
Status int
}
ErrorEntry 错误日志条目
type HourSnapshot ¶
type HourSnapshot struct {
PV uint64 `json:"pv"`
UV uint64 `json:"uv"`
IP uint64 `json:"ip"`
Bandwidth uint64 `json:"bandwidth"`
BandwidthIn uint64 `json:"bandwidth_in"`
Requests uint64 `json:"requests"`
Errors uint64 `json:"errors"`
Spiders uint64 `json:"spiders"`
RequestTimeSum uint64 `json:"request_time_sum"`
RequestTimeCount uint64 `json:"request_time_count"`
Status2xx uint64 `json:"status_2xx"`
Status3xx uint64 `json:"status_3xx"`
Status4xx uint64 `json:"status_4xx"`
Status5xx uint64 `json:"status_5xx"`
}
HourSnapshot 小时粒度快照
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener 通过 Unix Datagram Socket 监听 nginx syslog 消息
func NewListener ¶
NewListener 创建并绑定 Unix Datagram Socket 监听器
type LogEntry ¶
type LogEntry struct {
Site string // 来自 syslog tag
URI string // 请求 URI
Status int // HTTP 状态码
Bytes uint64 // 响应体大小
UA string // User-Agent
IP string // 客户端 IP
Method string // 请求方法
Body string // 请求体(仅 400-599 状态码时保留)
ContentType string // 响应 Content-Type(PV 判定用)
ReqLength uint64 // 请求大小(入站流量)
RequestTime float64 // 请求耗时(秒)
}
LogEntry 解析后的访问日志条目
type RealtimeStats ¶
type RealtimeStats struct {
Bandwidth float64 `json:"bandwidth"` // 出站字节/秒
BandwidthIn float64 `json:"bandwidth_in"` // 入站字节/秒
RPS float64 `json:"rps"` // 请求/秒
}
RealtimeStats 实时统计
type SiteDetailSnapshot ¶
type SiteDetailSnapshot struct {
Spiders map[string]uint64 // spider_name → requests
Clients map[string]*ClientCount // "browser|os" → count
IPs map[string]*IPCount // ip → count
URIs map[string]*URICount // uri → count
}
SiteDetailSnapshot 站点详细统计快照(用于 DrainDetailStats)
type SiteSnapshot ¶
type SiteSnapshot struct {
PV uint64 `json:"pv"`
UV uint64 `json:"uv"`
IP uint64 `json:"ip"`
Bandwidth uint64 `json:"bandwidth"`
BandwidthIn uint64 `json:"bandwidth_in"`
Requests uint64 `json:"requests"`
Errors uint64 `json:"errors"`
Spiders uint64 `json:"spiders"`
RequestTimeSum uint64 `json:"request_time_sum"`
RequestTimeCount uint64 `json:"request_time_count"`
Status2xx uint64 `json:"status_2xx"`
Status3xx uint64 `json:"status_3xx"`
Status4xx uint64 `json:"status_4xx"`
Status5xx uint64 `json:"status_5xx"`
Hours [24]*HourSnapshot `json:"-"`
}
SiteSnapshot 站点快照(用于 DB flush)