mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-08-14 08:59:19 +02:00
Added rule handles to dynamic proxy core
This commit is contained in:
@@ -15,15 +15,6 @@ import (
|
||||
*/
|
||||
|
||||
func (c *Collector) HandleTodayStatLoad(w http.ResponseWriter, r *http.Request) {
|
||||
type DailySummaryExport struct {
|
||||
TotalRequest int64 //Total request of the day
|
||||
ErrorRequest int64 //Invalid request of the day, including error or not found
|
||||
ValidRequest int64 //Valid request of the day
|
||||
|
||||
ForwardTypes map[string]int
|
||||
RequestOrigin map[string]int
|
||||
RequestClientIp map[string]int
|
||||
}
|
||||
|
||||
fast, err := utils.GetPara(r, "fast")
|
||||
if err != nil {
|
||||
|
@@ -74,16 +74,18 @@ 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)
|
||||
summaryKey := t.Format("02_01_2006")
|
||||
c.Option.Database.Write("stats", summaryKey, c.DailySummary)
|
||||
saveData := DailySummaryToExport(*c.DailySummary)
|
||||
c.Option.Database.Write("stats", summaryKey, saveData)
|
||||
}
|
||||
|
||||
//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")
|
||||
var targetSummary = newDailySummary()
|
||||
c.Option.Database.Read("stats", summaryKey, &targetSummary)
|
||||
return targetSummary
|
||||
targetSummaryExport := DailySummaryExport{}
|
||||
c.Option.Database.Read("stats", summaryKey, &targetSummaryExport)
|
||||
targetSummary := DailySummaryExportToSummary(targetSummaryExport)
|
||||
return &targetSummary
|
||||
}
|
||||
|
||||
//This function gives the current slot in the 288- 5 minutes interval of the day
|
||||
|
66
src/mod/statistic/structconv.go
Normal file
66
src/mod/statistic/structconv.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package statistic
|
||||
|
||||
import "sync"
|
||||
|
||||
type DailySummaryExport struct {
|
||||
TotalRequest int64 //Total request of the day
|
||||
ErrorRequest int64 //Invalid request of the day, including error or not found
|
||||
ValidRequest int64 //Valid request of the day
|
||||
|
||||
ForwardTypes map[string]int
|
||||
RequestOrigin map[string]int
|
||||
RequestClientIp map[string]int
|
||||
}
|
||||
|
||||
func DailySummaryToExport(summary DailySummary) DailySummaryExport {
|
||||
export := DailySummaryExport{
|
||||
TotalRequest: summary.TotalRequest,
|
||||
ErrorRequest: summary.ErrorRequest,
|
||||
ValidRequest: summary.ValidRequest,
|
||||
ForwardTypes: make(map[string]int),
|
||||
RequestOrigin: make(map[string]int),
|
||||
RequestClientIp: make(map[string]int),
|
||||
}
|
||||
|
||||
summary.ForwardTypes.Range(func(key, value interface{}) bool {
|
||||
export.ForwardTypes[key.(string)] = value.(int)
|
||||
return true
|
||||
})
|
||||
|
||||
summary.RequestOrigin.Range(func(key, value interface{}) bool {
|
||||
export.RequestOrigin[key.(string)] = value.(int)
|
||||
return true
|
||||
})
|
||||
|
||||
summary.RequestClientIp.Range(func(key, value interface{}) bool {
|
||||
export.RequestClientIp[key.(string)] = value.(int)
|
||||
return true
|
||||
})
|
||||
|
||||
return export
|
||||
}
|
||||
|
||||
func DailySummaryExportToSummary(export DailySummaryExport) DailySummary {
|
||||
summary := DailySummary{
|
||||
TotalRequest: export.TotalRequest,
|
||||
ErrorRequest: export.ErrorRequest,
|
||||
ValidRequest: export.ValidRequest,
|
||||
ForwardTypes: &sync.Map{},
|
||||
RequestOrigin: &sync.Map{},
|
||||
RequestClientIp: &sync.Map{},
|
||||
}
|
||||
|
||||
for k, v := range export.ForwardTypes {
|
||||
summary.ForwardTypes.Store(k, v)
|
||||
}
|
||||
|
||||
for k, v := range export.RequestOrigin {
|
||||
summary.RequestOrigin.Store(k, v)
|
||||
}
|
||||
|
||||
for k, v := range export.RequestClientIp {
|
||||
summary.RequestClientIp.Store(k, v)
|
||||
}
|
||||
|
||||
return summary
|
||||
}
|
Reference in New Issue
Block a user