|
@@ -15,8 +15,8 @@ import (
|
|
|
and store them for future analysis
|
|
|
*/
|
|
|
|
|
|
-//Faststat, a interval summary for all collected data and avoid
|
|
|
-//looping through every data everytime a overview is needed
|
|
|
+// Faststat, a interval summary for all collected data and avoid
|
|
|
+// looping through every data everytime a overview is needed
|
|
|
type DailySummary struct {
|
|
|
TotalRequest int64 //Total request of the day
|
|
|
ErrorRequest int64 //Invalid request of the day, including error or not found
|
|
@@ -69,7 +69,7 @@ func NewStatisticCollector(option CollectorOption) (*Collector, error) {
|
|
|
return &thisCollector, nil
|
|
|
}
|
|
|
|
|
|
-//Write the current in-memory summary to database file
|
|
|
+// Write the current in-memory summary to database file
|
|
|
func (c *Collector) SaveSummaryOfDay() {
|
|
|
//When it is called in 0:00am, make sure it is stored as yesterday key
|
|
|
t := time.Now().Add(-30 * time.Second)
|
|
@@ -78,7 +78,7 @@ func (c *Collector) SaveSummaryOfDay() {
|
|
|
c.Option.Database.Write("stats", summaryKey, saveData)
|
|
|
}
|
|
|
|
|
|
-//Load the summary of a day given
|
|
|
+// Load the summary of a day given
|
|
|
func (c *Collector) LoadSummaryOfDay(year int, month time.Month, day int) *DailySummary {
|
|
|
date := time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.Local)
|
|
|
summaryKey := date.Format("02_01_2006")
|
|
@@ -88,7 +88,7 @@ func (c *Collector) LoadSummaryOfDay(year int, month time.Month, day int) *Daily
|
|
|
return &targetSummary
|
|
|
}
|
|
|
|
|
|
-//This function gives the current slot in the 288- 5 minutes interval of the day
|
|
|
+// This function gives the current slot in the 288- 5 minutes interval of the day
|
|
|
func (c *Collector) GetCurrentRealtimeStatIntervalId() int {
|
|
|
now := time.Now()
|
|
|
startOfDay := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).Unix()
|
|
@@ -106,9 +106,9 @@ func (c *Collector) Close() {
|
|
|
|
|
|
}
|
|
|
|
|
|
-//Main function to record all the inbound traffics
|
|
|
-//Note that this function run in go routine and might have concurrent R/W issue
|
|
|
-//Please make sure there is no racing paramters in this function
|
|
|
+// Main function to record all the inbound traffics
|
|
|
+// Note that this function run in go routine and might have concurrent R/W issue
|
|
|
+// Please make sure there is no racing paramters in this function
|
|
|
func (c *Collector) RecordRequest(ri RequestInfo) {
|
|
|
go func() {
|
|
|
c.DailySummary.TotalRequest++
|
|
@@ -134,6 +134,14 @@ func (c *Collector) RecordRequest(ri RequestInfo) {
|
|
|
c.DailySummary.RequestOrigin.Store(originISO, fo.(int)+1)
|
|
|
}
|
|
|
|
|
|
+ //Filter out CF forwarded requests
|
|
|
+ if strings.Contains(ri.IpAddr, ",") {
|
|
|
+ ips := strings.Split(ri.IpAddr, ",")
|
|
|
+ if len(ips) >= 1 {
|
|
|
+ ri.IpAddr = ips[0]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
fi, ok := c.DailySummary.RequestClientIp.Load(ri.IpAddr)
|
|
|
if !ok {
|
|
|
c.DailySummary.RequestClientIp.Store(ri.IpAddr, 1)
|
|
@@ -143,7 +151,7 @@ func (c *Collector) RecordRequest(ri RequestInfo) {
|
|
|
}()
|
|
|
}
|
|
|
|
|
|
-//nightly task
|
|
|
+// nightly task
|
|
|
func (c *Collector) ScheduleResetRealtimeStats() chan bool {
|
|
|
doneCh := make(chan bool)
|
|
|
|