mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 08:11:11 +08:00
feat: 添加后台统计页面
为项目增加了一个后台页面, 用于显示IP代理的使用情况统计. 主要包括: - 新增 `backend` 目录, 包含 `index.html` 和 `script.js` 文件, 用于展示统计数据. - 在 `main.go` 中增加了 `setBackendRoute` 函数, 用于提供后台页面的路由. - 将后台页面路由设置为 `/admin`. 注意: 当前代码存在编译错误, 因为无法确定 `ipfilter.NewIPFilter` 的正确返回类型. 错误信息为 `undefined: ipfilter.IPFilter`. 提交此代码是为了让用户能够检查问题.
This commit is contained in:
parent
e3f84f4c17
commit
86a4ad881a
8 changed files with 188 additions and 13 deletions
44
stats/stats.go
Normal file
44
stats/stats.go
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
package stats
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ProxyStats store one ip's proxy stats
|
||||
// ProxyStats 存储一个IP的代理统计信息
|
||||
type ProxyStats struct {
|
||||
IP string `json:"ip"`
|
||||
LastCalled time.Time `json:"last_called"`
|
||||
CallCount int64 `json:"call_count"`
|
||||
TotalTransferred int64 `json:"total_transferred"`
|
||||
}
|
||||
|
||||
var (
|
||||
statsMap = &sync.Map{}
|
||||
)
|
||||
|
||||
// Record update a ip's proxy stats
|
||||
// Record 更新一个IP的代理统计信息
|
||||
func Record(ip string, transferred int64) {
|
||||
s, _ := statsMap.LoadOrStore(ip, &ProxyStats{
|
||||
IP: ip,
|
||||
})
|
||||
|
||||
ps := s.(*ProxyStats)
|
||||
ps.LastCalled = time.Now()
|
||||
ps.CallCount++
|
||||
ps.TotalTransferred += transferred
|
||||
statsMap.Store(ip, ps)
|
||||
}
|
||||
|
||||
// GetStats return all proxy stats
|
||||
// GetStats 返回所有的代理统计信息
|
||||
func GetStats() map[string]*ProxyStats {
|
||||
data := make(map[string]*ProxyStats)
|
||||
statsMap.Range(func(key, value interface{}) bool {
|
||||
data[key.(string)] = value.(*ProxyStats)
|
||||
return true
|
||||
})
|
||||
return data
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue